Java Code Examples for org.openide.nodes.Node#getCookie()

The following examples show how to use org.openide.nodes.Node#getCookie() . 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: JaxWsExplorerPanel.java    License: Apache License 2.0 6 votes vote down vote up
public void propertyChange(PropertyChangeEvent evt) {
    if(evt.getSource() == manager) {
        if(ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) {
            Node nodes[] = manager.getSelectedNodes();
            if(nodes != null && nodes.length > 0 ) {
                Node node = nodes[0];
                if(node.getCookie(WsWsdlCookie.class)!=null) {
                    // This is a service node.
                    selectedServiceNode = node;
                    descriptor.setValid(true);
                } else {
                    // This is not a service node.
                    selectedServiceNode = null;
                    descriptor.setValid(false);
                }
            }
        }
    }
}
 
Example 2
Source Project: netbeans   File: DiffAction.java    License: Apache License 2.0 6 votes vote down vote up
static FileObject getFileFromNode(Node node) {
    FileObject fo = (FileObject) node.getLookup().lookup(FileObject.class);
    if (fo == null) {
        Project p = (Project) node.getLookup().lookup(Project.class);
        if (p != null) return p.getProjectDirectory();

        DataObject dobj = (DataObject) node.getCookie(DataObject.class);
        if (dobj instanceof DataShadow) {
            dobj = ((DataShadow) dobj).getOriginal();
        }
        if (dobj != null) {
            fo = dobj.getPrimaryFile();
        }
    }
    return fo;
}
 
Example 3
@Override
protected boolean enable(Node[] nodes) {
    for(Node node : nodes) {
        ConnectionPoolAdvancedAttributesCookie cookie = node.getCookie(ConnectionPoolAdvancedAttributesCookie.class);
        if(cookie == null) {
            return false;
        }
    }

    return true;
}
 
Example 4
@Override
protected boolean enable(Node[] nodes) {
    for(Node node : nodes) {
        UnregisterResourceCookie cookie = node.getCookie(UnregisterResourceCookie.class);
        if(cookie == null || cookie.isRunning()) {
            return false;
        }
    }

    return true;
}
 
Example 5
Source Project: netbeans   File: AnnotateAction.java    License: Apache License 2.0 5 votes vote down vote up
private File activatedFile(Node[] nodes) {
    if (nodes.length == 1) {
        Node node = nodes[0];
        DataObject dobj = (DataObject) node.getCookie(DataObject.class);
        if (dobj != null) {
            FileObject fo = dobj.getPrimaryFile();
            return FileUtil.toFile(fo);
        }
    }
    return null;
}
 
Example 6
protected void performAction(Node[] activatedNodes) {
    for (Node n : activatedNodes) {
        RemoveCookie removeCookie = n.getCookie(RemoveCookie.class);
        if (removeCookie != null) {
            removeCookie.remove();
        }
    }
}
 
Example 7
Source Project: netbeans   File: EditDetailsAction.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected boolean enable(Node[] nodes) {
    for(Node node : nodes) {
        EditDetailsCookie cookie = node.getCookie(EditDetailsCookie.class);
        if(cookie == null) { // || cookie.isRunning()) {
            return false;
        }
    }

    return true;
}
 
Example 8
protected void performAction(Node[] activatedNodes) {
    for (Node n : activatedNodes) {
        RemoveCookie removeCookie = n.getCookie(RemoveCookie.class);
        if (removeCookie != null) {
            removeCookie.remove();
        }
    }
}
 
Example 9
Source Project: netbeans   File: DeployDirectoryAction.java    License: Apache License 2.0 5 votes vote down vote up
protected boolean enable(Node[] nodes) {
    for(Node node: nodes) {
        DeployDirectoryCookie cookie = node.getCookie(DeployDirectoryCookie.class);
        if (cookie == null) {
            return false;
        }
    }        
    return true;
}
 
Example 10
/**
 * Returns true if all selected file are refactorable java files
 **/

@Override
public boolean canDelete(Lookup lookup) {
    if (SourceUtils.isScanInProgress()) {
        return false;
    }
    Collection<? extends Node> nodes = new HashSet<Node>(lookup.lookupAll(Node.class));
    //We live with a 2 pass validation of the selected nodes for now since
    //the code will become unreadable if we attempt to implement all checks
    //in one pass.
    if (isSelectionHeterogeneous(nodes)) {
        return false;
    }
    for (Node n:nodes) {
        TreePathHandle tph = n.getLookup().lookup(TreePathHandle.class);
        if (tph != null) {
            return JavaRefactoringUtils.isRefactorable(tph.getFileObject());
        }
        DataObject dataObject = n.getCookie(DataObject.class);
        if (dataObject == null){
            return false;
        }
        FileObject fileObject = dataObject.getPrimaryFile();
        if (isRefactorableFolder(dataObject)){
            return true;
        }
        if (!JavaRefactoringUtils.isRefactorable(fileObject)) {
            return false;
        }
    }
    return !nodes.isEmpty();
}
 
