@NbBundle.Messages("TITLE_CannotWriteFile=Cannot Write to File") @Override public void handleUserQuestionException(final IOException ioe, final UserQuestionExceptionCallback callback) { if(ioe instanceof UserQuestionException) { final UserQuestionException e = (UserQuestionException) ioe; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { NotifyDescriptor.Confirmation desc = new NotifyDescriptor.Confirmation( e.getLocalizedMessage(), Bundle.TITLE_CannotWriteFile(), NotifyDescriptor.Confirmation.OK_CANCEL_OPTION); if (DialogDisplayer.getDefault().notify(desc).equals(NotifyDescriptor.OK_OPTION)) { try { e.confirmed(); callback.accepted(); } catch (IOException x) { callback.error(x); } } else { callback.denied(); } } }); } }
public void testOpenDocumentIsLoadedUsingUserQuestionException() throws Exception{ class MyEx extends UserQuestionException { private int confirmed; public @Override String getLocalizedMessage() { return "locmsg"; } public @Override String getMessage() { return "msg"; } public void confirmed () { confirmed++; toThrow = null; } } doOpenDocumentIsLoaded (new MyEx ()); }
@NbBundle.Messages("TXT_Question=Question") private static StyledDocument getDocument(EditorCookie ec) throws IOException { StyledDocument doc; try { doc = ec.openDocument(); } catch (UserQuestionException uqe) { final Object value = DialogDisplayer.getDefault().notify( new NotifyDescriptor.Confirmation(uqe.getLocalizedMessage(), Bundle.TXT_Question(), NotifyDescriptor.YES_NO_OPTION)); if (value != NotifyDescriptor.YES_OPTION) { return null; } uqe.confirmed(); doc = ec.openDocument(); } return doc; }
private static StyledDocument openDocument(EditorCookie ec) throws IOException { StyledDocument doc; try { doc = ec.openDocument(); } catch (UserQuestionException ex) { // issue #156068 - open even big file, issue #232257 - encoding should not be a problem for guarded test if (ex.getMessage().startsWith("The file is too big.") || ex.getMessage().contains("cannot be safely opened with encoding")) { // NOI18N ex.confirmed(); doc = ec.openDocument(); } else { throw ex; } } return doc; }
/** * Get the document associated with a file. * * <p>Method will throw {@link org.openide.util.UserQuestionException} * exception if file size is too big. This exception is caught and its * method {@link org.openide.util.UserQuestionException#confirmed} is used * for confirmation. * * * @param provider for example a {@code org.openide.loaders.DataObject} * @return a document or null * @since org.openide.text 6.46 */ @NbBundle.Messages("TXT_Question=Question") public static StyledDocument getDocument(Lookup.Provider provider) { try { EditorCookie ec = provider.getLookup().lookup(EditorCookie.class); if (ec != null) { StyledDocument doc = null; try { doc = ec.openDocument(); } catch (UserQuestionException uqe) { final Object value = DialogDisplayer.getDefault().notify( new NotifyDescriptor.Confirmation(uqe.getLocalizedMessage(), Bundle.TXT_Question(), NotifyDescriptor.YES_NO_OPTION)); if (value != NotifyDescriptor.YES_OPTION) { return null; } uqe.confirmed(); doc = ec.openDocument(); } return doc; } } catch (IOException ioe) { Logger.getLogger(NbDocument.class.getName()).log(Level.WARNING, null, ioe); } return null; }
void reloadUQEThrown(UserQuestionException uqe) { userQuestionExceptionInReload = true; // In case of reload handle UQE so that the reloading finishes with doc's content loading UserQuestionExceptionHandler handler = new UserQuestionExceptionHandler( ces, (UserQuestionException) loadIOException) { @Override protected StyledDocument openDocument() throws IOException { loadIOException = null; // Reuse current reload task activeReloadTask.schedule(0); return loadDoc; } @Override protected void openRefused() { loadIOException = null; // This is a problematic situation since the user refused document loading // during reload. skipInputStreamReading = true; activeReloadTask.schedule(0); } }; handler.runInEDT(); // This however means that the task returned by CES.reloadDocument() will no longer ensure // finished reloading. There does not seem to be a good way for possible tests to sync // on finished reloading so currently they have to only wait for certain amount of time. }
/** Tests that UserQuestionException is thrown when saving externally modified document. */ public void testSaveExternallyModified() throws Exception { content = "Ahoj\nMyDoc"; support.openDocument(); modified = true; // simulate external modification date = new Date(System.currentTimeMillis() + 100); try { support.saveDocument(); fail("UserQuestionException should be thrown because of external modification."); } catch (UserQuestionException e) { // OK, exception expected. } }
/** Tests that UserQuestionException is NOT thrown when document is not externally * modified but there is some delay between closing stream and setting file modification time. * See issue 149069. */ public void testSaveNotExternallyModified() throws Exception { content = "Ahoj\nMyDoc"; support.openDocument(); modified = true; // intentionally extremly big to make it work even in debugger delay = 86400000; support.saveDocument(); modified = true; try { support.saveDocument(); } catch (UserQuestionException e) { fail("UserQuestionException should NOT be thrown (see #149069)."); } }
public ErrorDescriptionChildren(java.util.Map<AnalyzerFactory, List<ErrorDescription>> errors) { List<ErrorDescription> eds = new ArrayList<ErrorDescription>(); for (Entry<AnalyzerFactory, List<ErrorDescription>> e : errors.entrySet()) { for (ErrorDescription ed : e.getValue()) { error2Analyzer.put(ed, e.getKey()); eds.add(ed); } } Collections.sort(eds, new Comparator<ErrorDescription>() { @Override public int compare(ErrorDescription o1, ErrorDescription o2) { try { try { final PositionBounds r1 = o1.getRange(); final PositionBounds r2 = o2.getRange(); if (r1 != null) { return r2 != null ? r1.getBegin().getLine() - r2.getBegin().getLine() : -1; } else { return r2 != null ? 1 : o1.getDescription().compareTo(o2.getDescription()); } } catch (UserQuestionException uqe) { uqe.confirmed(); return compare(o1, o2); } } catch (IOException ex) { throw new IllegalStateException(ex); //XXX } } }); setKeys(eds); }
/** * Load the document for the given fileObject. * @param fileObject the file whose document we want to obtain * @param openIfNecessary If true, block if necessary to open the document. If false, will only return the * document if it is already open. * @param skipLarge If true, check the file size, and if the file is really large (defined by * openide.loaders), then skip it (otherwise we could end up with a large file warning). * @return */ public static BaseDocument getDocument(FileObject fileObject, boolean openIfNecessary, boolean skipLarge) { if (skipLarge) { // Make sure we're not dealing with a huge file! // Causes issues like 132306 // openide.loaders/src/org/openide/text/DataEditorSupport.java // has an Env#inputStream method which posts a warning to the user // if the file is greater than 1Mb... //SG_ObjectIsTooBig=The file {1} seems to be too large ({2,choice,0#{2}b|1024#{3} Kb|1100000#{4} Mb|1100000000#{5} Gb}) to safely open. \n\ // Opening the file could cause OutOfMemoryError, which would make the IDE unusable. Do you really want to open it? // Apparently there is a way to handle this // (see issue http://www.netbeans.org/issues/show_bug.cgi?id=148702 ) // but for many cases, the user probably doesn't want really large files as indicated // by the skipLarge parameter). if (fileObject.getSize () > 1024 * 1024) { return null; } } try { EditorCookie ec = fileObject.isValid() ? DataLoadersBridge.getDefault().getCookie(fileObject, EditorCookie.class) : null; if (ec != null) { if (openIfNecessary) { try { return (BaseDocument) ec.openDocument(); } catch (UserQuestionException uqe) { uqe.confirmed(); return (BaseDocument) ec.openDocument(); } } else { return (BaseDocument) ec.getDocument(); } } } catch (IOException ex) { LOG.log(Level.WARNING, null, ex); } return null; }
public void testUserQuestionExceptionDisplayedOK() throws Exception { class UQE extends UserQuestionException { UQE() { super("HelloTest"); } boolean confirm; @Override public void confirmed() throws IOException { confirm = true; } @Override public String getLocalizedMessage() { return "Reboot?"; } } MockDD.reply = NotifyDescriptor.OK_OPTION; UQE ex = new UQE(); Exceptions.printStackTrace(ex); waitEDT(); assertNotNull("Dialog created", MockDD.lastDescriptor); assertEquals("Message is localized text", "Reboot?", MockDD.lastDescriptor.getMessage()); assertTrue("The message has been confirmed", ex.confirm); }
public void testUserQuestionExceptionDisplayedCancel() throws Exception { class UQE extends UserQuestionException { UQE() { super("HelloTest"); } boolean confirm; @Override public void confirmed() throws IOException { confirm = true; } @Override public String getLocalizedMessage() { return "Reboot?"; } } MockDD.reply = NotifyDescriptor.CLOSED_OPTION; UQE ex = new UQE(); Exceptions.printStackTrace(ex); waitEDT(); assertNotNull("Dialog created", MockDD.lastDescriptor); assertEquals("Message is localized text", "Reboot?", MockDD.lastDescriptor.getMessage()); assertFalse("The message has not been confirmed", ex.confirm); }
private Document getSourceDocument(StreamSource ss) { Document sdoc = null; FileObject fo = ss.getLookup().lookup(FileObject.class); if (fo != null) { try { DataObject dao = DataObject.find(fo); if (dao.getPrimaryFile() == fo) { EditorCookie ec = dao.getCookie(EditorCookie.class); if (ec != null) { try { sdoc = ec.openDocument(); } catch (UserQuestionException ex) { boolean open = !Boolean.TRUE.equals(skipFile); if (skipFile == null) { NotifyDescriptor.Confirmation desc = new NotifyDescriptor.Confirmation(ex.getLocalizedMessage(), NbBundle.getMessage(EditableDiffView.class, "EditableDiffView.ConfirmOpenningTitle"), NotifyDescriptor.Confirmation.OK_CANCEL_OPTION); //NOI18N open = DialogDisplayer.getDefault().notify(desc).equals(NotifyDescriptor.OK_OPTION); } if (open) { LOG.log(Level.INFO, "User acepted UQE: {0}", fo.getPath()); //NOI18N ex.confirmed(); sdoc = ec.openDocument(); } else { sdoc = null; this.skipFile = true; } } } } } catch (Exception e) { // fallback to other means of obtaining the source } } else { sdoc = ss.getLookup().lookup(Document.class); } return sdoc; }
@Override public Document readDocument(FileObject fileObject, boolean forceOpen) { EditorCookie ec = null; try { DataObject dataObject = DataObject.find (fileObject); ec = dataObject.getLookup ().lookup (EditorCookie.class); } catch (DataObjectNotFoundException ex) { //DataobjectNotFoundException may happen in case of deleting opened file //handled by returning null } if (ec == null) return null; Document doc = ec.getDocument (); if (doc == null && forceOpen) { try { try { doc = ec.openDocument (); } catch (UserQuestionException uqe) { uqe.confirmed (); doc = ec.openDocument (); } } catch (IOException ioe) { LOGGER.log (Level.WARNING, null, ioe); } } return doc; }
public void navigate(final DataObject d) { attachDataObject(d); final EditorCookie ec = (EditorCookie)d.getCookie(EditorCookie.class); if(ec == null) { ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "The DataObject " + d.getName() + "(class=" + d.getClass().getName() + ") has no EditorCookie!?"); } else { RP.post(new Runnable() { public void run() { try { if(DEBUG) System.out.println("[xml navigator] navigating to DATAOBJECT " + d.hashCode()); //test if the document is opened in editor BaseDocument bdoc = (BaseDocument)ec.openDocument(); //create & show UI if(bdoc != null) { //there is something we can navigate in navigate(d, bdoc); } } catch(UserQuestionException uqe) { //do not open a question dialog when the document is just loaded into the navigator showError(AbstractXMLNavigatorContent.ERROR_TOO_LARGE_DOCUMENT); }catch(IOException e) { ErrorManager.getDefault().notify(e); } } }); } }
private void performAction(Savable sc, Node n) { UserQuestionException userEx = null; for (;;) { try { if (userEx == null) { sc.save(); } else { userEx.confirmed(); } StatusDisplayer.getDefault().setStatusText( NbBundle.getMessage(SaveAction.class, "MSG_saved", getSaveMessage(sc, n)) ); } catch (UserQuestionException ex) { NotifyDescriptor nd = new NotifyDescriptor.Confirmation(ex.getLocalizedMessage(), NotifyDescriptor.YES_NO_OPTION); Object res = DialogDisplayer.getDefault().notify(nd); if (NotifyDescriptor.OK_OPTION.equals(res)) { userEx = ex; continue; } } catch (IOException e) { Exceptions.attachLocalizedMessage(e, NbBundle.getMessage(SaveAction.class, "EXC_notsaved", getSaveMessage(sc, n), e.getLocalizedMessage ())); Logger.getLogger (getClass ().getName ()).log (Level.SEVERE, null, e); } break; } }
@Override public GuardedSectionManager getGuardedSectionManager() { try { StyledDocument doc = null; try { doc = openDocument(); } catch (UserQuestionException uqex) { // Issue 143655 Object retVal = DialogDisplayer.getDefault().notify( new NotifyDescriptor.Confirmation(uqex.getLocalizedMessage(), NotifyDescriptor.YES_NO_OPTION)); if (NotifyDescriptor.YES_OPTION == retVal) { uqex.confirmed(); doc = openDocument(); } } if (doc == null) { // Issue 143655 - opening of big file canceled EventQueue.invokeLater(new Runnable() { @Override public void run() { close(); } }); return null; } else { return GuardedSectionManager.getInstance(doc); } } catch (IOException ex) { throw new IllegalStateException("cannot open document", ex); // NOI18N } }
public void outputLineAction(OutputEvent ev) { RP.post(new Runnable() { public @Override void run() { FileObject file = URLMapper.findFileObject(url); if (file == null) { // #13115 Toolkit.getDefaultToolkit().beep(); return; } try { DataObject dob = DataObject.find(file); EditorCookie ed = dob.getLookup().lookup(EditorCookie.class); if (ed != null && /* not true e.g. for *_ja.properties */file == dob.getPrimaryFile()) { if (line1 == -1) { // OK, just open it. ed.open(); } else { // Fix for IZ#97727 - warning dialogue for opening large files is meaningless if opened via a hyperlink try { ed.openDocument(); // XXX getLineSet does not do it for you! } catch (UserQuestionException exc ){ if ( !askUserAndDoOpen( exc , ed) ){ return; } } AntModule.err.log("opened document for " + file); try { final Line line = updateLines(ed); if (!line.isDeleted()) { EventQueue.invokeLater(new Runnable() { public @Override void run() { line.show(Line.ShowOpenType.REUSE, Line.ShowVisibilityType.FOCUS, col1 == -1 ? -1 : col1 - 1); } }); } } catch (IndexOutOfBoundsException ioobe) { // Probably harmless. Bogus line number. ed.open(); } } } else { Toolkit.getDefaultToolkit().beep(); } } catch (DataObjectNotFoundException donfe) { ErrorManager.getDefault().notify(ErrorManager.WARNING, donfe); } catch (IOException ioe) { // XXX see above, should not be necessary to call openDocument at all ErrorManager.getDefault().notify(ErrorManager.WARNING, ioe); } if (message != null) { // Try to do after opening the file, since opening a new file // clears the current status message. StatusDisplayer.getDefault().setStatusText(message); } } }); }
@Override public boolean isUserQuestionException(IOException ioe) { return ioe instanceof UserQuestionException; }
UserQuestionExceptionHandler(CloneableEditorSupport ces, UserQuestionException uqe) { this.ces = ces; this.uqe = uqe; }
public void testModifyTheFileAndThenPreventItToBeSavedOnFileDisappear() throws Exception { Document doc = edit.openDocument(); assertFalse("Not Modified", edit.isModified()); doc.insertString(0, "Base change\n", null); edit.saveDocument(); edit.open(); waitEQ(); JEditorPane[] arr = getPanes(); assertNotNull("There is one opened pane", arr); java.awt.Component c = arr[0]; while (!(c instanceof CloneableEditor)) { c = c.getParent(); } CloneableEditor ce = (CloneableEditor)c; // to change timestamps Thread.sleep(1000); content = "Ahoj\n"; date = new Date(); // to change timestamps Thread.sleep(1000); doc.remove(0, doc.getLength()); doc.insertString(0, "Internal change\n", null); String txt = doc.getText(0, doc.getLength()); assertEquals("The right text is there", txt, "Internal change\n"); arr = getPanes(); assertNotNull("Panes are still open", arr); assertTrue("Document is remains modified", edit.isModified()); // DD.toReturn.push(DialogDescriptor.CLOSED_OPTION); try { edit.saveDocument(); fail("External modification detected, expect UserQuestionException"); } catch (UserQuestionException ex) { // rerun the action ex.confirmed(); } assertFalse("Editor saved", edit.isModified()); waitEQ(); String txt2 = doc.getText(0, doc.getLength()); assertEquals("The right text still remains", txt2, "Internal change\n"); assertEquals("Text is saved as well", txt2,"Internal change\n"); assertTrue("No dialog", DD.toReturn.isEmpty()); if (DD.error != null) { fail("Error in dialog:\n" + DD.error); } }
public void testReloadOfABigFile() throws Exception { Document doc = edit.openDocument(); doc.insertString(0, "Ahoj", null); assertTrue("Modified", edit.isModified()); edit.open(); waitEQ(); JEditorPane[] arr = getPanes(); assertNotNull("There is one opened pane", arr); java.awt.Component c = arr[0]; while (!(c instanceof CloneableEditor)) { c = c.getParent(); } CloneableEditor ce = (CloneableEditor)c; // select Yes DD.toReturn.push(DialogDescriptor.YES_OPTION); toThrow = new UserQuestionException() { @Override public void confirmed() throws IOException { // ok, confirmed toThrow = null; ByteArrayOutputStream os = new ByteArrayOutputStream(); for (int i = 0; i < 1024 * 1024 + 50000; i++) { os.write('A'); if (i % 80 == 0) { os.write('\n'); } } os.close(); content = os.toString(); } @Override public String getLocalizedMessage() { return "Ahoj"; } }; PropertyChangeEvent evt = new PropertyChangeEvent(this, PROP_TIME, null, null); for (PropertyChangeListener propertyChangeListener : propL) { propertyChangeListener.propertyChange(evt); } /* java.io.File f = FileUtil.toFile(obj.getPrimaryFile()); assertNotNull("There is file behind the fo", f); obj.getPrimaryFile().getParent().refresh(); */ waitEQ(); Task reloadTask = support.reloadDocument(); reloadTask.waitFinished(); // Notification will be resolved in EDT so wait again for EDT waitEQ(); Thread.sleep(3000); assertNotNull ("Text message was there", DD.message); assertEquals ("Text message was there", "Ahoj", DD.message); if (doc.getLength() < 1024) { fail("Should be pretty big: " + doc.getLength()); } }
private void doExceptionThrownWhenDocumentIsBeingRead () throws Exception { class MyEx extends UserQuestionException { private int confirmed; public @Override String getLocalizedMessage() { return "locmsg"; } public @Override String getMessage() { return "msg"; } public void confirmed () { confirmed++; toThrow = null; } } MyEx my = new MyEx (); toThrow = my; DD.toReturn = NotifyDescriptor.NO_OPTION; support.open (); if (!SwingUtilities.isEventDispatchThread ()) { javax.swing.SwingUtilities.invokeAndWait (new Runnable () { public void run () {} }); } assertNotNull ("Some otions", DD.options); assertEquals ("Two options", 2, DD.options.length); assertEquals ("Yes", NotifyDescriptor.YES_OPTION, DD.options[0]); assertEquals ("No", NotifyDescriptor.NO_OPTION, DD.options[1]); assertEquals ("confirmed not called", 0, my.confirmed); assertNull ("Still no document", support.getDocument ()); DD.options = null; DD.toReturn = NotifyDescriptor.YES_OPTION; support.open (); if (!SwingUtilities.isEventDispatchThread ()) { javax.swing.SwingUtilities.invokeAndWait (new Runnable () { public void run () {} }); } assertEquals ("confirmed called", 1, my.confirmed); assertNotNull ("Some otions", DD.options); assertEquals ("Two options", 2, DD.options.length); assertEquals ("Yes", NotifyDescriptor.YES_OPTION, DD.options[0]); assertEquals ("No", NotifyDescriptor.NO_OPTION, DD.options[1]); DD.options = null; assertNotNull ("Document opened", support.getDocument ()); }
final boolean isUserQuestion() { return t instanceof UserQuestionException; }
final void confirm() throws IOException { ((UserQuestionException)t).confirmed(); }
public void testModifyTheFileAndThenPreventItToBeSavedOnFileDisappear() throws Exception { Document doc = edit.openDocument(); assertFalse("Not Modified", edit.isModified()); doc.insertString(0, "Base change\n", null); edit.saveDocument(); edit.open(); waitEQ(); JEditorPane[] arr = getPanes(); assertNotNull("There is one opened pane", arr); java.awt.Component c = arr[0]; while (!(c instanceof CloneableEditor)) { c = c.getParent(); } CloneableEditor ce = (CloneableEditor)c; // to change timestamps Thread.sleep(1000); java.io.File f = FileUtil.toFile(obj.getPrimaryFile()); FileOutputStream os = new FileOutputStream(f); os.write("Ahoj\n".getBytes()); os.close(); // to change timestamps Thread.sleep(1000); doc.remove(0, doc.getLength()); doc.insertString(0, "Internal change\n", null); String txt = doc.getText(0, doc.getLength()); assertEquals("The right text is there", txt, "Internal change\n"); arr = getPanes(); assertNotNull("Panes are still open", arr); assertTrue("Document is remains modified", edit.isModified()); DD.toReturn.push(DialogDescriptor.YES_NO_OPTION); SaveCookie sc = obj.getLookup().lookup(SaveCookie.class); assertNotNull("File is modified and has save cookie", sc); try { edit.saveDocument(); // Since fix of #186364 UQE is catched in DataEditorSupport // fail("External modification detected, expect UserQuestionException"); } catch (UserQuestionException ex) { // Since fix of #186364 UQE is catched in DataEditorSupport fail("UserQuestionException should no longer be thrown"); waitEQ(); String txt2 = doc.getText(0, doc.getLength()); assertEquals("The right text from the IDE remains", txt2, "Internal change\n"); assertFileObject("Ahoj\n"); // rerun the action ex.confirmed(); String txt3 = doc.getText(0, doc.getLength()); assertEquals("No reload, text saved", "Internal change\n", txt3); } assertFalse("Editor saved", edit.isModified()); assertFileObject("Internal change\n"); waitEQ(); assertTrue("No dialog", DD.toReturn.isEmpty()); if (DD.error != null) { fail("Error in dialog:\n" + DD.error); } }
private static boolean doOpen(FileObject fo, int offset) { try { DataObject od = DataObject.find(fo); EditorCookie ec = od.getLookup().lookup(EditorCookie.class); LineCookie lc = od.getLookup().lookup(LineCookie.class); if (ec != null && lc != null && offset != -1) { StyledDocument doc = null; try { doc = ec.openDocument(); } catch (UserQuestionException uqe) { final Object value = DialogDisplayer.getDefault().notify( new NotifyDescriptor.Confirmation(uqe.getLocalizedMessage(), NbBundle.getMessage(UiUtils.class, "TXT_Question"), NotifyDescriptor.YES_NO_OPTION)); if (value != NotifyDescriptor.YES_OPTION) { return false; } uqe.confirmed(); doc = ec.openDocument(); } if (doc != null) { int line = NbDocument.findLineNumber(doc, offset); int lineOffset = NbDocument.findLineOffset(doc, line); int column = offset - lineOffset; if (line != -1) { Line l = lc.getLineSet().getCurrent(line); if (l != null) { doShow( l, column); return true; } } } } OpenCookie oc = od.getLookup().lookup(OpenCookie.class); if (oc != null) { doOpen(oc); return true; } } catch (IOException e) { if (log.isLoggable(Level.INFO)) log.log(Level.INFO, e.getMessage(), e); } return false; }
@Override protected boolean notifyModified () { boolean alreadyModified = isModified(); boolean retVal = super.notifyModified(); if (retVal) { // java source modification addSaveCookie(); } if (!alreadyModified) { FileObject formFile = formDataObject.getFormFile(); if (!formFile.canWrite()) { // Issue 74092 FileLock lock = null; try { lock = formFile.lock(); } catch (UserQuestionException uqex) { NotifyDescriptor nd = new NotifyDescriptor.Confirmation( uqex.getLocalizedMessage(), FormUtils.getBundleString("TITLE_UserQuestion"), // NOI18N NotifyDescriptor.YES_NO_OPTION); DialogDisplayer.getDefault().notify(nd); if (NotifyDescriptor.YES_OPTION.equals(nd.getValue())) { try { uqex.confirmed(); EventQueue.invokeLater(new Runnable() { @Override public void run() { reloadForm(); } }); } catch (IOException ioex) { ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioex); } } } catch (IOException ex) { ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); } finally { if (lock != null) { lock.releaseLock(); } } } updateMVTCDisplayName(); } return retVal; }
@Override public void actionPerformed(ActionEvent e) { try { DataObject od = DataObject.find(getFileObject()); EditorCookie ec = od.getLookup().lookup(EditorCookie.class); LineCookie lc = od.getLookup().lookup(LineCookie.class); if (ec != null && lc != null && getOffset() != -1) { StyledDocument doc; try { doc = ec.openDocument(); } catch (UserQuestionException uqe) { final Object value = DialogDisplayer.getDefault().notify( new NotifyDescriptor.Confirmation(uqe.getLocalizedMessage(), Bundle.TXT_Question(), NotifyDescriptor.YES_NO_OPTION)); if (value != NotifyDescriptor.YES_OPTION) { return; } uqe.confirmed(); doc = ec.openDocument(); } if (doc != null) { int line = NbDocument.findLineNumber(doc, getOffset()); int lineOffset = NbDocument.findLineOffset(doc, line); int column = getOffset() - lineOffset; if (line != -1) { Line l = lc.getLineSet().getCurrent(line); if (l != null) { doShow( l, column); return; } } } } OpenCookie oc = od.getLookup().lookup(OpenCookie.class); if (oc != null) { doOpen(oc); } } catch (IOException ex) { LOGGER.log(Level.WARNING, "An exception occurred while opening a file.", ex); } }
/** Called when the document is being modified. * The responsibility of this method is to inform the environment * that its document is modified. Current implementation * Just calls env.setModified (true) to notify it about * modification. * * @return true if the environment accepted being marked as modified * or false if it refused it and the document should still be unmodified */ protected boolean notifyModified () { boolean locked = true; try { env.markModified (); } catch (final UserQuestionException ex) { synchronized (this) { if (! this.inUserQuestionExceptionHandler){ this.inUserQuestionExceptionHandler = true; RequestProcessor.getDefault().post(new Runnable() { public void run () { NotifyDescriptor nd = new NotifyDescriptor.Confirmation (ex.getLocalizedMessage ()); Object res = DialogDisplayer.getDefault ().notify (nd); if (NotifyDescriptor.OK_OPTION.equals(res)) { try { ex.confirmed (); } catch (IOException ex1) { ErrorManager.getDefault ().notify (ex1); } } synchronized (CloneableEditorSupport.this) { CloneableEditorSupport.this.inUserQuestionExceptionHandler = false; } } }); } } locked = false; } catch (IOException e) { // locking failed if (e.getMessage () != e.getLocalizedMessage ()) { StatusDisplayer.getDefault().setStatusText(e.getLocalizedMessage()); } locked = false; } if (!locked) { revertUpcomingUndo(); return false; } updateTitles (); return true; }