Package org.jdesktop.swingx.treetable
Class AbstractTreeTableModel
- java.lang.Object
-
- org.jdesktop.swingx.treetable.AbstractTreeTableModel
-
- All Implemented Interfaces:
javax.swing.tree.TreeModel,TreeTableModel
- Direct Known Subclasses:
DefaultTreeTableModel,FileSystemModel
public abstract class AbstractTreeTableModel extends java.lang.Object implements TreeTableModel
AbstractTreeTableModel provides an implementation ofTreeTableModelas a convenient starting point in defining custom data models forJXTreeTable. It takes care of listener management and contains convenience methods for creating and dispatchingTreeModelEvents. To create a concreate instance ofTreeTableModelyou 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
Fields Modifier and Type Field Description protected TreeModelSupportmodelSupportProvides support for event dispatching.protected java.lang.ObjectrootRoot node of the model
-
Constructor Summary
Constructors Constructor Description AbstractTreeTableModel()Constructs anAbstractTreeTableModelwith anullroot node.AbstractTreeTableModel(java.lang.Object root)Constructs anAbstractTreeTableModelwith the specified root node.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddTreeModelListener(javax.swing.event.TreeModelListener l)java.lang.Class<?>getColumnClass(int column)Returns the most specific superclass for all the cell values in the column.java.lang.StringgetColumnName(int column)Returns the name of the column atcolumnIndex.intgetHierarchicalColumn()Returns the column that is the "tree" column.java.lang.ObjectgetRoot()javax.swing.event.TreeModelListener[]getTreeModelListeners()Returns an array of all theTreeModelListeners added to this JXTreeTable with addTreeModelListener().booleanisCellEditable(java.lang.Object node, int column)Returns true if the cell for thenodeatcolumnIndexis editable.booleanisLeaf(java.lang.Object node)Returnstrueifnodeis a leaf.voidremoveTreeModelListener(javax.swing.event.TreeModelListener l)voidsetValueAt(java.lang.Object value, java.lang.Object node, int column)Sets the value for thenodeatcolumnIndextovalue.voidvalueForPathChanged(javax.swing.tree.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 javax.swing.tree.TreeModel
getChild, getChildCount, getIndexOfChild
-
Methods inherited from interface org.jdesktop.swingx.treetable.TreeTableModel
getColumnCount, getValueAt
-
-
-
-
Field Detail
-
root
protected java.lang.Object root
Root node of the model
-
modelSupport
protected TreeModelSupport modelSupport
Provides support for event dispatching.
-
-
Constructor Detail
-
AbstractTreeTableModel
public AbstractTreeTableModel()
Constructs anAbstractTreeTableModelwith anullroot node.
-
AbstractTreeTableModel
public AbstractTreeTableModel(java.lang.Object root)
Constructs anAbstractTreeTableModelwith the specified root node.- Parameters:
root- root node
-
-
Method Detail
-
getColumnClass
public java.lang.Class<?> getColumnClass(int column)
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:
TableModel.getColumnClass(int)
-
getColumnName
public java.lang.String getColumnName(int column)
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:
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:
getHierarchicalColumnin interfaceTreeTableModel- Returns:
- the index of the hierarchical column or -1 if no column is the hierarchical column.
-
getRoot
public java.lang.Object getRoot()
- Specified by:
getRootin interfacejavax.swing.tree.TreeModel
-
isCellEditable
public boolean isCellEditable(java.lang.Object node, int column)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:
TreeTableModel.setValueAt(java.lang.Object, java.lang.Object, int),TableModel.isCellEditable(int, int)
-
isLeaf
public boolean isLeaf(java.lang.Object node)
Returnstrueifnodeis a leaf.- Specified by:
isLeafin interfacejavax.swing.tree.TreeModel- Parameters:
node- a node in the tree, obtained from this data source- Returns:
- true if
nodeis a leaf
-
setValueAt
public void setValueAt(java.lang.Object value, java.lang.Object node, int column)Sets the value for thenodeatcolumnIndextovalue.- 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:
TreeTableModel.getValueAt(java.lang.Object, int),isCellEditable(java.lang.Object, int),TableModel.setValueAt(Object, int, int)
-
valueForPathChanged
public void valueForPathChanged(javax.swing.tree.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 atreeNodesChangedevent.- Specified by:
valueForPathChangedin interfacejavax.swing.tree.TreeModel- Parameters:
path- path to the node that has changednewValue- the new value from theTreeCellEditor
-
addTreeModelListener
public void addTreeModelListener(javax.swing.event.TreeModelListener l)
- Specified by:
addTreeModelListenerin interfacejavax.swing.tree.TreeModel
-
removeTreeModelListener
public void removeTreeModelListener(javax.swing.event.TreeModelListener l)
- Specified by:
removeTreeModelListenerin interfacejavax.swing.tree.TreeModel
-
getTreeModelListeners
public javax.swing.event.TreeModelListener[] 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
-
-