Monday May 30, 2005
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:
- Create MyOwnAction.java and subclass CallableSystemAction. Here you see an illustration that includes the new MyOwnAction.java:
- 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), }; } - 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.
May 30 2005, 05:00:16 AM PDT Permalink


