Copyright © 2005 Scientific Applications. All Rights Reserved.

com.sciapp.treetable
Class TreeModelMap

java.lang.Object
  extended by com.sciapp.treetable.AbstractTreeTableModel
      extended by com.sciapp.treetable.TreeModelMap
All Implemented Interfaces:
TreeTableModel, Serializable, EventListener, TreeModelListener, TreeModel
Direct Known Subclasses:
DefaultRemoteTreeTableModel, DynamicTreeTableModel, TreeTableModelMap

public abstract class TreeModelMap
extends AbstractTreeTableModel
implements TreeModelListener

TreeModelMap is a wrapper around a TreeTableModel.

See Also:
Serialized Form

Field Summary
protected  TreeModel treeModel
          the underlying treemodel.
 
Fields inherited from class com.sciapp.treetable.AbstractTreeTableModel
listenerList, root
 
Fields inherited from interface com.sciapp.treetable.TreeTableModel
CHANGE_COLUMN_SOURCE
 
Constructor Summary
TreeModelMap(TreeModel treeModel)
          Constructs a TreeModelMap.
 
Method Summary
 Object getChild(Object parent, int index)
          Returns the child of parent at index index in the parent's child array.
 int getChildCount(Object parent)
          Returns the number of children of parent.
 int getIndexOfChild(Object parent, Object child)
          Returns the index of child in parent.
 TreeNode[] getPathToRoot(TreeNode aNode)
          Builds the parents of node up to and including the root node, where the original node is the last element in the returned array.
protected  TreeNode[] getPathToRoot(TreeNode aNode, int depth)
          Builds the parents of node up to and including the root node, where the original node is the last element in the returned array.
 Object getRoot()
          Returns the root of the tree. Returns null only if the tree has no nodes.
 TreeModel getTreeModel()
          Returns the underlying tree model.
 boolean isLeaf(Object node)
          Returns true if node is a leaf.
 void nodeChanged(TreeNode node)
          This method should be invoked when the representation of node in the tree has changed.
 void nodesChanged(TreeNode node, int[] childIndices)
          This method should be invoked when the representation of the children identified by childIndices in the tree has changed.
 void nodeStructureChanged(TreeNode node)
          This method should be invoked when the children of node and its children children have completely changed.
 void setTreeModel(TreeModel newModel)
          Sets the underlying tree model to newModel
 void treeNodesChanged(TreeModelEvent e)
          

Invoked after a node (or a set of siblings) has changed in some way.

 void treeNodesInserted(TreeModelEvent e)
          

Invoked after nodes have been inserted into the tree.

 void treeNodesRemoved(TreeModelEvent e)
          

Invoked after nodes have been removed from the tree.

 void treeStructureChanged(TreeModelEvent e)
          

Invoked after the tree has drastically changed structure from a given node down.

 void valueForPathChanged(TreePath path, Object newValue)
          Messaged when the user has altered the value for the item identified by path to newValue.
 
Methods inherited from class com.sciapp.treetable.AbstractTreeTableModel
addTreeModelListener, fireTreeNodesChanged, fireTreeNodesInserted, fireTreeNodesRemoved, fireTreeStructureChanged, fireTreeTableStructureChanged, fireTreeTableStructureChanged, isAggregate, isFooter, isHeader, removeTreeModelListener, setRoot
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.sciapp.treetable.TreeTableModel
getColumnClass, getColumnCount, getColumnName, getValueAt, isCellEditable, setValueAt
 

Field Detail

treeModel

protected TreeModel treeModel
the underlying treemodel.

Constructor Detail

TreeModelMap

public TreeModelMap(TreeModel treeModel)
Constructs a TreeModelMap.

Method Detail

getChild

public Object getChild(Object parent,
                       int index)
Returns the child of parent at index index in the parent's child array. parent must be a node previously obtained from this data source. This should not return null if index is a valid index for parent (that is index >= 0 && index < getChildCount(parent)).

Specified by:
getChild in interface TreeModel
Parameters:
parent - a node in the tree, obtained from this data source
Returns:
the child of parent at index index

getChildCount

public int getChildCount(Object parent)
Returns the number of children of parent. Returns 0 if the node is a leaf or if it has no children. parent must be a node previously obtained from this data source.

Specified by:
getChildCount in interface TreeModel
Parameters:
parent - a node in the tree, obtained from this data source
Returns:
the number of children of the node parent

