@ServicesTabNodeRegistration

I tried the new org.netbeans.api.core.ide.ServicesTabNodeRegistration today. It worked for me, the code below creates a Root node in the Services window (#DISPLAYNAME points to a key in the Bundle), with the children being the three names defined in the ChildFactory:
@ServicesTabNodeRegistration(displayName = "#DISPLAYNAME",
iconResource = "/org/demo/country/node/icon.png", name = "")
public class RootNode extends AbstractNode {

    public RootNode() {
        super(Children.create(new DemoNodeFactory(), true));
    }

    static class DemoNodeFactory extends ChildFactory {

        @Override
        protected boolean createKeys(List list) {
            String[] names = {"Tom", "Dick", "Harry"};
            for (String name : names) {
                list.add(name);
            }
            return true;
        }

        @Override
        protected Node createNodeForKey(String name) {
            Node node = new AbstractNode(Children.LEAF);
            node.setDisplayName(name);
            return node;
        }
    }

}

Compare that to the code here and the only difference is that I now don't need to do anything at all in the layer.xml.

I'm surprised, though, that (1) the attributes 'displayName', 'iconResource', and 'name' all appear to be mandatory and that (2) the annotation is set on a Node, instead of on a Children object. Probably I don't understand it completely yet.

Comments:

The annotation is on a Node, not a Children, because the moment the user expands the node or gets its context menu, the real Node is swapped into the tab in place of the dummy node. The real node could have a rich context menu, drag-n-drop behavior, whatever; whereas the dummy node is quick to load (no class loading from your module is required).

The label and icon are mandatory because it would look very bad for a node to be missing either.

The (code) 'name' attr could probably be made optional, defaulted say to the class(+method) name. File an RFE if you like.

Posted by Jesse Glick on April 03, 2009 at 05:12 AM PDT #

Thanks, now it makes sense -- the annotation provides a dummy node. So, the icon and display name of the dummy node should be the same as the real node, right? (In which case, why can't the annotation get that information from the real node?)

And, whether the 'name' attribute is mandatory or not, what's its purpose?

Posted by Geertjan Wielenga on April 03, 2009 at 09:52 PM PDT #

Yes, the annotation fields should match those of the real node. They cannot be inferred from the real node because the annotation can use only compile-time constants, whereas the real node could be running arbitrary computations:

@ServicesTabNodeRegistration(..., displayName="???")
public class MyNode extends AbstractNode {
public MyNode() {super(Children.LEAF};}
public @Override String getDisplayName() {
if (isPrime(436798769715643961587888934267)) {
return "Yes it is prime";
} else {
return "Nope, composite";
}
}
}

Node.name serves two functions: (1) it is what is changed when you rename a node in place using F2, if supported; (2) it is used when creating paths, e.g. to persist expansion state of a tree (see NodeOp), in which case it should be unique among siblings.

Posted by Jesse Glick on April 04, 2009 at 12:08 AM PDT #

Thanks. Makes perfect sense.

Posted by Geertjan Wielenga on April 04, 2009 at 05:29 AM PDT #

I recently came across your blog and have been reading along. I thought I would leave my first comment. I don't know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.

Sarah

http://adoptpet.info

Posted by Sarah on April 05, 2009 at 02:40 PM PDT #

Have you tryed it with a Maven project, instead of an Ant one? For some dumb reason, it does not recognize the package (even after adding org-openide-code-ide)...

Posted by Eduardo Costa on December 18, 2009 at 05:52 AM PST #

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
« May 2015
SunMonTueWedThuFriSat
     
2
3
8
9
10
19
26
27
28
29
30
31
      
Today