Java Code Examples for org.openide.nodes.Node#Cookie

The following examples show how to use org.openide.nodes.Node#Cookie . 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: JspHyperlinkProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void openInEditor(FileObject fObj) {
    if (fObj != null) {
        DataObject dobj;
        try {
            dobj = DataObject.find(fObj);
        } catch (DataObjectNotFoundException e) {
            Exceptions.printStackTrace(e);
            return;
        }
        if (dobj != null) {
            Node.Cookie cookie = dobj.getLookup().lookup(EditCookie.class);
            if (cookie != null) {
                ((EditCookie) cookie).edit();
            }
        }
    }
}
 
Example 2
Source File: OpenInEditorAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private final boolean openDataObjectByCookie(DataObject dataObject) {
    Node.Cookie cookie;
 
    if ((cookie = dataObject.getCookie(EditorCookie.Observable.class)) != null)
        return openByCookie(cookie, EditorCookie.Observable.class);
    if ((cookie = dataObject.getCookie(EditorCookie.class)) != null)
        return openByCookie(cookie, EditorCookie.class);
    if ((cookie = dataObject.getCookie(OpenCookie.class)) != null)
        return openByCookie(cookie, OpenCookie.class);
    if ((cookie = dataObject.getCookie(EditCookie.class)) != null)
        return openByCookie(cookie, EditCookie.class);
    if ((cookie = dataObject.getCookie(ViewCookie.class)) != null)
        return openByCookie(cookie, ViewCookie.class);
    
    return false;
}
 
Example 3
Source File: StrutsConfigHyperlinkProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void openInEditor(FileObject fObj){
    if (fObj != null){
        DataObject dobj = null;
        try{
            dobj = DataObject.find(fObj);
        } catch (DataObjectNotFoundException e){
            Exceptions.printStackTrace(e);
            return;
        }
        if (dobj != null){
            Node.Cookie cookie = dobj.getCookie(OpenCookie.class);
            if (cookie != null)
                ((OpenCookie)cookie).open();
        }
    }
}
 
Example 4
Source File: GraphNode.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public <T extends Node.Cookie> T getCookie(Class<T> aClass) {
    if (aClass == DiffGraphCookie.class) {
        InputGraphProvider graphProvider = Utilities.actionsGlobalContext().lookup(InputGraphProvider.class);

        InputGraph graphA = null;
        if (graphProvider != null) {
            graphA = graphProvider.getGraph();
        }

        if (graphA != null && !graphA.isDifferenceGraph()) {
            return (T) new DiffGraphCookie(graphA, graph);
        }
    }

    return super.getCookie(aClass);
}
 
Example 5
Source File: PresentableFileEntry.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Looks for a cookie in the current cookie set matching the requested class.
 *
 * @param type the class to look for
 * @return an instance of that class, or <code>null</code> if this class of cookie
 *    is not supported
 */
@SuppressWarnings("unchecked")
public <T extends Node.Cookie> T getCookie(Class<T> type) {
    CookieSet c = cookieSet;
    if (c != null) {
        T cookie = c.getCookie(type);
        if (cookie != null) {
            return cookie;
        }
    }
    
    if (type.isInstance (this)) {
        return (T) this;
    }
    return null;
}
 
Example 6
Source File: GraphNode.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public <T extends Node.Cookie> T getCookie(Class<T> aClass) {
    if (aClass == DiffGraphCookie.class) {
        InputGraphProvider graphProvider = Utilities.actionsGlobalContext().lookup(InputGraphProvider.class);

        InputGraph graphA = null;
        if (graphProvider != null) {
            graphA = graphProvider.getGraph();
        }

        if (graphA != null && !graphA.isDifferenceGraph()) {
            return (T) new DiffGraphCookie(graphA, graph);
        }
    }

    return super.getCookie(aClass);
}
 
Example 7
Source File: LookupNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** @return empty property sets. *
public PropertySet[] getPropertySets () {
    return NO_PROPERTIES;
}
 */

@Override
public final <T extends Node.Cookie> T getCookie(Class<T> type) {
    if (isUISettingCategoryNode()) return null;
    return super.getCookie (type);
}
 
Example 8
Source File: StrutsConfigDataObject.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Implements <code>CookieSet.Factory</code> interface. */
public Node.Cookie createCookie(Class clazz) {
    if(clazz.isAssignableFrom(StrutsConfigEditorSupport.class))
        return getEditorSupport();
    else
        return null;
}
 
Example 9
Source File: FolderChildrenTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public <T extends Node.Cookie> T getCookie(Class<T> type) {
    if (type == getClass()) {
        return type.cast(this);
    }
    return null;
}
 
Example 10
Source File: DefaultDataObject.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Getter for cookie.
 * @param force if true, there are no checks for content of the file
 */
final <T extends Node.Cookie> T getCookie(Class<T> c, boolean force) {
    if (c == OpenCookie.class) {
        return c.cast(this);
    }

    T cook = super.getCookie (c);
    if (cook != null) {
        return cook;
    }
    fixCookieSet(c, force);
    return getCookieSet ().getCookie(c);
}
 
