org.openide.nodes.FilterNode (Part 1)

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

Comments:

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

Posted by hantsy on October 20, 2009 at 10:49 AM PDT #

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 20, 2009 at 07:49 PM 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.

Posted by hantsy on October 20, 2009 at 10:22 PM PDT #

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

Posted by hantsy on October 22, 2009 at 01:42 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« September 2015
SunMonTueWedThuFriSat
  
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today