Adding Children to Other Tree Nodes

When a CTreeNode object is expanded for the first time, each plug-in gets the opportunity to add child nodes to the CTreeNode being expanded.

In the plug-in root, add a class called ConsoleTreeHandler. In our example, this would be com.MyPlugin.ConsoleTreeHandler. Add a method called “getTreeNodeChildren()” to this class. The source code should look something like the following example:

public static CTreeNode[] getTreeNodeChildren(CTreeNode node) {	
  // strictly speaking, this check for null should never be	
  // necessary
  if (node == null)
    return new CTreeNode[0];
  if (node instanceof SomeSpecificTreeNode) {
    CTreeNode[] theChildren = new CTreeNode[5];
    theChildren[0] = new ChildNode();
    theChildren[1] = new AnotherChildNode();
    // and so on...
    return theChildren;
  }
  else if (node instanceof SomeOtherTreeNode) {
    // different set of children here.
  }
  // and if we're not interested in any other types.
  return new CTreeNode[0].
}

Item of interest for this operation: