Java Code Examples for org.openide.ErrorManager#notify()

The following examples show how to use org.openide.ErrorManager#notify() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SettingsRecognizer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** reade codenamebase + revision */
private void resolveModuleElm(String codeName) {
    if (codeName != null) {
        int slash = codeName.indexOf("/"); // NOI18N
        if (slash == -1) {
            codeNameBase = codeName;
            codeNameRelease = -1;
        } else {
            codeNameBase = codeName.substring(0, slash);
            try {
                codeNameRelease = Integer.parseInt(codeName.substring(slash + 1));
            } catch (NumberFormatException ex) {
                ErrorManager emgr = ErrorManager.getDefault();
                emgr.annotate(ex, "Content: \n" + getFileContent(source)); // NOI18N
                emgr.annotate(ex, "Source: " + source); // NOI18N
                emgr.notify(ErrorManager.INFORMATIONAL, ex);
                codeNameRelease = -1;
            }
        }
    } else {
        codeNameBase = null;
        codeNameRelease = -1;
    }
}
 
Example 2
Source File: AnnotatedNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected final void setFiles(final Set<FileObject> files) {
    fileSystemListeners = new HashSet<FileStatusListener>();
    this.files = files;
    if (files == null) {
        return;
    }
    Set<FileSystem> hookedFileSystems = new HashSet<FileSystem>();
    for (FileObject fo: files) {
        try {
            FileSystem fs = fo.getFileSystem();
            if (hookedFileSystems.contains(fs)) {
                continue;
            }
            hookedFileSystems.add(fs);
            FileStatusListener fsl = FileUtil.weakFileStatusListener(this, fs);
            fs.addFileStatusListener(fsl);
            fileSystemListeners.add(fsl);
        } catch (FileStateInvalidException e) {
            ErrorManager err = ErrorManager.getDefault();
            err.annotate(e, "Cannot get " + fo + " filesystem, ignoring...");  // NOI18N
            err.notify(ErrorManager.INFORMATIONAL, e);
        }
    }
}
 
Example 3
Source File: AnnotatedNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected final void setFiles(final Set<FileObject> files) {
    fileSystemListeners = new HashSet<FileStatusListener>();
    this.files = files;
    if (files == null) {
        return;
    }
    Iterator<FileObject> it = files.iterator();
    Set<FileSystem> hookedFileSystems = new HashSet<FileSystem>();
    while (it.hasNext()) {
        FileObject fo = it.next();
        try {
            FileSystem fs = fo.getFileSystem();
            if (hookedFileSystems.contains(fs)) {
                continue;
            }
            hookedFileSystems.add(fs);
            FileStatusListener fsl = FileUtil.weakFileStatusListener(this, fs);
            fs.addFileStatusListener(fsl);
            fileSystemListeners.add(fsl);
        } catch (FileStateInvalidException e) {
            ErrorManager err = ErrorManager.getDefault();
            err.annotate(e, "Cannot get " + fo + " filesystem, ignoring...");  // NOI18N
            err.notify(ErrorManager.INFORMATIONAL, e);
        }
    }
}
 
Example 4
Source File: ExitDialog.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Tries to save given data object using its save cookie.
 * Notifies user if excetions appear.
 */
private void save (DataObject dataObject) {
    try {
        SaveCookie sc = dataObject.getLookup().lookup(SaveCookie.class);
        if (sc != null) {
            sc.save();
        }
        listModel.removeElement(dataObject);
    } catch (IOException exc) {
        ErrorManager em = ErrorManager.getDefault();
        Throwable t = em.annotate(
            exc, NbBundle.getBundle(ExitDialog.class).getString("EXC_Save")
        );
        em.notify(ErrorManager.EXCEPTION, t);
    }
}
 
Example 5
Source File: AnnotationBar.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Locates AnnotateLine associated with given line. The
 * line is translated to Element that is used as map lookup key.
 * The map is initially filled up with Elements sampled on
 * annotate() method.
 *
 * <p>Key trick is that Element's identity is maintained
 * until line removal (and is restored on undo).
 *
 * @param line
 * @return found AnnotateLine or <code>null</code>
 */
