org.jurvis.swing.tree
Class JvDynamicTreeNode

java.lang.Object
  extended by javax.swing.tree.DefaultMutableTreeNode
      extended by org.jurvis.swing.tree.JvDynamicTreeNode
All Implemented Interfaces:
Serializable, Cloneable, MutableTreeNode, TreeNode
Direct Known Subclasses:
JvDefaultExplorerNode, JvDynamicCheckedTreeNode

public class JvDynamicTreeNode
extends DefaultMutableTreeNode

A DefaultMutableTreeNode that permits on-demand loading of children. Frequently, to improve performance, children nodes are only loaded as the user expands the node. This class provides a standard means of lazily loading children nodes via the doChildrenQuery() method.

Author:
Neil W. Weber
See Also:
Serialized Form

Field Summary
protected  boolean wasQueried
          True if this node has been queried for its children.
 
Fields inherited from class javax.swing.tree.DefaultMutableTreeNode
allowsChildren, children, EMPTY_ENUMERATION, parent, userObject
 
Constructor Summary
JvDynamicTreeNode(Object userObject)
          Construct a JvDynamicTreeNode.
 
Method Summary
 Enumeration children()
          Returns the children of the reciever as an Enumeration.
protected  boolean doChildrenQuery()
          Determine if this node has any children and link them to this node.
 TreeNode getChildAt(int childIndex)
          Returns the child TreeNode at index childIndex.
 int getChildCount()
          Returns the number of children TreeNodes the receiver contains.
 boolean wasQueried()
          Returns true if the children of the node have been queried for.
 
Methods inherited from class javax.swing.tree.DefaultMutableTreeNode
add, breadthFirstEnumeration, clone, depthFirstEnumeration, getAllowsChildren, getChildAfter, getChildBefore, getDepth, getFirstChild, getFirstLeaf, getIndex, getLastChild, getLastLeaf, getLeafCount, getLevel, getNextLeaf, getNextNode, getNextSibling, getParent, getPath, getPathToRoot, getPreviousLeaf, getPreviousNode, getPreviousSibling, getRoot, getSharedAncestor, getSiblingCount, getUserObject, getUserObjectPath, insert, isLeaf, 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

wasQueried

protected boolean wasQueried
True if this node has been queried for its children.

Constructor Detail

JvDynamicTreeNode

public JvDynamicTreeNode(Object userObject)
Construct a JvDynamicTreeNode.

Parameters:
userObject - the object that constitutes the node's data
Method Detail

wasQueried

public boolean wasQueried()
Returns true if the children of the node have been queried for. This method may be used when traversing the tree to avoid traversing into sub-trees that haven't yet been loaded.

Returns:
true if the children of the node have been queried for

getChildAt

public TreeNode getChildAt(int childIndex)
Returns the child TreeNode at index childIndex.

Specified by:
getChildAt in interface TreeNode
Overrides:
getChildAt in class DefaultMutableTreeNode

getChildCount

public int getChildCount()
Returns the number of children TreeNodes the receiver contains.

Specified by:
getChildCount in interface TreeNode
Overrides:
getChildCount in class DefaultMutableTreeNode

children

public Enumeration children()
Returns the children of the reciever as an Enumeration.

Specified by:
children in interface TreeNode
Overrides:
children in class DefaultMutableTreeNode

doChildrenQuery

protected boolean doChildrenQuery()
Determine if this node has any children and link them to this node. This method is only called once per node. Currently this method does nothing; subclasses should override this method to perform custom children queries.

Note that a very common error is to forget to set the parent link of each child. Symptoms of this problem include the inability to programmatically expand or select nodes.

Returns:
true if the query was successful


Copyright © 1999-2004 Neil W. Weber. All Rights Reserved.