Class DefaultTreeTableModel
- All Implemented Interfaces:
TreeModel,TreeTableModel
DefaultTreeTableModel is a concrete implementation of
AbstractTreeTableModel and is provided purely as a convenience for
use with TreeTableNodes. Applications that use JXTreeTable
without TreeTableNodes are expected to provide their own
implementation of a TreeTableModel.
The DefaultTreeTableModel is designed to be used with
TreeTableNodes. Specifically, users should extend
AbstractMutableTreeTableNode to provide custom implementations for
data display.
Users who do not provide a list of column identifiers must provide a root that contains at least one column. Without specified identifiers the model will attempt to calculate the columns required for display by querying the root node. Normally, the root node can be little more than a shell (in displays that hide it), but without identifiers, the model relies on the root node metadata for display.
- Author:
- Ramesh Gupta, Karl Schaefer
-
Field Summary
FieldsFields inherited from class org.jdesktop.swingx.treetable.AbstractTreeTableModel
modelSupport, root -
Constructor Summary
ConstructorsConstructorDescriptionCreates a newDefaultTreeTableModelwith anullroot.Creates a newDefaultTreeTableModelwith the specifiedroot.DefaultTreeTableModel(TreeTableNode root, List<?> columnNames) Creates a newDefaultTreeTableModelwith the specifiedrootand column names. -
Method Summary
Modifier and TypeMethodDescriptionintgetChildCount(Object parent) intReturns the number of columns in the model.getColumnName(int column) Returns the name of the column atcolumnIndex.intgetIndexOfChild(Object parent, Object child) getPathToRoot(TreeTableNode aNode) Gets the path from the root to the specified node.getRoot()Returns the root of the tree.getValueAt(Object node, int column) Gets the value for thenodeatcolumn.voidinsertNodeInto(MutableTreeTableNode newChild, MutableTreeTableNode parent, int index) Invoked this to insert newChild at location index in parents children.booleanisCellEditable(Object node, int column) Returns true if the cell for thenodeatcolumnIndexis editable.booleanReturnstrueifnodeis a leaf.voidMessage this to remove node from its parent.voidsetColumnIdentifiers(List<?> columnIdentifiers) Replaces the column identifiers in the model.voidsetRoot(TreeTableNode root) Sets the root for this table model.voidsetUserObject(TreeTableNode node, Object userObject) Sets the user object for a node.voidsetValueAt(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 org.jdesktop.swingx.treetable.AbstractTreeTableModel
addTreeModelListener, getColumnClass, getHierarchicalColumn, getTreeModelListeners, removeTreeModelListener
-
Field Details
-
columnIdentifiers
TheListof column identifiers.
-
-
Constructor Details
-
DefaultTreeTableModel
public DefaultTreeTableModel()Creates a newDefaultTreeTableModelwith anullroot. -
DefaultTreeTableModel
Creates a newDefaultTreeTableModelwith the specifiedroot.- Parameters:
root- the root node of the tree
-
DefaultTreeTableModel
Creates a newDefaultTreeTableModelwith the specifiedrootand column names.- Parameters:
root- the root node of the treecolumnNames- the names of the columns used by this model- See Also:
-
-
Method Details
-
setColumnIdentifiers
Replaces the column identifiers in the model. If the number ofnewIdentifiers is greater than the current number of columns, new columns are added to the end of each row in the model. If the number ofnewIdentifiers is less than the current number of columns, all the extra columns at the end of a row are discarded.- Parameters:
columnIdentifiers- vector of column identifiers. Ifnull, set the model to zero columns
-
getRoot
Returns the root of the tree. Returnsnullonly if the tree has no nodes.- Specified by:
getRootin interfaceTreeModel- Overrides:
getRootin classAbstractTreeTableModel- Returns:
- the root of the tree
- Throws:
ClassCastException- ifrootis not aTreeTableNode. Even though subclasses have direct access toroot, they should avoid accessing it directly.- See Also:
-
getValueAt
Gets the value for thenodeatcolumn. Delegates toTreeTableNode.getValueAt(int)- Parameters:
node- the node whose value is to be queriedcolumn- the column whose value is to be queried- Returns:
- the value Object at the specified cell
- Throws:
IllegalArgumentException- ifnodeis not an instance ofTreeTableNodeor is not managed by this model, orcolumnis not a valid column index- See Also:
-
setValueAt
Sets the value for thenodeatcolumnIndextovalue.is no-op; provided for convenience for uneditable models
- Specified by:
setValueAtin interfaceTreeTableModel- Overrides:
setValueAtin classAbstractTreeTableModel- Parameters:
value- the new valuenode- the node whose value is to be changedcolumn- the column whose value is to be changed- See Also:
-
getColumnCount
public int getColumnCount()Returns the number of columns in the model. AJXTreeTableuses this method to determine how many columns it should create and display by default.- Returns:
- the number of columns 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- Overrides:
getColumnNamein classAbstractTreeTableModel- Parameters:
column- the index of the column- Returns:
- the name of the column
- See Also:
-
getChild
-
getChildCount
-
getIndexOfChild
-
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- Overrides:
isCellEditablein classAbstractTreeTableModel- 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.- Specified by:
isLeafin interfaceTreeModel- Overrides:
isLeafin classAbstractTreeTableModel- Parameters:
node- a node in the tree, obtained from this data source- Returns:
- true if
nodeis a leaf
-
getPathToRoot
Gets the path from the root to the specified node.- Parameters:
aNode- the node to query- Returns:
- an array of
TreeTableNodes, wherearr[0].equals(getRoot())andarr[arr.length - 1].equals(aNode), or an empty array if the node is not found. - Throws:
NullPointerException- ifaNodeisnull
-
setRoot
Sets the root for this table model. If no column identifiers have been specified, this will rebuild the identifier list, usingrootas an examplar of the table.- Parameters:
root- the node to set as root
-
insertNodeInto
Invoked this to insert newChild at location index in parents children. This will then message nodesWereInserted to create the appropriate event. This is the preferred way to add children as it will create the appropriate event.- Parameters:
newChild- MutableTreeTableNodeparent- MutableTreeTableNodeindex- TODO maven-javadoc-plugin 3.3.2 needs a doc here
-
removeNodeFromParent
Message this to remove node from its parent. This will message nodesWereRemoved to create the appropriate event. This is the preferred way to remove a node as it handles the event creation for you.- Parameters:
node- MutableTreeTableNode
-
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.This changes the object backing the
TreeTableNodedescribed by the path. This change does not alter a nodes children in any way. If you need to change structure of the node, use one of the provided mutator methods.- Specified by:
valueForPathChangedin interfaceTreeModel- Overrides:
valueForPathChangedin classAbstractTreeTableModel- Parameters:
path- path to the node that has changednewValue- the new value- Throws:
NullPointerException- ifpathisnullIllegalArgumentException- ifpathis not a path managed by this modelClassCastException- ifpath.getLastPathComponent()is not aTreeTableNode
-
setUserObject
Sets the user object for a node. Client code must use this method, so that the model can notify listeners that a change has occurred.This method is a convenient cover for
valueForPathChanged(TreePath, Object).- Parameters:
node- the node to modifyuserObject- the new user object to set- Throws:
NullPointerException- ifnodeisnullIllegalArgumentException- ifnodeis not a node managed by this model
-