private VcsAnnotation getAnnotateLine(int line) {
    StyledDocument sd = (StyledDocument) doc;
    int lineOffset = NbDocument.findLineOffset(sd, line);
    Element element = sd.getParagraphElement(lineOffset);
    VcsAnnotation al = elementAnnotations.get(element);

    if (al != null) {
        int startOffset = element.getStartOffset();
        int endOffset = element.getEndOffset();
        try {
            int len = endOffset - startOffset;
            String text = doc.getText(startOffset, len -1);
            String content = al.getDocumentText();
            if (text.equals(content)) {
                return al;
            }
        } catch (BadLocationException e) {
            ErrorManager err = ErrorManager.getDefault();
            err.annotate(e, "CVS.AB: can not locate line annotation."); // NOI18N
            err.notify(ErrorManager.INFORMATIONAL, e);
        }
    }

    return null;
}
 
Example 6
Source File: ParsingSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Converts to InputSource and pass it.
 */    
protected TreeDocumentRoot parse(FileObject fo) throws IOException, TreeException{
    
    try {
        URL url = fo.getURL();
        InputSource in = new InputSource(url.toExternalForm());  //!!! we could try ti get encoding from MIME content type
        in.setByteStream(fo.getInputStream());
        return parse(in);
        
    } catch (IOException ex) {
        ErrorManager emgr = ErrorManager.getDefault();
        emgr.annotate(ex, Util.THIS.getString("MSG_can_not_create_URL"));
        emgr.notify(ex);
    }           
    return null;
}
 
Example 7
Source File: AnnotatedNode.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
protected final void setFiles(final Set<FileObject> files) {
    fileSystemListeners = new HashSet<FileStatusListener>();
    this.files = files;
    if (files == null) {
        return;
    }
    Set<FileSystem> hookedFileSystems = new HashSet<FileSystem>();
    for (FileObject fo : files) {
        try {
            FileSystem fs = fo.getFileSystem();
            if (hookedFileSystems.contains(fs)) {
                continue;
            }
            hookedFileSystems.add(fs);
            FileStatusListener fsl = FileUtil.weakFileStatusListener(this, fs);
            fs.addFileStatusListener(fsl);
            fileSystemListeners.add(fsl);
        } catch (FileStateInvalidException e) {
            ErrorManager err = ErrorManager.getDefault();
            err.annotate(e, "Cannot get " + fo + " filesystem, ignoring...");  // NOI18N
            err.notify(ErrorManager.INFORMATIONAL, e);
        }
    }
}
 
Example 8
Source File: NbErrorManagerTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testErrorManagerCompatibilityAsDescribedInIssue79227() throws Exception {
    MockDD.lastDescriptor = null;

    Exception ex = new ClassNotFoundException();
    ErrorManager em = ErrorManager.getDefault();
    String msg = "LocMsg";
    em.annotate(ex, msg);
    em.notify(ErrorManager.USER, ex); // Issue 65116 - don't show the exception to the user

    waitEQ();
    assertNotNull("Mock descriptor called", MockDD.lastDescriptor);
    assertEquals("Info msg", NotifyDescriptor.INFORMATION_MESSAGE, MockDD.lastDescriptor.getMessageType());
}
 
Example 9
Source File: ExitDialog.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static void doSave (DataObject dataObject) {
    try {
        SaveCookie sc = dataObject.getLookup().lookup(SaveCookie.class);
        if (sc != null) {
            sc.save();
        }
    } catch (IOException exc) {
        ErrorManager em = ErrorManager.getDefault();
        Throwable t = em.annotate(
            exc, NbBundle.getBundle(ExitDialog.class).getString("EXC_Save")
        );
        em.notify(ErrorManager.EXCEPTION, t);
    }
}
 
Example 10
Source File: XMLSyntaxSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void insertUpdate(DocumentEvent e) {
    int start = e.getOffset();
    int len = e.getLength();
    try {
        String s = e.getDocument().getText(start + len - 1, 1);
        lastInsertedChar = s.charAt(0);
    } catch (BadLocationException e1) {
        ErrorManager err = ErrorManager.getDefault();
        err.notify(e1);
    }
}
 
