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
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);
- Author:
- Ramesh Gupta, Karl Schaefer
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected TreeModelSupportProvides support for event dispatching.protected ObjectRoot node of the model -
Constructor Summary
ConstructorsConstructorDescriptionConstructs anAbstractTreeTableModelwith anullroot node.AbstractTreeTableModel(Object root) Constructs anAbstractTreeTableModelwith the specified root node. -
Method Summary
Modifier and TypeMethodDescriptionvoidClass<?>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.intReturns the column that is the "tree" column.getRoot()Returns an array of all theTreeModelListeners added to this JXTreeTable with addTreeModelListener().booleanisCellEditable(Object node, int column) Returns true if the cell for thenodeatcolumnIndexis editable.booleanReturnstrueifnodeis a leaf.voidvoidsetValueAt(Object value, Object node, int column) Sets the value for thenodeatcolumnIndextovalue.voidvalueForPathChanged(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, waitMethods inherited from interface javax.swing.tree.TreeModel
getChild, getChildCount, getIndexOfChildMethods 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 anAbstractTreeTableModelwith anullroot node. -
AbstractTreeTableModel
Constructs anAbstractTreeTableModelwith 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 theJXTreeTableto set up a default renderer and editor for the column.- Specified by:
getColumnClassin 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:
getColumnNamein 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:
getHierarchicalColumnin 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 thenodeatcolumnIndexis editable. Otherwise,setValueAton the cell will not change the value of that cell. Thenodemust be managed by this model. Unamanaged nodes should throw anIllegalArgumentException.- Specified by:
isCellEditablein 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
Returnstrueifnodeis a leaf. -
setValueAt
Sets the value for thenodeatcolumnIndextovalue.is no-op; provided for convenience for uneditable models
- Specified by:
setValueAtin 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 atreeNodesChangedevent.impl is no-op. A
JXTreeTabledoes not usually edit the node directly.- Specified by:
valueForPathChangedin interfaceTreeModel- Parameters:
path- path to the node that has changednewValue- the new value from theTreeCellEditor
-
addTreeModelListener
- Specified by:
addTreeModelListenerin interfaceTreeModel
-
removeTreeModelListener
- Specified by:
removeTreeModelListenerin interfaceTreeModel
-
getTreeModelListeners
Returns an array of all theTreeModelListeners added to this JXTreeTable with addTreeModelListener().- Returns:
- all of the
TreeModelListeners added or an empty array if no listeners have been added
-