Package org.jdesktop.swingx.treetable
Class AbstractTreeTableModel
java.lang.Object
org.jdesktop.swingx.treetable.AbstractTreeTableModel
- All Implemented Interfaces:
TreeModel
,TreeTableModel
- Direct Known Subclasses:
DefaultTreeTableModel
,FileSystemModel
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
TreeModelEvent
s. 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);
- Author:
- Ramesh Gupta, Karl Schaefer
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected TreeModelSupport
Provides support for event dispatching.protected Object
Root node of the model -
Constructor Summary
ConstructorsConstructorDescriptionConstructs anAbstractTreeTableModel
with anull
root node.AbstractTreeTableModel
(Object root) Constructs anAbstractTreeTableModel
with the specified root node. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Class<?>
getColumnClass
(int column) Returns the most specific superclass for all the cell values in the column.getColumnName
(int column) Returns the name of the column atcolumnIndex
.int
Returns the column that is the "tree" column.getRoot()
Returns an array of all theTreeModelListener
s added to this JXTreeTable with addTreeModelListener().boolean
isCellEditable
(Object node, int column) Returns true if the cell for thenode
atcolumnIndex
is editable.boolean
Returnstrue
ifnode
is a leaf.void
void
setValueAt
(Object value, Object node, int column) Sets the value for thenode
atcolumnIndex
tovalue
.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 javax.swing.tree.TreeModel
getChild, getChildCount, getIndexOfChild
Methods inherited from interface org.jdesktop.swingx.treetable.TreeTableModel
getColumnCount, getValueAt
-
Field Details
-
root
Root node of the model -
modelSupport
Provides support for event dispatching.
-
-
Constructor Details
-
AbstractTreeTableModel
public AbstractTreeTableModel()Constructs anAbstractTreeTableModel
with anull
root node. -
AbstractTreeTableModel
Constructs anAbstractTreeTableModel
with the specified root node.- Parameters:
root
- root node
-
-
Method Details
-
getColumnClass
Returns the most specific superclass for all the cell values in the column. This is used by theJXTreeTable
to set up a default renderer and editor for the column.- Specified by:
getColumnClass
in interfaceTreeTableModel
- Parameters:
column
- the index of the column- Returns:
- the common ancestor class of the object values in the model.
- See Also:
-
getColumnName
Returns the name of the column atcolumnIndex
. 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 interfaceTreeTableModel
- Parameters:
column
- the index of the column- Returns:
- the name of the column
- See Also:
-
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 interfaceTreeTableModel
- Returns:
- the index of the hierarchical column or -1 if no column is the hierarchical column.
-
getRoot
-
isCellEditable
Returns true if the cell for thenode
atcolumnIndex
is editable. Otherwise,setValueAt
on the cell will not change the value of that cell. Thenode
must be managed by this model. Unamanaged nodes should throw anIllegalArgumentException
.- Specified by:
isCellEditable
in interfaceTreeTableModel
- Parameters:
node
- the node whose value to be queriedcolumn
- the column whose value to be queried- Returns:
- true if the cell is editable
- See Also:
-
isLeaf
Returnstrue
ifnode
is a leaf. -
setValueAt
Sets the value for thenode
atcolumnIndex
tovalue
.is no-op; provided for convenience for uneditable models
- Specified by:
setValueAt
in interfaceTreeTableModel
- Parameters:
value
- the new valuenode
- the node whose value is to be changedcolumn
- the column whose value is to be changed- See Also:
-
valueForPathChanged
Called when value for the item identified by path has been changed. If newValue signifies a truly new value the model should post atreeNodesChanged
event.impl is no-op. A
JXTreeTable
does not usually edit the node directly.- Specified by:
valueForPathChanged
in interfaceTreeModel
- Parameters:
path
- path to the node that has changednewValue
- the new value from theTreeCellEditor
-
addTreeModelListener
- Specified by:
addTreeModelListener
in interfaceTreeModel
-
removeTreeModelListener
- Specified by:
removeTreeModelListener
in interfaceTreeModel
-
getTreeModelListeners
Returns an array of all theTreeModelListener
s added to this JXTreeTable with addTreeModelListener().- Returns:
- all of the
TreeModelListener
s added or an empty array if no listeners have been added
-