com.metamatrix.console.ui.util
Class LazyBranchNode

java.lang.Object
  extended by javax.swing.tree.DefaultMutableTreeNode
      extended by com.metamatrix.console.ui.tree.ChildSortingTreeNode
          extended by com.metamatrix.console.ui.util.LazyBranchNode
All Implemented Interfaces:
SortsChildren, java.io.Serializable, java.lang.Cloneable, javax.swing.tree.MutableTreeNode, javax.swing.tree.TreeNode

public abstract class LazyBranchNode
extends ChildSortingTreeNode

LazyBranchNode is a specialization of DefaultMutableTreeNode that delays populating its child nodes until it is expanded. To use, extend this class (typically as an inner class) and implement the populate method to obtain the child nodes, construct new LazyBranchNodes for each child branch and new DefaultMutableTreeNodes for each leaf, and call add(newChild) for each child node. Example:

   class MyLazyNode extends LazyBranchNode {
       MyLazyNode(Object id) {
           super(id);
       }
       public void populate() {
           if ( ! isPopulated() ) {  // will be true if add() has ever been called on this node
               Iterator iter = MyDataManager.getChildrenOfNode(id).iterator();
               while ( iter.hasNext() ) {
                   Object obj = iter.next();
                   if ( obj instanceof ALeafNodeClass ) {
                       this.add( new DefaultMutableTreeNode(node) );  // leaf nodes
                   } else {
                       this.add( new ResourceNode(node) );            // branch nodes
                   }
               }
           }
       }
   }
 

See Also:
LazyBranchListener, Serialized Form

Field Summary
protected  java.lang.Object id
           
protected  boolean populated
           
 
Fields inherited from class javax.swing.tree.DefaultMutableTreeNode
allowsChildren, children, EMPTY_ENUMERATION, parent, userObject
 
Fields inherited from interface com.metamatrix.console.ui.tree.SortsChildren
ALPHABETIC_SORT, NO_SORT, NUMERIC_SORT
 
Constructor Summary
LazyBranchNode(javax.swing.tree.DefaultTreeModel treeModel, java.lang.Object id)
           
 
Method Summary
 void add(javax.swing.tree.MutableTreeNode newChild)
           
 boolean isLeaf()
           
 boolean isPopulated()
           
abstract  void populate()
           
 void resetPopulated()
           
 void setPopulated()
           
 
Methods inherited from class com.metamatrix.console.ui.tree.ChildSortingTreeNode
getModel, getSortType, insert, isUsingUserObjectToString, setModel, setSortType, setUsingUserObjectToString, sortChildren, sortTree
 
Methods inherited from class javax.swing.tree.DefaultMutableTreeNode
breadthFirstEnumeration, children, clone, depthFirstEnumeration, getAllowsChildren, getChildAfter, getChildAt, getChildBefore, getChildCount, getDepth, getFirstChild, getFirstLeaf, getIndex, getLastChild, getLastLeaf, getLeafCount, getLevel, getNextLeaf, getNextNode, getNextSibling, getParent, getPath, getPathToRoot, getPreviousLeaf, getPreviousNode, getPreviousSibling, getRoot, getSharedAncestor, getSiblingCount, getUserObject, getUserObjectPath, isNodeAncestor, isNodeChild, isNodeDescendant, isNodeRelated, isNodeSibling, isRoot, pathFromAncestorEnumeration, postorderEnumeration, preorderEnumeration, remove, remove, removeAllChildren, removeFromParent, setAllowsChildren, setParent, setUserObject, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

id

protected java.lang.Object id

populated

protected boolean populated
Constructor Detail

LazyBranchNode

public LazyBranchNode(javax.swing.tree.DefaultTreeModel treeModel,
                      java.lang.Object id)
Method Detail

add

public void add(javax.swing.tree.MutableTreeNode newChild)
Overrides:
add in class ChildSortingTreeNode

isLeaf

public boolean isLeaf()
Specified by:
isLeaf in interface javax.swing.tree.TreeNode
Overrides:
isLeaf in class javax.swing.tree.DefaultMutableTreeNode

isPopulated

public boolean isPopulated()

setPopulated

public void setPopulated()

resetPopulated

public void resetPopulated()

populate

public abstract void populate()
                       throws java.lang.Exception
Throws:
java.lang.Exception


Copyright © 2009. All Rights Reserved.