kiwi.ui.model
Class StaticTreeModel

java.lang.Object
  |
  +--kiwi.ui.model.StaticTreeModel
Direct Known Subclasses:
DynamicTreeModel

public class StaticTreeModel
extends Object
implements ITreeModel

An implementation of ITreeModel that represents a static hierarchical data structure. The model preloads all of the children in the tree.

Version:
1.1 (10/98)
Author:
Mark Lindner, PING Software Group
See Also:
DynamicTreeModel

Inner Class Summary
protected  class StaticTreeModel.TreeNode
          Internal wrapper object for nodes.
 
Field Summary
protected  StaticTreeModel.TreeNode root
          The model's root node.
protected  HierarchicalDataSource source
          The model's data source.
 
Constructor Summary
protected StaticTreeModel()
          Construct a new StaticTreeModel.
  StaticTreeModel(HierarchicalDataSource source)
          Construct a new StaticTreeModel for a given data source.
 
Method Summary
 void addTreeModelListener(TreeModelListener listener)
          Add a TreeModelListener to this model's list of listeners.
 void collapse(ITreeNode node)
          Collapse a node.
 void expand(ITreeNode node)
          Expand a node.
protected  void fireNodeAdded(ITreeNode node, int index, ITreeNode parent)
          Notify listeners that a node has been added.
protected  void fireNodeChanged(ITreeNode node)
          Notify listeners that a node has changed.
protected  void fireNodeCollapsed(ITreeNode node)
          Notify listeners that a node has been collapsed.
protected  void fireNodeCollapsing(ITreeNode node)
          Notify listeners that a node will be collapsed.
protected  void fireNodeExpanded(ITreeNode node)
          Notify listeners that a node has been expanded.
protected  void fireNodeExpanding(ITreeNode node)
          Notify listeners that a node will be expanded.
protected  void fireNodeRemoved(ITreeNode node, int index, ITreeNode parent)
          Notify listeners that a node has been removed.
protected  void fireNodeStructureChanged(ITreeNode node)
          Notify listeners that the structure of the subtree rooted at a node has changed.
 int getChildCount(ITreeNode node)
          Get the child count for a node.
 ITreeNode[] getChildren(ITreeNode node)
          Get a node's children.
 ITreeNode getParent(ITreeNode node)
          Get the parent of a given node.
 ITreeNode getRoot()
          Get the root of the model.
 Object getValueForProperty(String property, ITreeNode node)
          Get the value of an arbitrary property for a given node.
 boolean isExpandable(ITreeNode node)
          Determine if a node is expandable.
 boolean isExpanded(ITreeNode node)
          Determine if a node is currently expanded.
protected  void loadChildren(StaticTreeModel.TreeNode node)
          Load the children for a given node by consulting the data source.
 void removeTreeModelListener(TreeModelListener listener)
          Remove a TreeModelListener from this model's list of listeners.
protected  void unloadChildren(StaticTreeModel.TreeNode node)
          Unload the children for a given node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

root

protected StaticTreeModel.TreeNode root
The model's root node.

source

protected HierarchicalDataSource source
The model's data source.
Constructor Detail

StaticTreeModel

protected StaticTreeModel()
Construct a new StaticTreeModel.

StaticTreeModel

public StaticTreeModel(HierarchicalDataSource source)
Construct a new StaticTreeModel for a given data source.
Parameters:
source - The data source that will provide nodes for this model.
Method Detail

getParent

public ITreeNode getParent(ITreeNode node)
Get the parent of a given node.
Specified by:
getParent in interface ITreeModel
Parameters:
node - The node.

isExpanded

public boolean isExpanded(ITreeNode node)
Determine if a node is currently expanded.
Specified by:
isExpanded in interface ITreeModel
Parameters:
node - The node.

isExpandable

public boolean isExpandable(ITreeNode node)
Determine if a node is expandable.
Specified by:
isExpandable in interface ITreeModel
Parameters:
node - The node.

getValueForProperty

public Object getValueForProperty(String property,
                                  ITreeNode node)
