Geertjan's Blog

  • October 13, 2008

How Users Can Let Children Move Up & Move Down (Part 1)

Geertjan Wielenga
Product Manager
"Move up" and "Move down" support for nodes is provided by the NetBeans Platform, as described in this "NetBeans Definitive Guide" page on-line. I tried to get it to work for some of my child nodes today and managed to get it working, with Jarda's help. The menu items are enabled, if I select one child node at a time, and they work as one would expect them to:

Let's say I define my children like this:

public class PropChildren extends Index.ArrayChildren {
protected java.util.List initCollection() {
ArrayList childrenNodes = new ArrayList();
Properties p = System.getProperties();
Enumeration e = p.keys();
while (e.hasMoreElements()) {
childrenNodes.add(new PropNode(e.nextElement().toString()));
return childrenNodes;
public class PropNode extends AbstractNode {
public PropNode(String key) {
super(Children.LEAF, Lookups.fixed());
}//You need to add the 'MoveUpAction' and 'MoveDownAction',
//which are part of the Actions API:

public Action[] getActions(boolean popup) {
return new Action[]{

For the above, you need the following in the TopComponent's constructor (of course, the TopComponent implements ExplorerManager.Provider and has an explorer view added to it):

//Create an instance of the children class:
PropChildren prop = new PropChildren();
//Add the map of actions to the TopComponent's Lookup:
associateLookup(ExplorerUtils.createLookup(explorerManager, getActionMap()));
//Create the children and
//include an implementation of the Index class in the Lookup of the root node.
//Since our children class above is such an implementation, we'll include that:

explorerManager.setRootContext(new AbstractNode(prop, Lookups.singleton(prop)));
//Set the display name of the root node:

The key to the above is that I have extended Index.ArrayChildren, which provides me with reorderable children out of the box (but only if I include the class in the Lookup of the root node, as shown above). If you're using Children.Keys or ChildFactory, the children class could implement Index. Or you could create a new class that extends Index.Support, which should then be added to the Lookup as shown above. But then you would have to handle the reordering yourself, unlike with Index.ArrayChildren which, as can be seen above, gives you that functionality for free.

Join the discussion

Comments ( 1 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.