Java Code Examples for org.openide.ErrorManager#annotate()
The following examples show how to use
org.openide.ErrorManager#annotate() .
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: AnnotatedNode.java From NBANDROID-V2 with Apache License 2.0 | 6 votes |
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 2
Source File: ParsingSupport.java From netbeans with Apache License 2.0 | 6 votes |
/** * 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 3
Source File: SettingsRecognizer.java From netbeans with Apache License 2.0 | 6 votes |
/** 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 4
Source File: FormatterIndentEngine.java From netbeans with Apache License 2.0 | 6 votes |
public void setSpacesPerTab(int spacesPerTab) { if (spacesPerTab <= 0) { IllegalArgumentException iae = new IllegalArgumentException("Invalid argument"); //NOI18N ErrorManager errMan = Lookup.getDefault().lookup(ErrorManager.class); if (errMan != null) { Toolkit.getDefaultToolkit().beep(); errMan.annotate(iae, ErrorManager.USER, iae.getMessage(), NbBundle.getMessage(FormatterIndentEngine.class, "MSG_NegativeValue"), null, null); //NOI18N } else { throw iae; } } int old = getFormatter().getSpacesPerTab(); getFormatter().setSpacesPerTab(spacesPerTab); if (old != spacesPerTab) { setValue(SimpleValueNames.SPACES_PER_TAB, new Integer(spacesPerTab), SPACES_PER_TAB_PROP); firePropertyChange(SPACES_PER_TAB_PROP, new Integer(old), new Integer(spacesPerTab) ); } }
Example 5
Source File: AnnotatedNode.java From netbeans with Apache License 2.0 | 6 votes |
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 6
Source File: AnnotatedNode.java From netbeans with Apache License 2.0 | 6 votes |
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 7
Source File: ExitDialog.java From netbeans with Apache License 2.0 | 6 votes |
/** 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 8
Source File: AnnotationBar.java From netbeans with Apache License 2.0 | 6 votes |
/** * 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 9
Source File: ExitDialog.java From netbeans with Apache License 2.0 | 5 votes |
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: NbEditorUtilities.java From netbeans with Apache License 2.0 | 5 votes |
/** Displays ErrorManager window with the localized message. If bundleKey parameter is not founded in bundle * it is considered as displayable text value. */ public static void invalidArgument(String bundleKey) { IllegalArgumentException iae=new IllegalArgumentException("Invalid argument"); //NOI18N Toolkit.getDefaultToolkit().beep(); ErrorManager errMan=(ErrorManager)Lookup.getDefault().lookup(ErrorManager.class); if (errMan!=null) { errMan.annotate(iae, ErrorManager.USER, iae.getMessage(), getString(bundleKey), null, null); //NOI18N } throw iae; }
Example 11
Source File: GuiUtil.java From netbeans with Apache License 2.0 | 5 votes |
/** * 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 12
Source File: URLEnvironment.java From netbeans with Apache License 2.0 | 5 votes |
/** * Always return fresh stream. */ public java.io.InputStream inputStream() throws java.io.IOException { try { URL peer = new URL(systemId); return peer.openStream(); } catch (IOException ex) { // #21556 // annotate exception as USER error, he provided wrong URL ErrorManager err = ErrorManager.getDefault(); err.annotate(ex, ErrorManager.USER, null, null, null, null); throw ex; } }
Example 13
Source File: NbErrorManagerTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testUIExceptionsTriggersTheDialogWithWarningPlus1() throws Exception { MockDD.lastDescriptor = null; Exception ex = new IOException(); ErrorManager em = ErrorManager.getDefault(); em.annotate(ex, ErrorManager.USER, "bla", "blaLoc", null, null); Logger.global.log(OwnLevel.UNKNOWN, "someerror", ex); waitEQ(); assertNotNull("Mock descriptor called", MockDD.lastDescriptor); assertEquals("Info msg", NotifyDescriptor.INFORMATION_MESSAGE, MockDD.lastDescriptor.getMessageType()); }
Example 14
Source File: NbErrorManagerTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testUIExceptionsTriggersTheDialog() throws Exception { MockDD.lastDescriptor = null; Exception ex = new IOException(); ErrorManager em = ErrorManager.getDefault(); em.annotate(ex, ErrorManager.USER, "bla", "blaLoc", null, null); Exceptions.printStackTrace(ex); waitEQ(); assertNotNull("Mock descriptor called", MockDD.lastDescriptor); assertEquals("Info msg", NotifyDescriptor.INFORMATION_MESSAGE, MockDD.lastDescriptor.getMessageType()); }
Example 15
Source File: NbErrorManagerTest.java From netbeans with Apache License 2.0 | 5 votes |
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 16
Source File: Util.java From netbeans with Apache License 2.0 | 4 votes |
/** * 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 17
Source File: PatchAction.java From netbeans with Apache License 2.0 | 4 votes |
/** 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))); }
Example 18
Source File: SettingsRecognizer.java From netbeans with Apache License 2.0 | 4 votes |
/** Create an instance. * @return the instance of type {@link #instanceClass} * @exception IOException if an I/O error occured * @exception ClassNotFoundException if a class was not found */ public Object instanceCreate() throws java.io.IOException, ClassNotFoundException { Object inst = null; // deserialize inst = readSerial(getSerializedInstance()); // default instance if (inst == null) { if (instanceMethod != null) { inst = createFromMethod(instanceClass, instanceMethod); } else { // use default constructor Class<?> clazz = instanceClass(); if (SharedClassObject.class.isAssignableFrom(clazz)) { inst = SharedClassObject.findObject(clazz.asSubclass(SharedClassObject.class), false); if (null != inst) { // instance already exists -> reset it to defaults try { Method method = SharedClassObject.class.getDeclaredMethod("reset", new Class[0]); // NOI18N method.setAccessible(true); method.invoke(inst, new Object[0]); } catch (Exception e) { ErrorManager.getDefault().notify(e); } } else { inst = SharedClassObject.findObject(clazz.asSubclass(SharedClassObject.class), true); } } else { try { inst = clazz.newInstance(); } catch (Exception ex) { IOException ioe = new IOException(); ErrorManager emgr = ErrorManager.getDefault(); emgr.annotate(ioe, ex); emgr.annotate(ioe, "Content: \n" + getFileContent(source)); // NOI18N emgr.annotate(ioe, "Class: " + clazz); // NOI18N emgr.annotate(ioe, "Source: " + source); // NOI18N throw ioe; } } } } return inst; }