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, FileSystemModel

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. It takes care of listener management and contains convenience methods for creating and dispatching TreeModelEvents. To create a concreate instance of TreeTableModel you need only to provide implementations for the following methods:

 public int getColumnCount();
 public Object getValueAt(Object node, int column);
 public Object getChild(Object parent, int index);
 public int getChildCount(Object parent);
 public int getIndexOfChild(Object parent, Object child);
 public boolean isLeaf(Object node);
 


Field Summary
protected  TreeModelSupport modelSupport
          Provides support for event dispatching.
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 root node.
 
Method Summary
 void addTreeModelListener(TreeModelListener l)
          Adds a listener for the TreeModelEvent posted after the tree changes.
 Class<?> getColumnClass(int column)
          Returns the most specific superclass for all the cell values in the column.
 String getColumnName(int column)
          Returns the name of the column at columnIndex.
 int getHierarchicalColumn()
          Returns the column that is the "tree" column.
 Object getRoot()
          Returns the root of the tree.
 TreeModelListener[] getTreeModelListeners()
          Returns an array of all the TreeModelListeners added to this JXTreeTable with addTreeModelListener().
 boolean isCellEditable(Object node, int column)
          Returns true if the cell for the node at columnIndex is editable.
 boolean isLeaf(Object node)
          Returns true if node is a leaf.
 void removeTreeModelListener(TreeModelListener l)
          Removes a listener previously added with addTreeModelListener.
 void setValueAt(Object value, Object node, int column)
          Sets the value for the node at columnIndex to value.
 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
getColumnCount, getValueAt
 
Methods inherited from interface javax.swing.tree.TreeModel
getChild, getChildCount, getIndexOfChild
 

Field Detail

root

protected Object root
Root node of the model


modelSupport

protected TreeModelSupport modelSupport
Provides support for event dispatching.

Constructor Detail

AbstractTreeTableModel

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


AbstractTreeTableModel

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

Parameters:
root - root node
Method Detail

getColumnClass

public Class<?> getColumnClass(int column)
Returns the most specific superclass for all the cell values in the column. This is used by the JXTreeTable to set up a default renderer and editor for the column.

Specified by:
getColumnClass in interface TreeTableModel
Parameters:
column - the index of the column
Returns:
the common ancestor class of the object values in the model.
See Also:
TableModel.getColumnClass(int)

getColumnName

public String getColumnName(int column)
Returns the name of the column at columnIndex. This is used to initialize the table's column header name. Note: this name does not need to be unique; two columns in a table can have the same name.

Specified by:
getColumnName in interface TreeTableModel
Parameters:
column - the index of the column
Returns:
the name of the column
See Also:
TableModel.getColumnName(int)

getHierarchicalColumn

public int getHierarchicalColumn()
Returns the column that is the "tree" column. While it is not required, most implementations will default the first column to be the hierarchical one.

Specified by:
getHierarchicalColumn in interface TreeTableModel
Returns:
the index of the hierarchical column or -1 if no column is the hierarchical column.

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
Returns:
the root of the tree

isCellEditable

public boolean isCellEditable(Object node,
                              int column)
Returns true if the cell for the node at columnIndex is editable. Otherwise, setValueAt on the cell will not change the value of that cell. The node must be managed by this model. Unamanaged nodes should throw an IllegalArgumentException.

Specified by:
isCellEditable in interface TreeTableModel
Parameters:
node - the node whose value to be queried
column - the column whose value to be queried
Returns:
true if the cell is editable
See Also:
TreeTableModel.setValueAt(java.lang.Object, java.lang.Object, int), TableModel.isCellEditable(int, int)

isLeaf

public boolean isLeaf(Object node)
Returns true if node is a leaf.

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
impl
true if getChildCount(node) == 0

setValueAt

public void setValueAt(Object value,
                       Object node,
                       int column)
Sets the value for the node at columnIndex to value.

Specified by:
setValueAt in interface TreeTableModel
Parameters:
value - the new value
node - the node whose value is to be changed
column - the column whose value is to be changed
See Also:
TreeTableModel.getValueAt(java.lang.Object, int), isCellEditable(java.lang.Object, int), TableModel.setValueAt(Object, int, int)
impl
is no-op; provided for convenience for uneditable models

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
impl
is no-op. A JXTreeTable does not usually edit the node directly.

addTreeModelListener

public void addTreeModelListener(TreeModelListener l)
Adds a listener for the TreeModelEvent posted after the tree changes.

Specified by:
addTreeModelListener in interface TreeModel
Parameters:
l - the listener to add
See Also:
TreeModel.removeTreeModelListener(javax.swing.event.TreeModelListener)

removeTreeModelListener

public void removeTreeModelListener(TreeModelListener l)
Removes a listener previously added with addTreeModelListener.

Specified by:
removeTreeModelListener in interface TreeModel
Parameters:
l - the listener to remove
See Also:
TreeModel.addTreeModelListener(javax.swing.event.TreeModelListener)

getTreeModelListeners

public TreeModelListener[] getTreeModelListeners()
Returns an array of all the TreeModelListeners added to this JXTreeTable with addTreeModelListener().

Returns:
all of the TreeModelListeners added or an empty array if no listeners have been added