swingx
Version 2005-08-19

org.jdesktop.swingx.treetable
Class AbstractTreeTableModel

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

public abstract class AbstractTreeTableModel
extends Object
implements TreeTableModel

AbstractTreeTableModel provides an implementation of TreeTableModel as a convenient starting point in defining custom data models for JXTreeTable.


Field Summary
static Class hierarchicalColumnClass
          Value returned by getColumnClass for the hierarchical column.
protected  EventListenerList listenerList
          Event listener list
protected  Object root
          Root node of the model
 
Constructor Summary
AbstractTreeTableModel()
          Constructs an AbstractTreeTableModel with a null root node
AbstractTreeTableModel(Object root)
          Constructs an AbstractTreeTableModel with the specified node as the root node.
 
Method Summary
 void addTreeModelListener(TreeModelListener l)
           
protected  void fireTreeNodesChanged(Object source, Object[] path, int[] childIndices, Object[] children)
           
protected  void fireTreeNodesInserted(Object source, Object[] path, int[] childIndices, Object[] children)
           
protected  void fireTreeNodesRemoved(Object source, Object[] path, int[] childIndices, Object[] children)
           
protected  void fireTreeStructureChanged(Object source, Object[] path, int[] childIndices, Object[] children)
           
 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 in the specified parent node.
 Class getColumnClass(int column)
          
 int getColumnCount()
          
 String getColumnName(int column)
          
 int getIndexOfChild(Object parent, Object child)
          Returns the index of child in parent.
 EventListener[] getListeners(Class listenerType)
          Returns an array of all the objects currently registered as FooListeners upon this model.
 Object getRoot()
          
 TreeModelListener[] getTreeModelListeners()
           
 boolean isCellEditable(Object node, int column)
          
 boolean isLeaf(Object node)
          Returns true if the specified node is a leaf node; false otherwise.
 void removeTreeModelListener(TreeModelListener l)
           
 void valueForPathChanged(TreePath path, 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 org.jdesktop.swingx.treetable.TreeTableModel
getValueAt, setValueAt
 

Field Detail

hierarchicalColumnClass

public static final Class hierarchicalColumnClass
Value returned by getColumnClass for the hierarchical column.


root

protected 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(Object root)
Constructs an AbstractTreeTableModel with the specified node as the root node.

Parameters:
root - root node
Method Detail

getColumnClass

public Class getColumnClass(int column)

Specified by:
getColumnClass in interface TreeTableModel

getColumnName

public String getColumnName(int column)

Specified by:
getColumnName in interface TreeTableModel

getRoot

public Object getRoot()

Specified by:
getRoot in interface TreeModel

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, or null if the specified parent node is not a TreeNode.

getChildCount

public int getChildCount(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()

Specified by:
getColumnCount in interface TreeTableModel

getIndexOfChild

public int getIndexOfChild(Object parent,
                           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

isCellEditable

public boolean isCellEditable(Object node,
                              int column)

Specified by:
isCellEditable in interface TreeTableModel

isLeaf

public boolean isLeaf(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

valueForPathChanged

public void valueForPathChanged(TreePath path,
                                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 from the TreeCellEditor

addTreeModelListener

public void addTreeModelListener(TreeModelListener l)
Specified by:
addTreeModelListener in interface TreeModel

removeTreeModelListener

public void removeTreeModelListener(TreeModelListener l)
Specified by:
removeTreeModelListener in interface TreeModel

getTreeModelListeners

public TreeModelListener[] getTreeModelListeners()

fireTreeNodesChanged

protected void fireTreeNodesChanged(Object source,
                                    Object[] path,
                                    int[] childIndices,
                                    Object[] children)

fireTreeNodesInserted

protected void fireTreeNodesInserted(Object source,
                                     Object[] path,
                                     int[] childIndices,
                                     Object[] children)

fireTreeNodesRemoved

protected void fireTreeNodesRemoved(Object source,
                                    Object[] path,
                                    int[] childIndices,
                                    Object[] children)

fireTreeStructureChanged

protected void fireTreeStructureChanged(Object source,
                                        Object[] path,
                                        int[] childIndices,
                                        Object[] children)

getListeners

public EventListener[] getListeners(Class listenerType)
Returns an array of all the objects currently registered as FooListeners upon this model. FooListeners are registered using the addFooListener method.

You can specify the listenerType argument with a class literal, such as FooListener.class. For example, you can query a DefaultTreeModel m for its tree model listeners with the following code:

TreeModelListener[] tmls = (TreeModelListener[])(m.getListeners(TreeModelListener.class));
If no such listeners exist, this method returns an empty array.

Parameters:
listenerType - the type of listeners requested; this parameter should specify an interface that descends from java.util.EventListener
Returns:
an array of all objects registered as FooListeners on this component, or an empty array if no such listeners have been added
Throws:
ClassCastException - if listenerType doesn't specify a class or interface that implements java.util.EventListener
Since:
1.3
See Also:
getTreeModelListeners()

swingx
Version 2005-08-19