/** * Computes a common popup menu for the specified nodes. * Provides only those actions supplied by all nodes in the list. * <p>Component action maps are not taken into consideration. * {@link Utilities#actionsToPopup(Action[], Component)} is a better choice * if you want to use actions such as "Paste" which look at action maps. * @param nodes the nodes * @return the menu for all nodes */ public static JPopupMenu findContextMenu(Node[] nodes) { Action[] arr = findActions(nodes); // prepare lookup representing all the selected nodes List<Lookup> allLookups = new ArrayList<Lookup>(); for (Node n : nodes) { allLookups.add(n.getLookup()); } Lookup lookup = new ProxyLookup(allLookups.toArray(new Lookup[allLookups.size()])); return Utilities.actionsToPopup(arr, lookup); }
public Node[] callGetNodes(boolean optimalResult) { Node[] hold = null; if (optimalResult) { hold = original.getChildren().getNodes(true); } hold = Children.this.getNodes(); return hold; }
/** Find a path (by name) from one node to the root or a parent. * @param node the node to start in * @param parent parent node to stop in (can be <code>null</code> for the root) * @return list of child names--i.e. a path from the parent to the child node * @exception IllegalArgumentException if <code>node</code>'s getName() * method returns <code>null</code> */ public static String[] createPath(Node node, Node parent) { LinkedList<String> ar = new LinkedList<String>(); while ((node != null) && (node != parent)) { if (node.getName() == null) { boolean isFilter = false; if (node instanceof FilterNode) { isFilter = true; } throw new IllegalArgumentException( "Node:" + node.getClass() // NOI18N +"[" + node.getDisplayName() + "]" // NOI18N +(isFilter ? (" of original:" + ((FilterNode) node).getOriginal().getClass()) : "") // NOI18N +" gets null name!" ); // NOI18N } ar.addFirst(node.getName()); node = node.getParentNode(); } String[] res = new String[ar.size()]; ar.toArray(res); return res; }
@Override public String toString() { return super.toString() + "[Name=" + getName() + ", displayName=" + getDisplayName() + "]"; // NOI18N }
Children.PR.enterReadAccess(); String childPath = node.getName(); Node parentNode = node.getParentNode(); Node foundChild = parentNode.getChildren().findChild(childPath); if (foundChild != node) { Logger.getLogger(DefaultHandle.class.getName()).log(Level.WARNING, Node.Handle parentHandle = parentNode.getHandle();
public static FileObject getFileObjectFromNode(Node node) { FileObject fo = node.getLookup().lookup(FileObject.class); if(fo == null) { Children children = node.getChildren(); for(Node child : children.getNodes()) { fo = child.getLookup().lookup(FileObject.class); if(fo != null) { return child.getDisplayName().equals("<default package>") ? fo : fo.getParent(); } } } return fo; }
@Override protected boolean enable(Node[] activatedNodes) { if (activatedNodes.length != 1) { return false; } Lookup l = activatedNodes[0].getLookup(); FileObject fo = l.lookup(FileObject.class); if (fo != null) { Project p = FileOwnerQuery.getOwner(fo); return TestNGSupport.isActionSupported(Action.DEBUG_TEST, p); } return false; }
@Override public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); if (COMMAND_SELECT.equals(command)) { Node[] selection = browsePanel.getExplorerManager().getSelectedNodes(); if (selection != null && selection.length > 0) { DataObject dobj = (DataObject) selection[0].getLookup().lookup(DataObject.class); result = dobj.getPrimaryFile(); } } }
protected static Project getProject(Node node) { DataObject dataObject = node.getLookup().lookup(DataObject.class); if (dataObject != null) { FileObject fileObject = dataObject.getPrimaryFile(); if (fileObject != null) { return FileOwnerQuery.getOwner(fileObject); } } return null; }
protected void performAction(Node[] activatedNodes) { final GrailsPlatform runtime = GrailsPlatform.getDefault(); if (!runtime.isConfigured()) { ConfigurationSupport.showConfigurationWarning(runtime); return; } DataObject dataObject = activatedNodes[0].getLookup().lookup(DataObject.class); GrailsProject prj = (GrailsProject) FileOwnerQuery.getOwner(dataObject.getFolder().getPrimaryFile()); FileObject domainDir = prj.getProjectDirectory().getFileObject(DOMAIN_DIR); if (domainDir == null) { return; } String relativePath = FileUtil.getRelativePath(domainDir, dataObject.getPrimaryFile()); if (relativePath == null) { return; } // replace slashes and cut off the extension StringBuilder builder = new StringBuilder(relativePath.replace('/', '.')); // NOI18N builder.setLength(builder.length() - dataObject.getPrimaryFile().getNameExt().length()); builder.append(dataObject.getPrimaryFile().getName()); ProjectInformation inf = prj.getLookup().lookup(ProjectInformation.class); String displayName = inf.getDisplayName() + " (" + command + ")"; // NOI18N Callable<Process> callable = ExecutionSupport.getInstance().createSimpleCommand( command, GrailsProjectConfig.forProject(prj), builder.toString()); // NOI18N ExecutionDescriptor descriptor = prj.getCommandSupport().getDescriptor(command); ExecutionService service = ExecutionService.newService(callable, descriptor, displayName); service.run(); }
private Node findPathPlain(FileObject fo, FileObject groupRoot, Node rootNode) { FileObject folder = fo.isFolder() ? fo : fo.getParent(); String relPath = FileUtil.getRelativePath(groupRoot, folder); List<String> path = new ArrayList<String>(); StringTokenizer strtok = new StringTokenizer(relPath, "/"); // NOI18N while (strtok.hasMoreTokens()) { String token = strtok.nextToken(); path.add(token); } try { Node folderNode = folder.equals(groupRoot) ? rootNode : NodeOp.findPath(rootNode, Collections.enumeration(path)); if (fo.isFolder()) { return folderNode; } else { Node[] childs = folderNode.getChildren().getNodes(true); for (int i = 0; i < childs.length; i++) { DataObject dobj = childs[i].getLookup().lookup(DataObject.class); if (dobj != null && dobj.getPrimaryFile().getNameExt().equals(fo.getNameExt())) { return childs[i]; } } } } catch (NodeNotFoundException e) { e.printStackTrace(); } return null; }
/** * This finally produces the java platform's XML that represents the basic * platform's properties. The XML is returned in the resulting Set. * @return singleton Set with java platform's instance DO inside. */ public java.util.Set instantiate() throws IOException { //Workaround #44444 this.detectPanel.storeSettings (this.wizard); CDCPlatform newPlatform = getPlatform(); final String systemName = platform.getAntName(); FileObject platformsFolder = FileUtil.getConfigFile( "Services/Platforms/org-netbeans-api-java-Platform"); //NOI18N if (platformsFolder.getFileObject(systemName,"xml")!=null) { //NOI18N String msg = NbBundle.getMessage(CDCWizardIterator.class,"ERROR_InvalidName"); throw (IllegalStateException)ErrorManager.getDefault().annotate( new IllegalStateException(msg), ErrorManager.USER, null, msg,null, null); } DataObject dobj = PlatformConvertor.create(newPlatform, DataFolder.findFolder(platformsFolder),systemName); JavaPlatform platform = (JavaPlatform) dobj.getNodeDelegate().getLookup().lookup(JavaPlatform.class); return Collections.singleton(platform); }
protected FileObject getNodeFileObject(Transferable transferable) { Node node = NodeTransfer.node(transferable, NodeTransfer.DND_COPY_OR_MOVE); if (node == null) return null; DataObject dataObject = (DataObject) node.getLookup().lookup(DataObject.class); if (dataObject == null) return null; FileObject file = dataObject.getPrimaryFile(); return file; }
protected Node[] createNodes(Node n) { DataObject dobj = (DataObject) n.getLookup().lookup(DataObject.class); if (dobj != null) { FileObject fobj = dobj.getPrimaryFile(); if (fobj.isFolder() && fobj.getNameExt().equals("nbproject") && fobj.getFileObject("project.xml") != null) { // It is the NetBeans project folder, ignore it. return new Node[0]; } ModelCookie cookie = (ModelCookie) dobj.getCookie(ModelCookie.class); String fname = fobj.getNameExt(); String ext = decorator.getDocumentType().toString(); if (fobj.isFolder() || cookie != null && fname.endsWith(ext)) { return super.createNodes(n); } } return new Node[0]; }
@Override protected boolean enable(Node[] activatedNodes) { if (activatedNodes.length == 0) { return false; } DataObject dataObject = activatedNodes[0].getLookup().lookup(DataObject.class); if (dataObject == null || dataObject.getFolder() == null) { return false; } Project prj = FileOwnerQuery.getOwner(dataObject.getFolder().getPrimaryFile()); if (prj == null) { return false; } FileObject domainDir = prj.getProjectDirectory().getFileObject(DOMAIN_DIR); if (domainDir == null) { return false; } return FileUtil.isParentOf(domainDir, dataObject.getPrimaryFile()); } }
public Set<Library> getSelectedLibraries() { Set<Library> s = new HashSet<Library>(); for (Node n : explorer.getSelectedNodes()) { Library l = n.getLookup().lookup(Library.class); if (l != null) { s.add(l); } else { return Collections.emptySet(); } } return s; }
@Override public String getDisplayName() { if (isTopLevelNode) { String s = NbBundle.getMessage(SiteDocsNode.class, "LBL_Site_Pages"); DataObject dob = getOriginal().getLookup().lookup(DataObject.class); FileObject file = dob.getPrimaryFile(); try { s = file.getFileSystem().getStatus().annotateName(s, Collections.singleton(file)); } catch (FileStateInvalidException e) { ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); } return s; } return getOriginal().getDisplayName(); }
private static boolean isDuplicateEnabled(Node[] nodes) { // It has not much sense to duplicate non-editable templates. // Thus using the same condition: if (nodes != null && nodes.length == 1 && nodes [0].isLeaf ()) { Node n = nodes[0]; DataObject dobj = n.getLookup().lookup(DataObject.class); assert dobj != null : "DataObject for node " + n; FileObject fo = dobj.getPrimaryFile (); return fo.canRevert() || fo.getSize () > 0; } else { return false; } }
private static Node getTemplateNode(String path) { FileObject rootFO = getTemplateRootNode().getLookup().lookup(FileObject.class); FileObject fo = rootFO.getFileObject(path); if (fo != null) { return getTemplateNode(fo, rootFO); } else { return null; } }