public void open() { currentEditorCookie().open(); }
@Override public void run() { try { EditorCookie ed = dob.getLookup().lookup(EditorCookie.class); if (ed != null && /* not true e.g. for *_ja.properties */ file == dob.getPrimaryFile()) { if (lineNum == -1) { // OK, just open it. ed.open(); } else { ed.openDocument();//XXX getLineSet doesn't do it for you try { Line l = ed.getLineSet().getOriginal(lineNum - 1); if (!l.isDeleted()) { l.show(ShowOpenType.OPEN, ShowVisibilityType.FOCUS); } } catch (IndexOutOfBoundsException ioobe) { // Probably harmless. Bogus line number. ed.open(); } } } else { java.awt.Toolkit.getDefaultToolkit().beep(); } } catch (Exception ex2) { // XXX see above, should not be necessary to call openDocument // at all } } });
private void openIssueLocation(IssueLocation issueLocation) { try { FileObject fileObject = issueLocation.getFileObject(projectContext, projectKeyChecker); if (fileObject == null) { notifyFileObjectNotFound(issueLocation); } else { EditorCookie editorCookie = IssueLocation.getEditorCookie(fileObject); if (editorCookie != null) { editorCookie.openDocument(); editorCookie.open(); Line line = issueLocation.getLine(editorCookie); line.show(Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS); } } } catch (IOException ex) { LOGGER.log(Level.WARNING, ex.getMessage(), ex); Exceptions.printStackTrace(ex); } catch (ProjectNotFoundException ex) { String message = org.openide.util.NbBundle.getMessage(SonarIssuesTopComponent.class, "ProjectNotFound", ex.getShortProjectKey()); DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(message, NotifyDescriptor.ERROR_MESSAGE)); } }
protected void performAction(DesignBean[] designBeans) { EditorCookie editorCookie = getNavigationFileEditorCookie(designBeans); if (editorCookie == null) { ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, new IllegalStateException("Editor cookie on navigation file is null for designBeans=" + Arrays.asList(designBeans))); // NOI18N } else { editorCookie.open(); } }
/** Either opens the in text editor or asks user questions. */ public void open() { EditorCookie ic = (EditorCookie)getCookie (EditorCookie.class); if (ic != null) { ic.open(); } else { // ask a query java.util.ArrayList options = new java.util.ArrayList (); options.add (NotifyDescriptor.OK_OPTION); options.add (NotifyDescriptor.CANCEL_OPTION); NotifyDescriptor nd = new NotifyDescriptor ( NbBundle.getMessage (DefaultDataObject.class, "MSG_BinaryFileQuestion"), NbBundle.getMessage (DefaultDataObject.class, "MSG_BinaryFileWarning"), NotifyDescriptor.DEFAULT_OPTION, NotifyDescriptor.QUESTION_MESSAGE, options.toArray(), null ); Object ret = DialogDisplayer.getDefault().notify (nd); if (ret != NotifyDescriptor.OK_OPTION) { return; } EditorCookie c = (EditorCookie)getCookie (EditorCookie.class, true); c.open (); } }
/** * Open server.xml file in editor. */ public void editServerXml() { FileObject fileObject = getTomcatConf(); if (fileObject != null) { DataObject dataObject = null; try { dataObject = DataObject.find(fileObject); } catch(DataObjectNotFoundException ex) { Logger.getLogger(TomcatInstanceNode.class.getName()).log(Level.INFO, null, ex); } if (dataObject != null) { EditorCookie editorCookie = (EditorCookie)dataObject.getCookie(EditorCookie.class); if (editorCookie != null) { editorCookie.open(); } else { Logger.getLogger(TomcatInstanceNode.class.getName()).log(Level.INFO, "Cannot find EditorCookie."); // NOI18N } } } }
private static boolean openFile(FileObject file) { if (file == null) { return false; } DataObject dObj; try { dObj = DataObject.find(file); } catch (DataObjectNotFoundException ex) { return false; } EditorCookie editorCookie = dObj.getCookie(EditorCookie.class); if (editorCookie == null) { return false; } editorCookie.open(); return true; } }
private boolean openByCookie(Node.Cookie cookie, Class cookieClass) { if ((cookieClass == EditorCookie.class) || (cookieClass == EditorCookie.Observable.class)) { ((EditorCookie) cookie).open(); } else if (cookieClass == OpenCookie.class) { ((OpenCookie) cookie).open(); } else if (cookieClass == EditCookie.class) { ((EditCookie) cookie).edit(); } else if (cookieClass == ViewCookie.class) { ((ViewCookie) cookie).view(); } else { throw new IllegalArgumentException("Reopen #58766: " + cookieClass); // NOI18N } return true; } }
private boolean openByCookie(Node.Cookie cookie, Class cookieClass) { if ((cookieClass == EditorCookie.class) || (cookieClass == EditorCookie.Observable.class)) { ((EditorCookie) cookie).open(); } else if (cookieClass == OpenCookie.class) { ((OpenCookie) cookie).open(); } else if (cookieClass == EditCookie.class) { ((EditCookie) cookie).edit(); } else if (cookieClass == ViewCookie.class) { ((ViewCookie) cookie).view(); } else { throw new IllegalArgumentException("Reopen #58766: " + cookieClass); // NOI18N } return true; } }
private void doWork() { if (url == null) { return; } try { FileObject fo; if (url.getProtocol().equals("file")) { //NOI18N fo = FileUtil.toFileObject(new File(url.getPath())); } else { fo = URLMapper.findFileObject(url); //NOI18N } DataObject dobj = DataObject.find(fo); EditorCookie ed = dobj.getLookup().lookup(EditorCookie.class); if (ed != null && fo == dobj.getPrimaryFile()) { if (lineNumber == -1) { ed.open(); } else { lc = (LineCookie) dobj.getLookup().lookup(LineCookie.class); SwingUtilities.invokeLater(this); } } else { Toolkit.getDefaultToolkit().beep(); } } catch (Exception ex) { // ignore } }
protected void performAction (final Node[] activatedNodes) { for (int i = 0; i < activatedNodes.length; i++) { JspDataObject jspdo = (JspDataObject)activatedNodes[i].getCookie(JspDataObject.class); if (jspdo != null) { jspdo.refreshPlugin(true); EditorCookie cook = jspdo.getServletEditor(); if (cook != null) cook.open (); else { //show error dialog String msg = NbBundle.getMessage(EditServletAction.class, "ERR_CantEditServlet"); String title = NbBundle.getMessage(EditServletAction.class, "EditServlet"); NotifyDescriptor descriptor = new NotifyDescriptor(msg, title, NotifyDescriptor.DEFAULT_OPTION, NotifyDescriptor.ERROR_MESSAGE, new Object[]{NotifyDescriptor.OK_OPTION}, null); DialogDisplayer.getDefault().notify(descriptor); } } } }
@Override public void run() { FileObject selectedFile = selectedEditorFile(); // Do not touch editor when it is switched to a related file if ((selectedFile == null) || !isStyledMimeType(selectedFile.getMIMEType()) || !DependentFileQuery.isDependent(fob, selectedFile)) { try { DataObject dob = DataObject.find(fob); EditorCookie editor = dob.getLookup().lookup(EditorCookie.class); if (editor != null) { editor.open(); } } catch (DataObjectNotFoundException ex) { } } } });
/** * Open given file in editor. * @return true if file was opened or false */ public static boolean openFile(FileObject fo) { DataObject dobj; try { dobj = DataObject.find(fo); } catch (DataObjectNotFoundException e) { getLogger().log(Level.WARNING, null, e); return false; } assert dobj != null; EditorCookie editorCookie = dobj.getCookie(EditorCookie.class); if (editorCookie != null) { editorCookie.open(); return true; } OpenCookie openCookie = dobj.getCookie(OpenCookie.class); if (openCookie != null) { openCookie.open(); return true; } return false; }
@Override public void actionPerformed(ActionEvent e) { dd.setClosingOptions(new Object[] {commitButton, cancelButton}); SaveCookie[] saveCookies = diffProvider.getSaveCookies(); if (cancelButton == e.getSource()) { if (saveCookies.length > 0) { if (SaveBeforeClosingDiffConfirmation.allSaved(saveCookies) || !isShowing()) { EditorCookie[] editorCookies = diffProvider.getEditorCookies(); for (EditorCookie cookie : editorCookies) { cookie.open(); } } else { dd.setClosingOptions(new Object[0]); } } dd.setValue(cancelButton); } else if (commitButton == e.getSource()) { if (saveCookies.length > 0 && !SaveBeforeCommitConfirmation.allSaved(saveCookies)) { dd.setClosingOptions(new Object[0]); } else if (!canCommit()) { dd.setClosingOptions(new Object[0]); } dd.setValue(commitButton); } } });
@Override public void actionPerformed(ActionEvent e) { dd.setClosingOptions(new Object[] {commitButton, cancelButton}); SaveCookie[] saveCookies = panel.getSaveCookies(); if (cancelButton == e.getSource()) { if (saveCookies.length > 0) { if (SaveBeforeClosingDiffConfirmation.allSaved(saveCookies) || !panel.isShowing()) { EditorCookie[] editorCookies = panel.getEditorCookies(); for (EditorCookie cookie : editorCookies) { cookie.open(); } } else { dd.setClosingOptions(new Object[0]); } } dd.setValue(cancelButton); } else if (commitButton == e.getSource()) { if (saveCookies.length > 0 && !SaveBeforeCommitConfirmation.allSaved(saveCookies)) { dd.setClosingOptions(new Object[0]); } else if (!panel.canCommit()) { dd.setClosingOptions(new Object[0]); } dd.setValue(commitButton); } } });
@Override protected void performContextAction(Node[] nodes) { if (visible(nodes)) { JEditorPane pane = activatedEditorPane(nodes); AnnotationBarManager.hideAnnotationBar(pane); } else { EditorCookie ec = activatedEditorCookie(nodes); if (ec == null) return; final File file = activatedFile(nodes); JEditorPane[] panes = ec.getOpenedPanes(); if (panes == null) { ec.open(); panes = ec.getOpenedPanes(); } if (panes == null) { return; } final JEditorPane currentPane = panes[0]; showAnnotations(currentPane, file, null, true); } }