Download NetBeans!

20090404 Saturday April 04, 2009

org.openide.explorer.view.CheckableNode

Those not actually developing on top of the NetBeans Platform themselves will possibly never fully understand this, but time and again NetBeans Platform developers are direct beneficiaries of improvements made to NetBeans IDE. A good example is the brand new org.openide.explorer.view.CheckableNode class, which comes from issue 159546, supporting checkboxes next to nodes, as below in the IDE:

However, since that class is also available as a public class, for certain explorer views, I'm able to create my own nodes with checkboxes:

How to do this yourself? Read the related Javadoc and then pass a CheckableNode into the node Lookup. A simplistic example is below, inside a class that extends ChildFactory:

@Override
protected Node createNodeForKey(String name) {
    Node node = new AbstractNode(Children.create(new CustomerInfoChildFactory(name), true), Lookups.singleton(new CheckableNode() {

        @Override
        public boolean isCheckable() {
            return true;
        }

        @Override
        public boolean isCheckEnabled() {
            return true;
        }

        @Override
        public Boolean isSelected() {
            return true;
        }

        @Override
        public void setSelected(Boolean arg0) {
        }

    }));

    node.setDisplayName(name);
    return node;
}

Strangely, clicking on a checkbox does not check/uncheck it, so maybe I'm doing something wrong. Plus, the CheckableNode is NOT available for ALL explorer views. In the screenshot above, I'm using an OutlineView. But I also tried a BeanTreeView and there this support is not provided.

In other news. I've started adding a new section on Multiview Windows to the File Type Integration Tutorial.

Apr 04 2009, 12:25:56 PM PDT Permalink

Trackback URL: http://blogs.sun.com/geertjan/entry/org_openide_explorer_view_checkablenode
Comments:

I guess it ain't working because your setSelected method does nothing. Try making isSelected/setSelected actually based on a Boolean selected variable and see if it works.

Posted by Michael Nascimento Santos on April 04, 2009 at 03:07 PM PDT #

Did you see this web app: http://www.chartle.net/

Whenever I read Javalobby, I think Java in the browser is dead. This is the only example so far that proves it wrong.

One should write an article on Javalobby introducing all the Java web apps that are really useful. There must be more like http://www.chartle.net/ out there, right?

Posted by Richard on April 04, 2009 at 08:20 PM PDT #

I absolutely love the CheckableNode interface. However, how can I add a listener to be notified when a checkbox is selected/deselected? I need to deselect a parent node if none of its children nodes are selected. Likewise, I need the checkboxes to behave like radio buttons (only allow one of the siblings to be selected at any one time). Help!

Posted by Richard St. John on July 24, 2009 at 11:20 AM PDT #

Post a Comment:

Name:
E-Mail:
URL:

Your Comment:

HTML Syntax: NOT allowed