echopointng.treetable
Class AbstractTreeTableModel

java.lang.Object
  extended by echopointng.treetable.AbstractTreeTableModel
All Implemented Interfaces:
TreeModel, TreeTableModel
Direct Known Subclasses:
DefaultTreeTableModel

public abstract class AbstractTreeTableModel
extends java.lang.Object
implements TreeTableModel

AbstractTreeTableModel provides an implementation of TreeTableModelas a convenient starting point in defining custom data models for TreeTable.


Field Summary
static java.lang.Class hierarchicalColumnClass
          Value returned by getColumnClassfor the hierarchicalcolumn.
protected  EventListenerList listenerList
          Event listener list
protected  java.lang.Object root
          Root node of the model
 
Constructor Summary
AbstractTreeTableModel()
          Constructs an AbstractTreeTableModel with a null root node
AbstractTreeTableModel(java.lang.Object root)
          Constructs an AbstractTreeTableModel with the specified node as the root node.
 
Method Summary
 void addTreeModelListener(TreeModelListener l)
          Adds a listener for the TreeModelEvent posted after the tree changes.
protected  void fireTreeNodesChanged(java.lang.Object source, java.lang.Object[] path, int[] childIndices, java.lang.Object[] children)
          Notify all listeners that have registered interest for notification on this event type.
protected  void fireTreeNodesInserted(java.lang.Object source, java.lang.Object[] path, int[] childIndices, java.lang.Object[] children)
          Notify all listeners that have registered interest for notification on this event type.
protected  void fireTreeNodesRemoved(java.lang.Object source, java.lang.Object[] path, int[] childIndices, java.lang.Object[] children)
          Notify all listeners that have registered interest for notification on this event type.
protected  void fireTreeStructureChanged(java.lang.Object source, java.lang.Object[] path, int[] childIndices, java.lang.Object[] children)
          Notify all listeners that have registered interest for notification on this event type.
 java.lang.Object getChild(java.lang.Object parent, int index)
          Returns the child of parent at index index in the parent's child array.
 int getChildCount(java.lang.Object parent)
          Returns the number of children in the specified parent node.
 java.lang.Class getColumnClass(int column)
          
 int getColumnCount()
          This is one of the methods you must override as it simply returns 1.
 java.lang.String getColumnName(int column)
          
 int getIndexOfChild(java.lang.Object parent, java.lang.Object child)
          Returns the index of child in parent.
 java.lang.Object getParent(java.lang.Object child)
          Returns the parent of child .
 java.lang.Object[] getPathToRoot(java.lang.Object node)
          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.
 java.lang.Object getRoot()
          Returns the root of the tree.
 TreeModelListener[] getTreeModelListeners()
           
 boolean isLeaf(java.lang.Object node)
          Returns true if the specified node is a leaf node; false otherwise.
 void removeTreeModelListener(TreeModelListener l)
          Removes a listener previously added with addTreeModelListener().
 void valueForPathChanged(TreePath path, java.lang.Object newValue)
          Called when value for the item identified by path has been changed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface echopointng.treetable.TreeTableModel
getValueAt
 

Field Detail

hierarchicalColumnClass

public static final java.lang.Class hierarchicalColumnClass
Value returned by getColumnClassfor the hierarchicalcolumn.


root

protected java.lang.Object root
Root node of the model


listenerList

protected EventListenerList listenerList
Event listener list

Constructor Detail

AbstractTreeTableModel

public AbstractTreeTableModel()
Constructs an AbstractTreeTableModel with a null root node


AbstractTreeTableModel

public AbstractTreeTableModel(java.lang.Object root)
Constructs an AbstractTreeTableModel with the specified node as the root node.

Parameters:
root - root node
Method Detail

getColumnClass

public java.lang.Class getColumnClass(int column)

Specified by:
getColumnClass in interface TreeTableModel
See Also:
TableModel.getColumnClass(int)

getColumnName

public java.lang.String getColumnName(int column)

Specified by:
getColumnName in interface TreeTableModel
See Also:
TableModel.getColumnName(int)

getRoot

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

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

getChild

public java.lang.Object getChild(java.lang.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 , or null if the specified parent node is not a TreeNode.

getParent

public java.lang.Object getParent(java.lang.Object child)
Returns the parent of child . Returns null if the node has no parent or the tree model does not support traversing from a child to a parent node.

Parameters:
child - a node in the tree
Returns:
the parent of the node child

getChildCount

public int getChildCount(java.lang.Object parent)
Returns the number of children in the specified parent node.

Specified by:
getChildCount in interface TreeModel
Parameters:
parent - node whose child count is being requested
Returns:
the number of children in the specified parent node

getColumnCount

public int getColumnCount()
This is one of the methods you must override as it simply returns 1.

Specified by:
getColumnCount in interface TreeTableModel
See Also:
TreeTableModel.getColumnCount()

getIndexOfChild

public int getIndexOfChild(java.lang.Object parent,
                           java.lang.Object child)
Returns the index of child in parent. If either the parent 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 the parent or the child is null

isLeaf

public boolean isLeaf(java.lang.Object node)
Returns true if the specified node is a leaf node; false otherwise.

Specified by:
isLeaf in interface TreeModel
Parameters:
node - node to test
Returns:
true if the specified node is a leaf node; false otherwise

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.

Parameters:
aNode - the TreeNode to get the path for
depth - an int giving the number of steps already taken towards the root (on recursive calls), used to size the returned array
Returns:
an array of TreeNodes giving the path from the root to the specified node

getPathToRoot

public java.lang.Object[] getPathToRoot(java.lang.Object node)
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.

Parameters:
node - the TreeNode to get the path for

valueForPathChanged

public void valueForPathChanged(TreePath path,
                                java.lang.Object newValue)
Called when value for the item identified by path has been changed. 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 has changed
newValue - the new value

addTreeModelListener

public void addTreeModelListener(TreeModelListener l)
Description copied from interface: TreeModel
Adds a listener for the TreeModelEvent posted after the tree changes.

Specified by:
addTreeModelListener in interface TreeModel
Parameters:
l - the listener to add

removeTreeModelListener

public void removeTreeModelListener(TreeModelListener l)
Description copied from interface: TreeModel
Removes a listener previously added with addTreeModelListener().

Specified by:
removeTreeModelListener in interface TreeModel

getTreeModelListeners

public TreeModelListener[] getTreeModelListeners()

fireTreeNodesChanged

protected void fireTreeNodesChanged(java.lang.Object source,
                                    java.lang.Object[] path,
                                    int[] childIndices,
                                    java.lang.Object[] children)
Notify all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

See Also:
EventListenerList

fireTreeNodesInserted

protected void fireTreeNodesInserted(java.lang.Object source,
                                     java.lang.Object[] path,
                                     int[] childIndices,
                                     java.lang.Object[] children)
Notify all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

See Also:
EventListenerList

fireTreeNodesRemoved

protected void fireTreeNodesRemoved(java.lang.Object source,
                                    java.lang.Object[] path,
                                    int[] childIndices,
                                    java.lang.Object[] children)
Notify all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

See Also:
EventListenerList

fireTreeStructureChanged

protected void fireTreeStructureChanged(java.lang.Object source,
                                        java.lang.Object[] path,
                                        int[] childIndices,
                                        java.lang.Object[] children)
Notify all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

See Also:
EventListenerList