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

The following are Jave code examples for showing how to use Cookie of the org.openide.nodes.Node class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: incubator-netbeans   File: XMLDataObjectTest.java   Source Code and License Vote up 6 votes
private static void checkLookup(DataObject obj, int expected) throws DataObjectNotFoundException {
    Collection<? extends Object> all = obj.getLookup().lookupAll(Object.class);

    int cnt = 0;
    for (Object object : all) {
        assertEquals("Is in lkp", object, obj.getLookup().lookup(object.getClass()));
        Class c = object.getClass();
        if (object instanceof EditorCookie) {
            c = EditorCookie.class;
        }
        if (object instanceof Node.Cookie) {
            assertEquals("Is in cookie: " + c.getSuperclass(), object, obj.getCookie(c));
        }
        cnt++;
    }
    assertEquals("There are some items:\n" + all, expected, cnt);
}
 
Example 2
Project: incubator-netbeans   File: PositionBoundsResolver.java   Source Code and License Vote up 5 votes
private CloneableEditorSupport findCloneableEditorSupport() {
    Node.Cookie obj = dataObject.getCookie(org.openide.cookies.OpenCookie.class);
    if (obj instanceof CloneableEditorSupport) {
        return (CloneableEditorSupport)obj;
    }
    obj = dataObject.getCookie(org.openide.cookies.EditorCookie.class);
    if (obj instanceof CloneableEditorSupport) {
        return (CloneableEditorSupport)obj;
    }
    return null;
}
 
Example 3
Project: incubator-netbeans   File: DatabaseNode.java   Source Code and License Vote up 5 votes
@Override
@SuppressWarnings("unchecked")
public Node.Cookie getCookie(Class cls) {
    if ( cls == Database.class ) {
        return model;
    } else {
        return super.getCookie(cls);
    }
    
}
 
Example 4
Project: incubator-netbeans   File: ServerNode.java   Source Code and License Vote up 5 votes
@Override
@SuppressWarnings("unchecked")
public Node.Cookie getCookie(Class cls) {
    if ( cls == DatabaseServer.class ) {
        return server;
    } else {
        return super.getCookie(cls);
    }
    
}
 
Example 5
Project: incubator-netbeans   File: OpenInEditorAction.java   Source Code and License Vote up 5 votes
private boolean openDataObjectByCookie(DataObject dataObject) {
    Node.Cookie cookie;
    Class cookieClass;
    if ((((     cookie = dataObject.getCookie(cookieClass = EditorCookie.Observable.class)) != null
            || (cookie = dataObject.getCookie(cookieClass = EditorCookie.class)) != null))
            || (cookie = dataObject.getCookie(cookieClass = OpenCookie.class)) != null
            || (cookie = dataObject.getCookie(cookieClass = EditCookie.class)) != null
            || (cookie = dataObject.getCookie(cookieClass = ViewCookie.class)) != null) {
        return openByCookie(cookie, cookieClass);
    }
    return false;
}
 
Example 6
Project: incubator-netbeans   File: LangRenameAction.java   Source Code and License Vote up 5 votes
/** Performs action. Overrides superclass method. */
  protected void performAction (Node[] activatedNodes) {
      Node n = activatedNodes[0]; // we supposed that one node is activated
      Node.Cookie cake = n.getCookie(PropertiesLocaleNode.class);
      PropertiesLocaleNode pln = (PropertiesLocaleNode)cake;

      String lang = Util.getLocaleSuffix(pln.getFileEntry());
      if (lang.length() > 0)
          if (lang.charAt(0) == PropertiesDataLoader.PRB_SEPARATOR_CHAR)
              lang = lang.substring(1);

      NotifyDescriptor.InputLine dlg = new NotifyDescriptor.InputLine(
NbBundle.getMessage(LangRenameAction.class,
		    "LBL_RenameLabel"),			//NOI18N
NbBundle.getMessage(LangRenameAction.class,
		    "LBL_RenameTitle"));		//NOI18N
      
      dlg.setInputText(lang);
      if (NotifyDescriptor.OK_OPTION.equals(DialogDisplayer.getDefault().notify(dlg))) {
          try {
              pln.setName(Util.assembleName (pln.getFileEntry().getDataObject().getPrimaryFile().getName(), dlg.getInputText()));
          }
          catch (IllegalArgumentException e) {
              // catch & report badly formatted names
              NotifyDescriptor.Message msg = new NotifyDescriptor.Message(
                  MessageFormat.format(
                      NbBundle.getBundle("org.openide.actions.Bundle").getString("MSG_BadFormat"),
                      new Object[] {pln.getName()}),
                  NotifyDescriptor.ERROR_MESSAGE);
                      
              DialogDisplayer.getDefault().notify(msg);
          }
      }
  }
 