Example 11
Source File: DiskFileKey.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public boolean equals(Object o) {
    if (this == o) return true;

    if (o instanceof DiskFileKey) {

        DiskFileKey key = (DiskFileKey) o;

        if (hashCode != key.hashCode) return false;
        FileObject fo2 = key.fileObject;
        FileObject fo = fileObject;

        if (fo == fo2) return true;

        try {
            FileSystem fs = fo.getFileSystem();
            FileSystem fs2 = fo2.getFileSystem();
            if (fs.equals(fs2)) {
                return fo.equals(fo2);
            } else {
                // fallback use absolute paths (cache them)
                if (absolutePath == null) {
                    File f = FileUtil.toFile(fo);
                    absolutePath = f.getAbsolutePath();
                }
                if (key.absolutePath == null) {
                    File f2 = FileUtil.toFile(fo2);
                    key.absolutePath = f2.getAbsolutePath();
                }
                return absolutePath.equals(key.absolutePath);
            }
        } catch (FileStateInvalidException e) {
            ErrorManager err = ErrorManager.getDefault();
            err.notify(e);
        }
    }
    return false;
}
 
Example 12
Source File: GuiUtil.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Notify annotated exception to user. Just shortcut to ErrorManager.
 */    
public static void notifyException (String desc, Throwable ex) {
    ErrorManager err = ErrorManager.getDefault();
    if (desc != null) {
        err.annotate (ex, desc);
    }
    err.notify (err.EXCEPTION, ex);  // show stack trace to user
}
 
Example 13
Source File: Util.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Write the exception into log.
 */
public static void debug(Throwable t) {
    ErrorManager err = ErrorManager.getDefault();
    err.notify(err.INFORMATIONAL, t);
}
 
Example 14
Source File: Util.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Write annotated exception into log.
 */
public static void debug(String annotation, Throwable t) {
    ErrorManager err = ErrorManager.getDefault();
    err.annotate(t, err.INFORMATIONAL, annotation, null, null, null);
    err.notify(err.INFORMATIONAL, t);
}
 
Example 15
Source File: PatchAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Removes the backup copies of files upon the successful application 
 * of a patch (.orig files).
 * @param files a list of files, to which the patch was successfully applied
 * @param backups a map of a form original file -> backup file
 */
private static void removeBackups(List<FileObject> files, Map<FileObject, FileObject> backups, boolean onExit) {
    StringBuffer filenames=new StringBuffer(), 
                 exceptions=new StringBuffer();
    for (int i = 0; i < files.size(); i++) {
        FileObject targetFileObject = files.get(i);
        FileObject backup= backups.get(targetFileObject);

        // delete files that become empty and they have a backup file
        if (targetFileObject != null && targetFileObject.getSize() == 0) {
            if (backup != null && backup.isValid() && backup.getSize() > 0) {
                if (onExit) {
                    deleteOnExit(targetFileObject);
                } else {
                    try {
                        targetFileObject.delete();
                    } catch (IOException e) {
                        ErrorManager err = ErrorManager.getDefault();
                        err.annotate(e, "Patch can not delete file, skipping...");
                        err.notify(ErrorManager.INFORMATIONAL, e);
                    }
                }
            }
        }

        if (backup != null && backup.isValid()) {
            if (onExit) {
                deleteOnExit(backup);
            } else {
                try {
                    backup.delete();
                }
                catch (IOException ex) {
                    filenames.append(FileUtil.getFileDisplayName(backup));
                    filenames.append('\n');
                    exceptions.append(ex.getLocalizedMessage());
                    exceptions.append('\n');
                }
            }
        }
    }
    if (filenames.length()>0)
        ErrorManager.getDefault().notify(
            ErrorManager.getDefault().annotate(new IOException(),
                NbBundle.getMessage(PatchAction.class, 
                    "EXC_CannotRemoveBackup", filenames, exceptions)));
}