Example 11
Source Project: netbeans   File: AnnotateAction.java    License: Apache License 2.0 5 votes vote down vote up
private File activatedFile (Node[] nodes) {
    if (nodes.length == 1) {
        Node node = nodes[0];
        DataObject dobj = (DataObject) node.getCookie(DataObject.class);
        if (dobj != null) {
            FileObject fo = dobj.getPrimaryFile();
            return FileUtil.toFile(fo);
        }
    }
    return null;
}
 
Example 12
Source Project: netbeans   File: OptionsAction.java    License: Apache License 2.0 5 votes vote down vote up
private HelpCtx getHelpId (Node node) {
    // it's template, return specific help id
    DataObject dataObj = (DataObject)node.getCookie (DataObject.class);
    if (dataObj != null) {
        Object o = dataObj.getPrimaryFile ().getAttribute ("helpID"); // NOI18N
        if (o != null) {
            return new HelpCtx (o.toString ());
        }
    }
    return null;
}
 
Example 13
Source Project: netbeans   File: OpenTestURLAction.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected boolean enable(Node[] nodes) {
    for(Node node : nodes) {
        OpenURLActionCookie oCookie = node.getCookie(OpenURLActionCookie.class);

        if(oCookie != null && oCookie.getWebURL() != null) {
            return true;
        }
    }

    return false;
}
 
Example 14
Source Project: netbeans   File: PrintAction.java    License: Apache License 2.0 5 votes vote down vote up
private PrintCookie getPrintCookie() {
    Node node = getSelectedNode();

    if (node == null) {
        return null;
    }
    return (PrintCookie) node.getCookie(PrintCookie.class);
}
 
Example 15
Source Project: netbeans   File: I18nAction.java    License: Apache License 2.0 5 votes vote down vote up
/** Overrides superclass method. Adds additional test if i18n module has registered factory
    * for this data object to be able to perform i18n action. */
   protected boolean enable(Node[] activatedNodes) {    
       if (activatedNodes.length != 1) {
           return false;
       }

       final Node node = activatedNodes[0];
       DataObject dataObject = node.getCookie(DataObject.class);
       if ((dataObject == null) || (dataObject.getPrimaryFile() == null)) {
           return false;
       }

       EditorCookie editorCookie = node.getCookie(EditorCookie.class);
       if (editorCookie == null) {
           editorCookie = dataObject.getCookie(EditorCookie.class);
           if (editorCookie == null) {
               return false;
           }
       }

       if (!FactoryRegistry.hasFactory(dataObject.getClass())) {
           return false;
       }

// check that the node has project
       Future<Project[]> openProjects = OpenProjects.getDefault().openProjects();
       if(!openProjects.isDone()) {
           return true;
       }
if (FileOwnerQuery.getOwner(dataObject.getPrimaryFile()) == null) {
           return false;
       }

return true;
   }
 
Example 16
Source Project: netbeans   File: Util.java    License: Apache License 2.0 5 votes vote down vote up
/** 
 * Create settings based on selected nodes. Finds all accepted data objects. 
 * Used by actions to populate wizard.
 * @param activatedNodes selected nodes 
 * @return map with accepted data objects as keys or empty map if no such
 * data object were found.
 */
public static Map<DataObject,SourceData> createWizardSourceMap(Node[] activatedNodes) {
    Map<DataObject,SourceData> sourceMap = createWizardSourceMap();
    
    if (activatedNodes != null && activatedNodes.length > 0) {
        final VisibilityQuery visQuery = VisibilityQuery.getDefault();
        for (Node node : activatedNodes) {
            DataObject dobj = node.getCookie(DataObject.class);
            if (dobj != null && !visQuery.isVisible(dobj.getPrimaryFile())) {
                continue;
            }

            DataObject.Container container = node.getCookie(DataObject.Container.class);
            if (container != null) {
                for (DataObject dataObj : I18nUtil.getAcceptedDataObjects(container)) {
                    addSource(sourceMap, dataObj);
                }
            }

            if (dobj == null) {
                continue;
            }

            if (FactoryRegistry.hasFactory(dobj.getClass())) {
                addSource(sourceMap, dobj);
            }
        }
    }
    
    return sourceMap;
}
 