Example 7
Project: incubator-netbeans   File: PropertiesDataObject.java   Source Code and License Vote up 5 votes
/** Initializes the object. Used by construction and deserialized. */
private void initialize() {
    bundleStructure = null;
    Class<? extends Node.Cookie>[] arr = (Class<Node.Cookie>[]) new Class[2];
    arr[0] = PropertiesOpen.class;
    arr[1] = PropertiesEditorSupport.class;
    getCookieSet().add(arr, this);
    getCookieSet().assign(PropertiesEncoding.class, getEncoding());
}
 
Example 8
Project: incubator-netbeans   File: BiFeatureNode.java   Source Code and License Vote up 5 votes
@Override
public <T extends Node.Cookie> T getCookie(Class<T> type) {
    if ( type == BiFeatureNode.class )
        return type.cast(this);

    return getCookieSet().getCookie( type );
}
 
Example 9
Project: incubator-netbeans   File: DefaultDataObject.java   Source Code and License Vote up 5 votes
@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 10
Project: incubator-netbeans   File: TestNGSuiteHyperlingProvider.java   Source Code and License Vote up 5 votes
private void openInEditor(FileObject fo) {
    DataObject dobj;
    try {
        dobj = DataObject.find(fo);
    } catch (DataObjectNotFoundException e) {
        Exceptions.printStackTrace(e);
        return;
    }
    if (dobj != null) {
        Node.Cookie cookie = dobj.getLookup().lookup(OpenCookie.class);
        if (cookie != null) {
            ((OpenCookie) cookie).open();
        }
    }
}
 
Example 11
Project: incubator-netbeans   File: EvenIfReadonlyItNeedsToThrowExceptionTest.java   Source Code and License Vote up 5 votes
public <T extends Node.Cookie> T createCookie(Class<T> klass) {
    if (klass.isAssignableFrom(DES.class)) {
        return klass.cast(new DES(this, new MyEnv(this)));
    } else {
        return null;
    }
}
 
Example 12
Project: incubator-netbeans   File: AnnotationProviderTest.java   Source Code and License Vote up 5 votes
/** Implements <code>CookieSet.Factory</code> interface. */
public Node.Cookie createCookie(Class clazz) {
    if(clazz.isAssignableFrom(TXTEditorSupport.class))
        return getEditorSupport();
    else
        return null;
}
 
Example 13
Project: incubator-netbeans   File: PropertiesDataObject.java   Source Code and License Vote up 5 votes
/** Implements <code>CookieSet.Factory</code> interface method. */
@SuppressWarnings("unchecked")
public <T extends Node.Cookie> T createCookie(Class<T> clazz) {
    if(clazz.isAssignableFrom(PropertiesOpen.class)) {
        return (T) getOpenSupport();
    } else if(clazz.isAssignableFrom(PropertiesEditorSupport.class)) {
        return (T) ((PropertiesFileEntry)getPrimaryEntry()).getPropertiesEditor();
    } else {
        return null;
    }
}
 
Example 14
Project: incubator-netbeans   File: XMLGenerateSupportFactory.java   Source Code and License Vote up 5 votes
/**
 */
public Node.Cookie createCookie (Class clazz) {
    if ( clazz.isAssignableFrom (GenerateDTDSupport.class) ) {
        return new GenerateDTDSupport (this.dataObject);
    }

    return null;
}
 
Example 15
Project: incubator-netbeans   File: DataNodeTest.java   Source Code and License Vote up 5 votes
@Override
public <T extends Node.Cookie> T getCookie(Class<T> clazz) {
    if (clazz.isAssignableFrom(OpenCookie.class)) {
        return clazz.cast(new OpenCookie () {
            public void open() {
            }
        });
    }
    return super.getCookie(clazz);
}
 
Example 16
Project: incubator-netbeans   File: InstanceDataObjectTest.java   Source Code and License Vote up 4 votes
@Override
protected <T extends Node.Cookie> T getCookie(DataObject obj, Class<T> clazz) {
    return obj.getLookup().lookup(clazz);
}
 
Example 17
Project: incubator-netbeans   File: DefaultDataObject.java   Source Code and License Vote up 4 votes
/** We implement OpenCookie and sometimes we also have cloneable
 * editor cookie */
@Override
public <T extends Node.Cookie> T getCookie(Class<T> c) {
    return getCookie (c, false);
}
 
Example 18
Project: incubator-netbeans   File: OpenActionTest.java   Source Code and License Vote up 4 votes
public Node.Cookie getCookie(Class clazz) { 
    if (clazz == OpenCookie.class) { 
        return this; 
    } 
    return null; 
}
 
Example 19
Project: incubator-netbeans   File: InstanceDataObjectTest.java   Source Code and License Vote up 4 votes
protected <T extends Node.Cookie> T getCookie(DataObject obj, Class<T> clazz) {
    return obj.getCookie(clazz);
}
 
Example 20
Project: incubator-netbeans   File: DefaultOpenFileImpl.java   Source Code and License Vote up 4 votes
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);
}