org.openide.nodes.Node类的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(12.6k)|赞(0)|评价(0)|浏览(131)

本文整理了Java中org.openide.nodes.Node类的一些代码示例,展示了Node类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node类的具体详情如下:
包路径:org.openide.nodes.Node
类名称:Node

Node介绍

[英]A node represents one element in a hierarchy of objects (beans). It provides all methods that are needed for communication between the IDE and the bean.

The node has three purposes:

  1. visually represent the object in the tree hierarchy (i.e. Explorer)
  2. provide sets of properties for that object (i.e. Component Inspector, Property Sheet)
  3. offer actions to perform on itself

Frequently nodes are created to represent DataObjects. But they may also represent anything to be displayed to the user or manipulated programmatically, even if they have no data directly stored behind them; for example, a control panel or debugger breakpoint.

There are two listeners in this class: PropertyChangeListenerand NodeListener (which extends PropertyChangeListener). The first is designed to listen on properties that can be returned from #getPropertySets, the later for listening on changes in the node itself (including the name, children, parent, set of properties, icons, etc.). Be sure to distinguish between these two.

The node is cloneable. When a node is cloned, it is initialized with an empty set of listeners and no parent. The display name and short description are copied to the new node. The set of properties is shared.

Implements org.openide.util.Lookup.Provider since 3.11.
[中]节点表示对象(bean)层次结构中的一个元素。它提供了IDE和bean之间通信所需的所有方法。
该节点有三个用途:
1.直观地表示树层次结构中的对象(即资源管理器)
1.提供该对象的属性集(即组件检查器、属性表)
1.为自己提供行动
通常创建节点是为了表示DataObjects。但它们也可能表示要向用户显示或以编程方式操作的任何内容,即使它们后面没有直接存储的数据;例如,控制面板或调试器断点。
此类中有两个侦听器:PropertyChangeListener和NodeListener(扩展PropertyChangeListener)。第一个用于侦听可从#getPropertySets返回的属性,第二个用于侦听节点本身的更改(包括名称、子级、父级、属性集、图标等)。一定要把这两者区别开来。
该节点是可克隆的。克隆节点时,将使用一组空侦听器初始化该节点,而不使用父节点。显示名称和简短描述将复制到新节点。属性集是“共享的”。
实现组织。openide。util。查找。从3.11开始。

代码示例

代码示例来源:origin: org.netbeans.api/org-openide-nodes

/**
 * 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);
}

代码示例来源:origin: org.netbeans.api/org-openide-nodes

public Node[] callGetNodes(boolean optimalResult) {
  Node[] hold = null;
  if (optimalResult) {
    hold = original.getChildren().getNodes(true);
  }
  hold = Children.this.getNodes();
  return hold;
}

代码示例来源:origin: org.netbeans.api/org-openide-nodes

/** 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;
}

代码示例来源:origin: org.netbeans.api/org-openide-nodes

@Override
public String toString() {
  return super.toString() + "[Name=" + getName() + ", displayName=" + getDisplayName() + "]"; // NOI18N
}

代码示例来源:origin: org.netbeans.api/org-openide-nodes

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();

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-gsf-testrunner-ui

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;
}

代码示例来源:origin: eu.agrosense.client/grid-api

private boolean accept(Node node) {
    return node.getLookup().lookup(FileObject.class) == null 
        || !node.getLookup().lookup(FileObject.class).isFolder();
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-testng-ui

@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;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-web-jsf

@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();
    }
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd

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;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-groovy-grailsproject

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();
}

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-java-project-ui

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;
}

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-j2me-cdc-platform

/**
 * 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);
}

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-vmd-midp

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;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-xml-xam-ui

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];
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-groovy-grailsproject

@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());
  }
}

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-project-libraries-ui

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;
}

代码示例来源:origin: org.codehaus.mevenide/nb-project

@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();
  
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-templates

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;
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-templates

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;
  }
}

相关文章

微信公众号

最新文章

更多