Example 11
Source File: DefaultDataObject.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
final void checkCookieSet(Class<?> c) {
    if (Node.Cookie.class.isAssignableFrom(c) && !cookieSetFixed) {
        Class<? extends Node.Cookie> cookie = c.asSubclass(Node.Cookie.class);
        fixCookieSet(cookie, false);
    }
}
 
Example 12
Source File: OpenInEditorAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 13
Source File: BytecodeNode.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <T extends Node.Cookie> T getCookie(Class<T> aClass) {
    if (aClass == SelectBytecodesCookie.class && nodes != null) {
        return (T) (new SelectBytecodesCookie(nodes));
    }
    return super.getCookie(aClass);
}
 
Example 14
Source File: BytecodeNode.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public <T extends Node.Cookie> T getCookie(Class<T> aClass) {
    if (aClass == SelectBytecodesCookie.class && nodes != null) {
        return (T) (new SelectBytecodesCookie(nodes));
    }
    return super.getCookie(aClass);
}
 
Example 15
Source File: BytecodeNode.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public <T extends Node.Cookie> T getCookie(Class<T> aClass) {
    if (aClass == SelectBytecodesCookie.class && nodes != null) {
        return (T) (new SelectBytecodesCookie(nodes));
    }
    return super.getCookie(aClass);
}
 
Example 16
Source File: BytecodeNode.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public <T extends Node.Cookie> T getCookie(Class<T> aClass) {
    if (aClass == SelectBytecodesCookie.class && nodes != null) {
        return (T) (new SelectBytecodesCookie(nodes));
    }
    return super.getCookie(aClass);
}
 
Example 17
Source File: DefaultOpenFileImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void openInEDT(FileObject fileObject, DataObject dataObject, int line) {
    Class<? extends Node.Cookie> cookieClass;        
    Node.Cookie cookie;
    
    if ((line != -1)
        && (   ((cookie = dataObject.getCookie(cookieClass = EditorCookie.Observable.class)) != null)
            || ((cookie = dataObject.getCookie(cookieClass = EditorCookie.class)) != null) )) {
        boolean ret = openByCookie(cookie, cookieClass, line);
        if (!ret) {
            showNotPlainFileWarning(fileObject);
        }
        return;
    } 
                        
    /* try to open the object using the default action */
    Node dataNode = dataObject.getNodeDelegate();        
    Action action = dataNode.getPreferredAction();
    if ((action != null)
            && !(action instanceof FileSystemAction)
            && !(action instanceof ToolsAction)) {
        if (log.isLoggable(FINEST)) {
            log.log(FINEST, " - using preferred action "            //NOI18N
                    + "(\"{0}\" - {1}) for opening the file",       //NOI18N
                    new Object[]{action.getValue(Action.NAME),
                        action.getClass().getName()});
        }

        if (action instanceof ContextAwareAction) {
            action = ((ContextAwareAction) action)
              .createContextAwareInstance(dataNode.getLookup());
            if (log.isLoggable(FINEST)) {
                log.finest("    - it is a ContextAwareAction");     //NOI18N
                log.log(FINEST, "    - using a context-aware "      //NOI18N
                        + "instance instead (\"{0}\" - {1})",       //NOI18N
                        new Object[]{action.getValue(Action.NAME),
                            action.getClass().getName()});
            }
        }

        log.finest("   - will call action.actionPerformed(...)");   //NOI18N
        final Action a = action;
        final Node n = dataNode;
        WindowManager.getDefault().invokeWhenUIReady(new Runnable() {

            @Override
            public void run() {
                a.actionPerformed(new ActionEvent(n, 0, ""));
            }
        });
        return;
    }             
    String fileName = fileObject.getNameExt();
    /* Try to grab an editor/open/edit/view cookie and open the object: */
    StatusDisplayer.getDefault().setStatusText(
            NbBundle.getMessage(DefaultOpenFileImpl.class,
                                "MSG_opening",                      //NOI18N
                                fileName));
    boolean success = openDataObjectByCookie(dataObject, line);
    if (success) {
        return;
    }        
    if (fileObject.isFolder() || FileUtil.isArchiveFile(fileObject)) {
        // select it in explorer:
        final Node node = dataObject.getNodeDelegate();
        if (node != null) {
            WindowManager.getDefault().invokeWhenUIReady(new Runnable() {

                @Override
                public void run() {
                    NodeOperation.getDefault().explore(node);
                }
            });
            return;
        }
    }
    showNotPlainFileWarning(fileObject);
}
 
Example 18
Source File: SimpleDESFactoryTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
protected Node.Cookie createEditorCookie(SO so) {
    return (Node.Cookie)DataEditorSupport.create(so, so.getPrimaryEntry(), so.getCSet(), null);
}
 
Example 19
Source File: InstanceDataObjectTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected <T extends Node.Cookie> T getCookie(DataObject obj, Class<T> clazz) {
    return obj.getCookie(clazz);
}
 
Example 20
Source File: SQLDataObject.java    From netbeans with Apache License 2.0 4 votes vote down vote up
void addCookie(Node.Cookie cookie) {
    getCookieSet().add(cookie);
}