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

The following examples show how to use org.openide.nodes.Node#Cookie . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: netbeans   File: JspHyperlinkProvider.java    License: 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 Project: netbeans   File: OpenInEditorAction.java    License: 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
@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 4
Source Project: netbeans   File: PresentableFileEntry.java    License: 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 5
@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 6
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 7
Source Project: netbeans   File: LookupNode.java    License: 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
@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 9
@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 10
@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 11
@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 12
Source Project: netbeans   File: OpenInEditorAction.java    License: 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 Project: netbeans   File: DefaultDataObject.java    License: 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 14
Source Project: netbeans   File: DefaultDataObject.java    License: 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 15
Source Project: netbeans   File: FolderChildrenTest.java    License: 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 16
Source Project: netbeans   File: StrutsConfigDataObject.java    License: 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 17
Source Project: netbeans   File: InstanceDataObjectTest.java    License: 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 18
Source Project: netbeans   File: DefaultOpenFileImpl.java    License: 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 19
Source Project: netbeans   File: SimpleDESFactoryTest.java    License: 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 20
Source Project: netbeans   File: SQLDataObject.java    License: Apache License 2.0 4 votes vote down vote up
void addCookie(Node.Cookie cookie) {
    getCookieSet().add(cookie);
}