X

Geertjan's Blog

  • October 20, 2009

org.openide.nodes.FilterNode (Part 1)

Geertjan Wielenga
Product Manager
No references to FilterNode in this blog, so let's change that. Here's a great reference by Tom Wheeler:

http://wiki.netbeans.org/DevFaqNodesDecorating

In my example, we'll filter the children of the root node, using the code referenced above. If a node display name is set to "Tom" it will not be displayed:

import java.util.ArrayList;
import java.util.List;
import org.openide.nodes.FilterNode;
import org.openide.nodes.Node;
public class ProxyChildren extends FilterNode.Children {
public ProxyChildren(Node owner) {
super(owner);
}
@Override
protected Node[] createNodes(Node object) {
List<Node> result = new ArrayList<Node>();
for (Node node : super.createNodes(object)) {
if (accept(node)) {
result.add(node);
}
}
return result.toArray(new Node[0]);
}
private boolean accept(Node node) {
if (node.getDisplayName().equals("Tom")){
return false;
} else {
return true;
}
}
}

And here's the TopComponent constructor that constructs the filtered children above:

public DemoTopComponent() {
...
...
...
Node filterNode = new FilterNode(new RootNode(), new ProxyChildren(new RootNode()));
em.setRootContext(filterNode);
}
public class RootNode extends AbstractNode {
public RootNode() {
super(Children.create(new DemoChildFactory(), true));
setDisplayName("Root");
}
}

More about this can be found here:

http://bits.netbeans.org/dev/javadoc/org-openide-nodes/org/openide/nodes/FilterNode.html

Join the discussion

Comments ( 4 )
  • hantsy Tuesday, October 20, 2009

    Nodes API is too old, at least it need to update to Java 5.


  • Geertjan Wednesday, October 21, 2009

    So... you're saying that the Nodes API should let you use generics? It does. So, what are you trying to say?


  • hantsy Wednesday, October 21, 2009

    Ok, Thanks.

    I mistakes Nodes API.

    I am working on the Click Plugin for NetBeans( http://hantsy.cublog.cn ), and copied a FolderBrowser panel from the Struts module. It produces some warning about the Node APIs. May be the struts module used the old api.


  • hantsy Thursday, October 22, 2009

    The click plugin v1.0 is available now, http://hantsy.blogspot.com


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha
Oracle

Integrated Cloud Applications & Platform Services