Java Code Examples for org.openide.nodes.Node#getCookie()
The following examples show how to use
org.openide.nodes.Node#getCookie() .
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: DiffAction.java From netbeans with Apache License 2.0 | 6 votes |
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 2
Source File: JaxWsExplorerPanel.java From netbeans with Apache License 2.0 | 6 votes |
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 3
Source File: UnregisterResourceAction.java From netbeans with Apache License 2.0 | 5 votes |
@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 4
Source File: FolderComparator.java From netbeans with Apache License 2.0 | 5 votes |
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 5
Source File: Util.java From netbeans with Apache License 2.0 | 5 votes |
/** * 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 6
Source File: I18nAction.java From netbeans with Apache License 2.0 | 5 votes |
/** 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 7
Source File: PrintAction.java From netbeans with Apache License 2.0 | 5 votes |
private PrintCookie getPrintCookie() { Node node = getSelectedNode(); if (node == null) { return null; } return (PrintCookie) node.getCookie(PrintCookie.class); }
Example 8
Source File: OpenTestURLAction.java From netbeans with Apache License 2.0 | 5 votes |
@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 9
Source File: OptionsAction.java From netbeans with Apache License 2.0 | 5 votes |
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 10
Source File: AnnotateAction.java From netbeans with Apache License 2.0 | 5 votes |
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 11
Source File: RefactoringActionsProvider.java From netbeans with Apache License 2.0 | 5 votes |
/** * 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 12
Source File: DeployDirectoryAction.java From netbeans with Apache License 2.0 | 5 votes |
protected boolean enable(Node[] nodes) { for(Node node: nodes) { DeployDirectoryCookie cookie = node.getCookie(DeployDirectoryCookie.class); if (cookie == null) { return false; } } return true; }
Example 13
Source File: RemoveAction.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
protected void performAction(Node[] activatedNodes) { for (Node n : activatedNodes) { RemoveCookie removeCookie = n.getCookie(RemoveCookie.class); if (removeCookie != null) { removeCookie.remove(); } } }
Example 14
Source File: EditDetailsAction.java From netbeans with Apache License 2.0 | 5 votes |
@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 15
Source File: RemoveAction.java From hottub with GNU General Public License v2.0 | 5 votes |
protected void performAction(Node[] activatedNodes) { for (Node n : activatedNodes) { RemoveCookie removeCookie = n.getCookie(RemoveCookie.class); if (removeCookie != null) { removeCookie.remove(); } } }
Example 16
Source File: AnnotateAction.java From netbeans with Apache License 2.0 | 5 votes |
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 17
Source File: ConnectionPoolAdvancedAttributesAction.java From netbeans with Apache License 2.0 | 5 votes |
@Override protected boolean enable(Node[] nodes) { for(Node node : nodes) { ConnectionPoolAdvancedAttributesCookie cookie = node.getCookie(ConnectionPoolAdvancedAttributesCookie.class); if(cookie == null) { return false; } } return true; }
Example 18
Source File: TemplateWizard1.java From netbeans with Apache License 2.0 | 4 votes |
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 19
Source File: TreeViewDropSupport.java From netbeans with Apache License 2.0 | 4 votes |
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 20
Source File: LookupNode.java From netbeans with Apache License 2.0 | 4 votes |
/** 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 }; }