Tuesday October 20, 2009
org.openide.nodes.FilterNode
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
Oct 20 2009, 04:10:33 PM PDT Permalink
Nodes API is too old, at least it need to update to Java 5.
So... you're saying that the Nodes API should let you use generics? It does. So, what are you trying to say?
Posted by Geertjan on October 21, 2009 at 02:49 AM PDT #
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.
The click plugin v1.0 is available now, http://hantsy.blogspot.com


