Java Code Examples for org.openide.nodes.CookieSet#Factory

The following examples show how to use org.openide.nodes.CookieSet#Factory . 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: DiffSidebar.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Tries to obtain an {@code EditorCookie} representing the given file.
 * @param  fileObj  file to get an {@code EditorCookie} from
 * @return  {@code EditorCookie} representing the file, or {@code null}
 * @throws  java.io.IOException
 *          if there was some I/O error while reading the file's content
 */
private static EditorCookie getEditorCookie(FileObject fileObj) throws IOException {
    DataObject dao;
    try {
        dao = DataObject.find(fileObj);
    } catch (DataObjectNotFoundException ex) {
        return null;
    }

    if (dao instanceof MultiDataObject) {
        MultiDataObject.Entry entry = findEntryForFile((MultiDataObject) dao, fileObj);
        if ((entry != null) && (entry instanceof CookieSet.Factory)) {
            CookieSet.Factory factory = (CookieSet.Factory) entry;
            return factory.createCookie(EditorCookie.class);   //can be null
        }
    }

    return dao.getCookie(EditorCookie.class);                  //can be null
}
 
Example 2
Source File: EjbJarMultiViewDataObject.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public EjbJarMultiViewDataObject(FileObject pf, EjbJarDataLoader loader) throws DataObjectExistsException {
    super(pf, loader);
    
    // added ValidateXMLCookie
    InputSource in = DataObjectAdapters.inputSource(this);
    ValidateXMLCookie validateCookie = new ValidateXMLSupport(in);
    CookieSet set = getCookieSet();
    set.add(validateCookie);
    CookieSet.Factory viewCookieFactory = new ViewCookieFactory();
    set.add(ViewCookie.class, viewCookieFactory);

    // initialize srcRoots
    refreshSourcesTask.schedule(0);

    RP.submit(new Runnable() {
        @Override
        public void run() {
            Project project = getProject();
            if (project != null) {
                Sources sources = ProjectUtils.getSources(project);
                sources.addChangeListener(EjbJarMultiViewDataObject.this);
            }
            // refresh srcRoots if any change happened in the meantime
            refreshSourcesTask.schedule(0);
        }
    });
}
 
Example 3
Source File: DiffStreamSource.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static EditorCookie.Observable getEditableCookie (File file) {
    EditorCookie.Observable editorCookie = null;
    if (file == null) {
        return null;
    }
    FileObject fileObj = FileUtil.toFileObject(file);
    if (fileObj != null) {
        try {
            DataObject dao = DataObject.find(fileObj);
            if (dao instanceof MultiDataObject) {
                MultiDataObject mdao = (MultiDataObject) dao;
                for (MultiDataObject.Entry entry : mdao.secondaryEntries()) {
                    if (fileObj == entry.getFile() && entry instanceof CookieSet.Factory) {
                        CookieSet.Factory factory = (CookieSet.Factory) entry;
                        EditorCookie ec = factory.createCookie(EditorCookie.class);
                        if (ec instanceof EditorCookie.Observable) {
                            editorCookie = (EditorCookie.Observable) ec;
                        }
                    }
                }
            }
            if (editorCookie == null) {
                EditorCookie cookie = dao.getCookie(EditorCookie.class);
                if (cookie instanceof EditorCookie.Observable) {
                    editorCookie = (EditorCookie.Observable) cookie;
                }
            }
        } catch (DataObjectNotFoundException ex) {
        }
    }
    return editorCookie;
}
 
Example 4
Source File: DiffUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * @since 1.9.1
 */
public static EditorCookie getEditorCookie(Document doc) {
    if (doc == null) {
        return null;
    }

    DataObject dataObj = (DataObject) doc.getProperty(
                                        Document.StreamDescriptionProperty);
    if (dataObj == null) {
        return null;
    }

    EditorCookie plain = null;

    if (dataObj instanceof MultiDataObject) {
        MultiDataObject multiDataObj = (MultiDataObject) dataObj;
        for (MultiDataObject.Entry entry : multiDataObj.secondaryEntries()) {
            if (entry instanceof CookieSet.Factory) {
                CookieSet.Factory factory = (CookieSet.Factory) entry;
                EditorCookie ec = factory.createCookie(EditorCookie.class);
                if (ec.getDocument() == doc) {
                    if (ec instanceof EditorCookie.Observable) {
                        return (EditorCookie.Observable) ec;
                    }

                    if (plain == null) {
                        plain = ec;
                    }
                }
            }
        }
    }

    return chooseBetterEditorCookie(getEditorCookie(dataObj, false), plain);
}
 
