Easy Extension of a Node's Functionality in NetBeans IDE 4.1

I've found that it's really easy to extend a node's functionality. Starting with the System Properties sample (which is a module that I created and installed in the IDE's Runtime window as outlined here), it takes three easy steps to add a new menu to the parent node. Let's say, for example, that I want to create a new menu item called "My Own Action", as shown below:

To get the above menu item, I just need to do three things:

  1. Create MyOwnAction.java and subclass CallableSystemAction. Here you see an illustration that includes the new MyOwnAction.java:

  2. In AllPropsNode.java, modify getActions() to add an instance of MyOwnAction.class:

    public SystemAction[] getActions(boolean context) {
      return new SystemAction[] {
          SystemAction.get(MyOwnAction.class),
          null,
          SystemAction.get(RefreshPropsAction.class),
          null,
          SystemAction.get(OpenLocalExplorerAction.class),
          null,
          SystemAction.get(NewAction.class),
          null,
          SystemAction.get(ToolsAction.class),
          SystemAction.get(PropertiesAction.class),
      };
    }

  3. If MyOwnAction.java refers to Bundle.properties, add a localizing tag to Bundle.properties:

    LBL_MyOwnAction=My Own Action

    For example, getName() in MyOwnAction.java is probably as follows:

    public String getName() {
      return NbBundle.getBundle(RefreshPropsAction.class).getString("LBL_MyOwnAction");
    }

That's it. Now you can rebuild and reload the module. You've extended the node's functionality by adding a new menu item. It's a lot less painful than I would have thought.

Comments:

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
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
23
24
25
26
27
28
29
30
   
       
Today