Get the value of an arbitrary property for a given node. An ITreeNode wrapper object is passed rather than the original object so that state information about the object within the tree can be determined.
Specified by:
getValueForProperty in interface ITreeModel
Parameters:
node - The node.
property - The name of the property.
Returns:
The value of the specified property, or null if there is no value for this property.
See Also:
ITreeNode

getRoot

public ITreeNode getRoot()
Get the root of the model.
Specified by:
getRoot in interface ITreeModel

getChildCount

public int getChildCount(ITreeNode node)
Get the child count for a node.
Specified by:
getChildCount in interface ITreeModel
Parameters:
node - The node.
Returns:
The child count for the node.

getChildren

public ITreeNode[] getChildren(ITreeNode node)
Get a node's children. Returns an Enumeration of the children of the specified node.
Specified by:
getChildren in interface ITreeModel
Parameters:
parent - The node whose children should be returned.

loadChildren

protected final void loadChildren(StaticTreeModel.TreeNode node)
Load the children for a given node by consulting the data source.
Parameters:
node - The node.
See Also:
unloadChildren(kiwi.ui.model.StaticTreeModel.TreeNode)

unloadChildren

protected final void unloadChildren(StaticTreeModel.TreeNode node)
Unload the children for a given node.
Parameters:
node - The node.
See Also:
loadChildren(kiwi.ui.model.StaticTreeModel.TreeNode)

addTreeModelListener

public void addTreeModelListener(TreeModelListener listener)
Add a TreeModelListener to this model's list of listeners.
Specified by:
addTreeModelListener in interface ITreeModel
Parameters:
listener - The listener to be added.
See Also:
removeTreeModelListener(kiwi.event.TreeModelListener)

removeTreeModelListener

public void removeTreeModelListener(TreeModelListener listener)
Remove a TreeModelListener from this model's list of listeners.
Specified by:
removeTreeModelListener in interface ITreeModel
Parameters:
listener - The listener to remove.
See Also:
addTreeModelListener(kiwi.event.TreeModelListener)

fireNodeExpanding

protected final void fireNodeExpanding(ITreeNode node)
Notify listeners that a node will be expanded.
Parameters:
node - The node that will be expanded.

fireNodeExpanded

protected final void fireNodeExpanded(ITreeNode node)
Notify listeners that a node has been expanded.
Parameters:
node - The node that was expanded.

fireNodeCollapsing

protected final void fireNodeCollapsing(ITreeNode node)
Notify listeners that a node will be collapsed.
Parameters:
node - The node that will be collapsed.

fireNodeCollapsed

protected final void fireNodeCollapsed(ITreeNode node)
Notify listeners that a node has been collapsed.
Parameters:
node - The node that was collapsed.

fireNodeAdded

protected final void fireNodeAdded(ITreeNode node,
                                   int index,
                                   ITreeNode parent)
Notify listeners that a node has been added.
Parameters:
node - The new node.
index - The index of the new node in its parent's list of children.
parent - The parent of the new node.

fireNodeRemoved

protected final void fireNodeRemoved(ITreeNode node,
                                     int index,
                                     ITreeNode parent)
Notify listeners that a node has been removed.
Parameters:
node - The node that was removed.
parent - The parent of the removed node.

fireNodeChanged

protected final void fireNodeChanged(ITreeNode node)
Notify listeners that a node has changed.
Parameters:
node - The node that changed.

fireNodeStructureChanged

protected final void fireNodeStructureChanged(ITreeNode node)
Notify listeners that the structure of the subtree rooted at a node has changed.
Parameters:
node - The node that is the root of the subtree.

expand

public void expand(ITreeNode node)
Expand a node. Expanding a node initiates the display of its children. The model will fire a TreeModelEvent to notify listeners when th children should be displayed.
Specified by:
expand in interface ITreeModel
Parameters:
node - The node to expand.

collapse

public void collapse(ITreeNode node)
Collapse a node. Collapsing a node hides its children from the display. The model will fire a TreeModelEvent to notify listeners when the children should be hidden.
Specified by:
collapse in interface ITreeModel
Parameters:
node - The node to collapse.