Example 5
Source File: DiffSidebarManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private FileObject fileForDataobject(Document doc, MultiDataObject dobj) {
    for (MultiDataObject.Entry entry : dobj.secondaryEntries()) {
        if (entry instanceof CookieSet.Factory) {
            CookieSet.Factory factory = (CookieSet.Factory) entry;
            EditorCookie ec = factory.createCookie(EditorCookie.class);
            Document entryDocument = ec.getDocument();
            if (entryDocument == doc) {
                return entry.getFile();
            }
        }
    }
    return dobj.getPrimaryFile();
}
 
Example 6
Source File: DiffStreamSource.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static EditorCookie.Observable getEditableCookie (File file) {
    EditorCookie.Observable editorCookie = null;
    if (file == null) {
        return null;
    }
    FileObject fileObj = FileUtil.toFileObject(file);
    if (fileObj != null) {
        try {
            DataObject dao = DataObject.find(fileObj);
            if (dao instanceof MultiDataObject) {
                MultiDataObject mdao = (MultiDataObject) dao;
                for (MultiDataObject.Entry entry : mdao.secondaryEntries()) {
                    if (fileObj == entry.getFile() && entry instanceof CookieSet.Factory) {
                        CookieSet.Factory factory = (CookieSet.Factory) entry;
                        EditorCookie ec = factory.createCookie(EditorCookie.class);
                        if (ec instanceof EditorCookie.Observable) {
                            editorCookie = (EditorCookie.Observable) ec;
                        }
                    }
                }
            }
            if (editorCookie == null) {
                EditorCookie cookie = dao.getCookie(EditorCookie.class);
                if (cookie instanceof EditorCookie.Observable) {
                    editorCookie = (EditorCookie.Observable) cookie;
                }
            }
        } catch (DataObjectNotFoundException ex) {
        }
    }
    return editorCookie;
}
 
Example 7
Source File: EditableDiffView.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void setSource2 (StreamSource ss, Document sdoc) throws IOException {
    secondSourceAvailable = false;
    EditorKit kit = jEditorPane2.getEditorPane().getEditorKit();
    if (kit == null) throw new IOException("Missing Editor Kit"); // NOI18N
    
    modifiedDocument = sdoc;
    if (sdoc != null && ss.isEditable()) {
        DataObject dao = (DataObject) sdoc.getProperty(Document.StreamDescriptionProperty);
        if (dao != null) {
            if (dao instanceof MultiDataObject) {
                MultiDataObject mdao = (MultiDataObject) dao;
                for (MultiDataObject.Entry entry : mdao.secondaryEntries()) {
                    if (entry instanceof CookieSet.Factory) {
                        CookieSet.Factory factory = (CookieSet.Factory) entry;
                        EditorCookie ec = factory.createCookie(EditorCookie.class);
                        Document entryDocument = ec.getDocument();
                        if (entryDocument == sdoc && ec instanceof EditorCookie.Observable) {
                            editableCookie = (EditorCookie.Observable) ec;
                            editableDocument = sdoc;
                            editorUndoRedo = getUndoRedo(ec);
                        }
                    }
                }
            }
            if (editableCookie == null) {
                EditorCookie cookie = dao.getCookie(EditorCookie.class);
                if (cookie instanceof EditorCookie.Observable) {
                    editableCookie = (EditorCookie.Observable) cookie;
                    editableDocument = sdoc;
                    editorUndoRedo = getUndoRedo(cookie);
                }
            }
        }
    }
    Document doc = sdoc != null ? sdoc : kit.createDefaultDocument();
    if (sdoc != null || !Boolean.TRUE.equals(skipFile)) {
        if (jEditorPane2.getEditorPane().getUI() instanceof BaseTextUI) {
            if (sdoc == null) {
                Reader r = ss.createReader();
                if (r != null) {
                    secondSourceAvailable = true;
                    try {
                        kit.read(r, doc, 0);
                    } catch (javax.swing.text.BadLocationException e) {
                        throw new IOException("Can not locate the beginning of the document."); // NOI18N
                    } finally {
                        r.close();
                    }
                }
            } else {
                secondSourceAvailable = true;
            }
        } else {
            secondSourceUnsupportedTextUI = true;
        }
    }
    jEditorPane2.initActions();
    view.putClientProperty(UndoRedo.class, editorUndoRedo);
    jEditorPane2.getEditorPane().setDocument(doc);
    jEditorPane2.getEditorPane().setEditable(editableCookie != null);
    if (doc instanceof NbDocument.CustomEditor) {
        Component c = ((NbDocument.CustomEditor)doc).createEditor(jEditorPane2.getEditorPane());
        if (c instanceof JComponent) {
            jEditorPane2.setCustomEditor((JComponent)c);
        }
    }
    
    customizeEditor(jEditorPane2.getEditorPane());
    jViewport2 = jEditorPane2.getScrollPane().getViewport();
    joinScrollBars();
}