Refine search
private static BaseDocument getDocument(final FileObject fo) throws DataObjectNotFoundException, IOException { BaseDocument doc = null; DataObject dObj = DataObject.find(fo); if (dObj != null) { EditorCookie editor = dObj.getLookup().lookup(EditorCookie.class); if (editor != null) { doc = (BaseDocument) editor.openDocument(); } } return doc; }
dobj = DataObject.find(fileObject); EditorCookie ec = dobj.getLookup().lookup(EditorCookie.class); throw new IOException("Can't open " + fileObject.getNameExt()); document = ec.openDocument(); } else { document = ec.getDocument(); Exceptions.printStackTrace(ex); Exceptions.printStackTrace(ioe);
@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 } } });
public boolean save() throws IOException { if (editorCookie == null) { return false; } if (editorCookie.isModified()) { editorCookie.saveDocument(); return true; } return false; }
public static void updateDocument(DataObject dobj, org.w3c.dom.Document doc) throws javax.swing.text.BadLocationException, java.io.IOException { org.openide.cookies.EditorCookie editor = (EditorCookie)dobj.getCookie(EditorCookie.class); javax.swing.text.Document textDoc = editor.getDocument(); if (textDoc == null) { textDoc = editor.openDocument(); } TomcatInstallUtil.updateDocument(textDoc,TomcatInstallUtil.getDocumentText(doc),"<Server"); //NOI18N SaveCookie savec = (SaveCookie) dobj.getCookie(SaveCookie.class); if (savec!=null) savec.save(); }
/** * opens document even if it is very big by silently confirming open * @param cookie * @return */ public static StyledDocument openDocument(EditorCookie cookie) { if (cookie == null) { return null; } StyledDocument document = null; try { try { document = cookie.openDocument(); } catch (UserQuestionException e) { e.confirmed(); document = cookie.openDocument(); } } catch(UserQuestionException e) { // no need to report } catch (IOException ex) { Exceptions.printStackTrace(ex); } cookie.prepareDocument().waitFinished(); return document; }
for (PathRecognizer pr : Lookup.getDefault().lookupAll(PathRecognizer.class)) { Set<String> ids = pr.getSourcePathIds(); Set<FileObject> nonRecursiveRoots = new HashSet<FileObject>(); for (DataObject d : context.lookupAll(DataObject.class)) { if (cancel.get()) return; if (nonRecursiveRoots.contains(d.getPrimaryFile())) continue; addRecursivelly(d.getPrimaryFile(), toFormat, sourceIds, null, null, cancel); if (cancel.get()) break ; try { DataObject d = DataObject.find(current); EditorCookie ec = d.getLookup().lookup(EditorCookie.class); sd = ec.openDocument(); } catch (UserQuestionException uqe) { uqe.confirmed(); sd = ec.openDocument(); ec.saveDocument(); } catch (UserQuestionException uqe) { uqe.confirmed(); } catch (IOException ex) { Exceptions.printStackTrace(ex); } finally { handle.progress(++done);
static Document getDatabaseYml(FileObject projectDir) { FileObject fo = projectDir.getFileObject("config/database.yml"); // NOI18N if (fo == null) { return null; } try { DataObject dobj = DataObject.find(fo); EditorCookie ec = dobj.getCookie(EditorCookie.class); if (ec != null) { try { return ec.openDocument(); } catch (IOException ex) { Exceptions.printStackTrace(ex); } } } catch (DataObjectNotFoundException donfe) { Exceptions.printStackTrace(donfe); } return null; }
public static void reformat(DataObject dob) { try { EditorCookie ec = dob.getLookup().lookup(EditorCookie.class); if (ec == null) { return; final StyledDocument doc = ec.openDocument(); final Reformat reformat = Reformat.get(doc); Exceptions.printStackTrace(ex); } finally { reformat.unlock(); ec.saveDocument(); Exceptions.printStackTrace(ex);
public static FileBuffer createFileBuffer(FileObject fo) { Parameters.notNull("null file object", fo); // NOI18N if (fo.isValid()) { try { DataObject dao = DataObject.find(fo); if (dao.isModified()) { EditorCookie editor = dao.getLookup().lookup(EditorCookie.class); if (editor != null) { Document doc = editor.getDocument(); if (doc != null) { return new FileBufferDoc(fo, doc); } } } } catch (DataObjectNotFoundException e) { // nothing } return new FileBufferFile(fo); } else { FileSystem fs; try { fs = fo.getFileSystem(); } catch (FileStateInvalidException ex) { Exceptions.printStackTrace(ex); fs = InvalidFileObjectSupport.getDummyFileSystem(); } return new FileBufferFile(InvalidFileObjectSupport.getInvalidFileObject(fs, fo.getPath())); } }
public static Document getDocument(FileObject fo) { if (fo != null && fo.isValid()) { try { DataObject dob = DataObject.find(fo); if (dob != null && dob.isValid()) { EditorCookie ec = dob.getLookup().lookup(EditorCookie.class); if (ec != null) { return ec.getDocument(); } } } catch (IOException ex) { // file can be removed or became invalid // we catch IOException, because FileStateInvalidException is IOException // but is not declared to be thrown from DataObject.find if (fo.isValid() && !fo.isVirtual()) { Exceptions.printStackTrace(ex); } } } return null; }
/** * Saves file. * * @param fo - file object */ private static void saveFileAndMarkAsReadOnly(FileObject fo) { try { DataObject dob = DataObject.find(fo); EditorCookie ec = dob.getLookup().lookup(EditorCookie.class); ec.saveDocument(); ReadOnlySupport ro = dob.getLookup().lookup(ReadOnlySupport.class); if (ro != null) { ro.setReadOnly(true); } } catch (DataObjectNotFoundException e) { //do nothing, memory file already deleted } catch (FileStateInvalidException e) { //do nothing, memory file already deleted } catch (IOException ex) { Exceptions.printStackTrace(ex); } }
@Override protected void performAction(Node[] activatedNodes) { Lookup l = activatedNodes[0].getLookup(); FileObject fo = l.lookup(FileObject.class); EditorCookie ec = l.lookup(EditorCookie.class); if (fo == null && ec == null) { throw new UnsupportedOperationException(); JEditorPane[] panes = ec.getOpenedPanes(); if (panes.length > 0) { final int cursor = panes[0].getCaret().getDot(); JavaSource js = JavaSource.forDocument(panes[0].getDocument()); if(js == null) { return;
/** Add the line offset into the jump history */ private void addPositionToJumpList(String url, Line l, int column) { DataObject dataObject = getDataObject(url); if (dataObject != null) { EditorCookie ec = dataObject.getLookup().lookup(EditorCookie.class); if (ec != null) { try { StyledDocument doc = ec.openDocument(); JEditorPane[] eps = ec.getOpenedPanes(); if (eps != null && eps.length > 0) { JumpList.addEntry(eps[0], NbDocument.findLineOffset(doc, l.getLineNumber()) + column); } } catch (java.io.IOException ioex) { ErrorManager.getDefault().notify(ioex); } } } }
@Override public void outputLineCleared(OutputEvent ev) { try { DataObject dob = DataObject.find(file); StyledDocument doc = null; if (dob.isValid()) { EditorCookie ec = dob.getLookup().lookup(EditorCookie.class); if (ec != null) { doc = ec.getDocument(); } } if (doc != null) { HintsController.setErrors(doc, CC_compiler_errors, Collections.<ErrorDescription>emptyList()); } } catch (DataObjectNotFoundException ex) { } }
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) { sdoc = ec.openDocument(); } } } catch (Exception e) { // fallback to other means of obtaining the source } } else { sdoc = ss.getLookup().lookup(Document.class); } return sdoc; }
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 } }
/*package*/ static void navigateToOccurrence(boolean next) { final Node[] activatedNodes = TopComponent.getRegistry().getActivatedNodes(); // check whether current file is C/C++ DataObject dobj = activatedNodes[0].getLookup().lookup(DataObject.class); FileObject fo = (dobj == null) ? null : dobj.getPrimaryFile(); String mime = (fo == null) ? "" : fo.getMIMEType(); if (MIMENames.isHeaderOrCppOrC(mime)) { EditorCookie ec = dobj.getLookup().lookup(EditorCookie.class); Document doc = ec.getDocument(); int position = CaretAwareCsmFileTaskFactory.getLastPosition(dobj.getPrimaryFile()); int goTo = findOccurrencePosition(next, doc, position); if (goTo > 0) { JEditorPane pane = NbDocument.findRecentEditorPane(ec); pane.setCaretPosition(goTo); } else { StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(SemanticUtils.class, "cpp-no-marked-occurrence")); } } } }
private static FileBuffer createFileBuffer(DataObject dao) { FileObject fo = dao.getPrimaryFile(); if (fo.isValid()) { if (dao.isModified()) { EditorCookie editor = dao.getLookup().lookup(EditorCookie.class); if (editor != null) { Document doc = editor.getDocument(); if (doc != null) { return new FileBufferDoc(fo, doc); } } } } return new FileBufferFile(fo); }
doc = ec.openDocument(); } catch (IOException ex) { return ; if (ep == null || ep.getDocument() != doc) { return ; return; final FileObject fo = line.getLookup().lookup(FileObject.class); if (isFunctionPtr[0]) {