Example 17
Source Project: netbeans   File: FolderComparator.java    License: Apache License 2.0 5 votes vote down vote up
private static DataObject findDataObject(Object o) {
    if (o instanceof DataObject) {
        return (DataObject) o;
    }
    if (o instanceof FileObject) {
        try {
            return DataObject.find((FileObject) o);
        } catch (DataObjectNotFoundException ex) {
            return null;
        }
    }
    Node n = (Node) o;
    DataObject obj = n.getCookie(DataObject.class);
    return obj;
}
 
Example 18
Source Project: netbeans   File: TreeViewDropSupport.java    License: Apache License 2.0 4 votes vote down vote up
private void performReorder(final Node folder, Node[] dragNodes, int lNode, int uNode) {
    try {
        Index indexCookie = folder.getCookie(Index.class);

        if (indexCookie != null) {
            int[] perm = new int[indexCookie.getNodesCount()];
            int[] indexes = new int[dragNodes.length];
            int indexesLength = 0;

            for (int i = 0; i < dragNodes.length; i++) {
                int idx = indexCookie.indexOf(dragNodes[i]);

                if ((idx >= 0) && (idx < perm.length)) {
                    indexes[indexesLength++] = idx;
                }
            }

            // XXX: normally indexes of dragged nodes should be in ascending order, but
            // it seems that Tree.getSelectionPaths doesn't keep this order
            Arrays.sort(indexes);

            if ((lNode < 0) || (uNode >= perm.length) || (indexesLength == 0)) {
                return;
            }

            int k = 0;

            for (int i = 0; i < perm.length; i++) {
                if (i <= uNode) {
                    if (!containsNumber(indexes, indexesLength, i)) {
                        perm[i] = k++;
                    }

                    if (i == uNode) {
                        for (int j = 0; j < indexesLength; j++) {
                            if (indexes[j] <= uNode) {
                                perm[indexes[j]] = k++;
                            }
                        }
                    }
                } else {
                    if (i == lNode) {
                        for (int j = 0; j < indexesLength; j++) {
                            if (indexes[j] >= lNode) {
                                perm[indexes[j]] = k++;
                            }
                        }
                    }

                    if (!containsNumber(indexes, indexesLength, i)) {
                        perm[i] = k++;
                    }
                }
            }

            // check for identity permutation
            for (int i = 0; i < perm.length; i++) {
                if (perm[i] != i) {
                    indexCookie.reorder(perm);

                    break;
                }
            }
        }
    } catch (Exception e) {
        // Pending: add annotation or remove try/catch block
        Logger.getLogger(TreeViewDropSupport.class.getName()).log(Level.WARNING, null, e);
    }
}
 
Example 19
Source Project: netbeans   File: TemplateWizard1.java    License: Apache License 2.0 4 votes vote down vote up
public int getChildCount (Object o) {
    Node n = Visualizer.findNode(o);
    DataObject obj = n.getCookie(DataObject.class);

    return obj == null || obj.isTemplate () ? 0 : super.getChildCount (o);
}
 
Example 20
Source Project: netbeans   File: LookupNode.java    License: Apache License 2.0 4 votes vote down vote up
/** Overridden, returns LookupNode filters of original nodes.
*
* @param node node to create copy of
* @return LookupNode filter of the original node
*/
@Override
protected Node[] createNodes(Node node) {
    DataObject obj = (DataObject)node.getCookie(DataObject.class);
    //System.err.println("obj="+obj+" node="+node+" hidden="+(obj==null?null:obj.getPrimaryFile ().getAttribute (EA_HIDDEN)));
    
    if (
        obj != null && Boolean.TRUE.equals (obj.getPrimaryFile ().getAttribute (EA_HIDDEN))
    ) {
        return new Node[0];
    }
    
    LookupNode parent = (LookupNode)getNode ();
    
    if (obj != null) {
        if (obj instanceof DataFolder && node.equals (obj.getNodeDelegate ())) {
            node = parent.createChild ((DataFolder)obj);
            return new Node[] { node };
        } else if (obj instanceof DataShadow) {
            DataObject orig = ((DataShadow) obj).getOriginal();
            FileObject fo = orig.getPrimaryFile();
            
            // if folder referenced by shadow is empty do not show it
            if (fo.isFolder() && !fo.getChildren(false).hasMoreElements()) return null;
            
            if (orig instanceof DataFolder) {
                return new Node[] { 
                    parent.createChild ((DataFolder) orig)
                };
            } else {
                obj = orig;
                node = orig.getNodeDelegate();
            }
        }
        node = new Leaf(node, obj, parent);
    }
    
    node = parent.createChild (node);

    return new Node[] { node };
}