Java Code Examples for org.openide.loaders.MultiDataObject#secondaryEntries()

The following examples show how to use org.openide.loaders.MultiDataObject#secondaryEntries() . 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
/**
 * Finds entry of the given {@code MultiDataObject} that corresponds to the
 * to the given {@code FileObject}.
 * @param  dataObj  {@code MultiDataObject} to search for the corresponding
 *                  entry
 * @param  fileObj  file for which the entry is to be found
 * @return  found entry, or {@code null} if not found
 */
private static MultiDataObject.Entry findEntryForFile(MultiDataObject dataObj,
                                                      FileObject fileObj) {
    MultiDataObject.Entry primaryEntry;

    primaryEntry = dataObj.getPrimaryEntry();
    if (fileObj.equals(primaryEntry.getFile())) {
        return primaryEntry;
    }

    for (MultiDataObject.Entry entry : dataObj.secondaryEntries()) {
        if (fileObj.equals(entry.getFile())) {
            return primaryEntry;
        }
    }

    return null;
}
 
Example 2
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 3
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 4
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 5
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 6
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();
}