getIndexOfChild

public int getIndexOfChild(Object parent,
                           Object child)
Returns the index of child in parent. If parent is null or child is null, returns -1.

Specified by:
getIndexOfChild in interface TreeModel
Parameters:
parent - a note in the tree, obtained from this data source
child - the node we are interested in
Returns:
the index of the child in the parent, or -1 if either child or parent are null

getPathToRoot

public TreeNode[] getPathToRoot(TreeNode aNode)
Builds the parents of node up to and including the root node, where the original node is the last element in the returned array. The length of the returned array gives the node's depth in the tree.


getPathToRoot

protected TreeNode[] getPathToRoot(TreeNode aNode,
                                   int depth)
Builds the parents of node up to and including the root node, where the original node is the last element in the returned array. The length of the returned array gives the node's depth in the tree.


getRoot

public Object getRoot()
Returns the root of the tree. Returns null only if the tree has no nodes.

Specified by:
getRoot in interface TreeModel
Overrides:
getRoot in class AbstractTreeTableModel
Returns:
the root of the tree

getTreeModel

public TreeModel getTreeModel()
Returns the underlying tree model.

Returns:
the underlying tree model.

isLeaf

public boolean isLeaf(Object node)
Returns true if node is a leaf. It is possible for this method to return false even if node has no children. A directory in a filesystem, for example, may contain no files; the node representing the directory is not a leaf, but it also has no children.

Specified by:
isLeaf in interface TreeModel
Parameters:
node - a node in the tree, obtained from this data source
Returns:
true if node is a leaf

nodeChanged

public void nodeChanged(TreeNode node)
This method should be invoked when the representation of node in the tree has changed.


nodesChanged

public void nodesChanged(TreeNode node,
                         int[] childIndices)
This method should be invoked when the representation of the children identified by childIndices in the tree has changed.


nodeStructureChanged

public void nodeStructureChanged(TreeNode node)
This method should be invoked when the children of node and its children children have completely changed. This will post a treeStructureChanged event.


setTreeModel

public void setTreeModel(TreeModel newModel)
Sets the underlying tree model to newModel

Parameters:
newModel - the new tree model to assign.

treeStructureChanged

public void treeStructureChanged(TreeModelEvent e)

Invoked after the tree has drastically changed structure from a given node down. If the path returned by e.getPath() is of length one and the first element does not identify the current root node the first element should become the new root of the tree.

Use e.getPath() to get the path to the node. e.getChildIndices() returns null.

Specified by:
treeStructureChanged in interface TreeModelListener

valueForPathChanged

public void valueForPathChanged(TreePath path,
                                Object newValue)
Messaged when the user has altered the value for the item identified by path to newValue. If newValue signifies a truly new value the model should post a treeNodesChanged event.

Specified by:
valueForPathChanged in interface TreeModel
Parameters:
path - path to the node that the user has altered
newValue - the new value from the TreeCellEditor

treeNodesChanged

public void treeNodesChanged(TreeModelEvent e)

Invoked after a node (or a set of siblings) has changed in some way. The node(s) have not changed locations in the tree or altered their children arrays, but other attributes have changed and may affect presentation. Example: the name of a file has changed, but it is in the same location in the file system.

To indicate the root has changed, childIndices and children will be null.

Use e.getPath() to get the parent of the changed node(s). e.getChildIndices() returns the index(es) of the changed node(s).

Specified by:
treeNodesChanged in interface TreeModelListener

treeNodesInserted

public void treeNodesInserted(TreeModelEvent e)

Invoked after nodes have been inserted into the tree.

Use e.getPath() to get the parent of the new node(s). e.getChildIndices() returns the index(es) of the new node(s) in ascending order.

Specified by:
treeNodesInserted in interface TreeModelListener

treeNodesRemoved

public void treeNodesRemoved(TreeModelEvent e)

Invoked after nodes have been removed from the tree. Note that if a subtree is removed from the tree, this method may only be invoked once for the root of the removed subtree, not once for each individual set of siblings removed.

Use e.getPath() to get the former parent of the deleted node(s). e.getChildIndices() returns, in ascending order, the index(es) the node(s) had before being deleted.

Specified by:
treeNodesRemoved in interface TreeModelListener

Copyright © 2005 Scientific Applications. All Rights Reserved.