private static StyledDocument getDocument (EditorCookie ec) { return ec == null ? null : ec.getDocument(); }
public javax.swing.text.StyledDocument getDocument() { return currentEditorCookie().getDocument(); }
private Document getDocument() { Document document = docRef.get(); if (document != null) { return document; } DataObject dataObject = getDataObject(); EditorCookie ec = dataObject == null ? null : dataObject.getLookup().lookup(EditorCookie.class); if (ec == null) { return null; } Document doc = ec.getDocument(); docRef = new WeakReference<>(doc); return doc; }
public HighlightAnnotatable(AttributeSet attrs, int start, int end, FileObject fo) { this.attrs = attrs; this.start = start; this.end = end; try { DataObject dobj = DataObject.find(fo); EditorCookie ec = dobj.getCookie(EditorCookie.class); doc = ec.getDocument(); } catch (DataObjectNotFoundException ex) { } }
/** This method returns a BaseDocument for the configuration file. If the configuration * file is not opened, then the document is not created yet and this method push to load * the document to the memory. */ public static BaseDocument getBaseDocument(DataObject dataObject){ BaseDocument document = null; if (dataObject != null){ synchronized (dataObject){ EditorCookie editor = dataObject.getLookup().lookup(EditorCookie.class); if (editor != null){ document = (BaseDocument)editor.getDocument(); if (document == null){ Task preparing = editor.prepareDocument(); preparing.waitFinished(); document = (BaseDocument)editor.getDocument(); } } } } return document; }
/** This method returns a BaseDocument for the configuration file. If the configuration * file is not opened, then the document is not created yet and this method push to load * the document to the memory. */ public static BaseDocument getBaseDocument(DataObject dataObject){ BaseDocument document = null; if (dataObject != null){ synchronized (dataObject){ EditorCookie editor = dataObject.getLookup().lookup(EditorCookie.class); if (editor != null){ document = (BaseDocument)editor.getDocument(); if (document == null){ Task preparing = editor.prepareDocument(); preparing.waitFinished(); document = (BaseDocument)editor.getDocument(); } } } } return document; } }
private void checkClosed(Object o){ if (o instanceof Set<?>) { Set<EditorCookie> editorCookies = new HashSet<EditorCookie>(); for(Object top : (Set<?>) o){ if (top instanceof EditorCookie){ EditorCookie cookie = (EditorCookie) top; if (MIMENames.isFortranOrHeaderOrCppOrC( DocumentUtilities.getMimeType(cookie.getDocument()))) { editorCookies.add(cookie); } } } checkClosed(editorCookies); } }
@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) { } }
@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) { } }
public HighlightAnnotatable(AttributeSet attrs, int start, int end, FileObject fo) { this.attrs = attrs; this.start = start; this.end = end; try { DataObject dobj = DataObject.find(fo); EditorCookie ec = dobj.getLookup().lookup(EditorCookie.class); if (ec != null) { doc = ec.getDocument(); if (doc == null) { try { doc = ec.openDocument(); } catch (java.io.IOException ioex) {} } } } catch (DataObjectNotFoundException ex) { } }
public HighlightAnnotatable(AttributeSet attrs, int start, int end, FileObject fo) { this.attrs = attrs; this.start = start; this.end = end; try { DataObject dobj = DataObject.find(fo); EditorCookie ec = dobj.getLookup().lookup(EditorCookie.class); if (ec != null) { doc = ec.getDocument(); if (doc == null) { try { doc = ec.openDocument(); } catch (java.io.IOException ioex) {} } } } catch (DataObjectNotFoundException ex) { } }
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; }
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); }
@Override protected PhaseRunner createTask(final FileObject fo) { PhaseRunner pr = null; try { DataObject dobj = DataObject.find(fo); EditorCookie ec = dobj.getCookie(EditorCookie.class); Document doc = ec.getDocument(); if (doc != null) { pr = new SemanticHighlighter(doc); } } catch (DataObjectNotFoundException ex) { ex.printStackTrace(); } return pr != null ? pr : lazyRunner(); }
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(); }
@Override protected PhaseRunner createTask(FileObject fo) { PhaseRunner pr = null; try { final DataObject dobj = DataObject.find(fo); EditorCookie ec = dobj.getCookie(EditorCookie.class); final CsmFile file = CsmUtilities.getCsmFile(dobj, false, false); final Document doc = ec.getDocument(); if (doc != null && file != null) { pr = new PhaseRunnerImpl(dobj, file, doc); } } catch (DataObjectNotFoundException ex) { ex.printStackTrace(); } return pr != null ? pr : lazyRunner(); }
private static int findNumLines(String url) { FileObject file; try { file = URLMapper.findFileObject (new URL(url)); } catch (MalformedURLException e) { return 0; } if (file == null) return 0; DataObject dataObject; try { dataObject = DataObject.find (file); } catch (DataObjectNotFoundException ex) { return 0; } EditorCookie ec = (EditorCookie) dataObject.getCookie(EditorCookie.class); if (ec == null) return 0; ec.prepareDocument().waitFinished(); Document d = ec.getDocument(); if (!(d instanceof StyledDocument)) return 0; StyledDocument sd = (StyledDocument) d; return NbDocument.findLineNumber(sd, sd.getLength()); }
/*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")); } } } }
public static Line getCurrentLine() { EditorCookie e = getCurrentEditorCookie(); if (e == null) return null; JEditorPane ep = getCurrentEditor(e); if (ep == null) return null; StyledDocument d = e.getDocument(); if (d == null) return null; int lineNo = NbDocument.findLineNumber(d, ep.getCaret().getDot()); // Editor numbers lines from 0! Line l = null; try { l = e.getLineSet().getCurrent(lineNo + 1); } catch (IndexOutOfBoundsException x) { // 6494346 } return l; }
private ASTNode getCurrentRootNode () { Node[] ns = TopComponent.getRegistry ().getActivatedNodes (); if (ns.length != 1) return null; EditorCookie editorCookie = ns [0].getLookup (). lookup (EditorCookie.class); if (editorCookie == null) return null; if (editorCookie.getOpenedPanes () == null) return null; if (editorCookie.getOpenedPanes ().length < 1) return null; JEditorPane pane = editorCookie.getOpenedPanes () [0]; if (caretListener == null) caretListener = new CListener (); if (lastPane != null && lastPane != pane) { lastPane.removeCaretListener (caretListener); lastPane = null; } if (lastPane == null) { pane.addCaretListener (caretListener); lastPane = pane; } Document document = editorCookie.getDocument (); if (document == null || !(document instanceof NbEditorDocument)) return null; return ParserManagerImpl.getImpl (document).getAST (); }