Package org.jdesktop.swingx.treetable
Class DefaultTreeTableModel
- java.lang.Object
-
- org.jdesktop.swingx.treetable.AbstractTreeTableModel
-
- org.jdesktop.swingx.treetable.DefaultTreeTableModel
-
- All Implemented Interfaces:
javax.swing.tree.TreeModel,TreeTableModel
public class DefaultTreeTableModel extends AbstractTreeTableModel
DefaultTreeTableModelis a concrete implementation ofAbstractTreeTableModeland is provided purely as a convenience. Applications that useJXTreeTableare expected to provide their own implementation of aTreeTableModel.The
DefaultTreeTableModelis designed to be used withTreeTableNodes. Specifically, users should extendAbstractMutableTreeTableNodeto 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.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<?>columnIdentifiersTheListof column identifiers.-
Fields inherited from class org.jdesktop.swingx.treetable.AbstractTreeTableModel
modelSupport, root
-
-
Constructor Summary
Constructors Constructor Description DefaultTreeTableModel()Creates a newDefaultTreeTableModelwith anullroot.DefaultTreeTableModel(TreeTableNode root)Creates a newDefaultTreeTableModelwith the specifiedroot.DefaultTreeTableModel(TreeTableNode root, java.util.List<?> columnNames)Creates a newDefaultTreeTableModelwith the specifiedroot.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.ObjectgetChild(java.lang.Object parent, int index)intgetChildCount(java.lang.Object parent)intgetColumnCount()Returns the number of columns in the model.java.lang.StringgetColumnName(int column)Returns the name of the column atcolumnIndex.intgetIndexOfChild(java.lang.Object parent, java.lang.Object child)TreeTableNode[]getPathToRoot(TreeTableNode aNode)Gets the path from the root to the specified node.TreeTableNodegetRoot()Returns the root of the tree.java.lang.ObjectgetValueAt(java.lang.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(java.lang.Object node, int column)Returns true if the cell for thenodeatcolumnIndexis editable.booleanisLeaf(java.lang.Object node)Returnstrueifnodeis a leaf.voidremoveNodeFromParent(MutableTreeTableNode node)Message this to remove node from its parent.voidsetColumnIdentifiers(java.util.List<?> columnIdentifiers)Replaces the column identifiers in the model.voidsetRoot(TreeTableNode root)Sets the root for this table model.voidsetValueAt(java.lang.Object value, java.lang.Object node, int column)Sets the value for thenodeatcolumnIndextovalue.-
Methods inherited from class org.jdesktop.swingx.treetable.AbstractTreeTableModel
addTreeModelListener, getColumnClass, getHierarchicalColumn, getTreeModelListeners, removeTreeModelListener, valueForPathChanged
-
-
-
-
Constructor Detail
-
DefaultTreeTableModel
public DefaultTreeTableModel()
Creates a newDefaultTreeTableModelwith anullroot.
-
DefaultTreeTableModel
public DefaultTreeTableModel(TreeTableNode root)
Creates a newDefaultTreeTableModelwith the specifiedroot.asksAllowsChildrenis disabled andisLeafwill provide the same semantics asAbstractTreeTableModel.isLeaf.- Parameters:
root- the root node of the tree
-
DefaultTreeTableModel
public DefaultTreeTableModel(TreeTableNode root, java.util.List<?> columnNames)
Creates a newDefaultTreeTableModelwith the specifiedroot.asksAllowsChildrenis disabled andisLeafwill provide the same semantics asAbstractTreeTableModel.isLeaf.- Parameters:
root- the root node of the tree
-
-
Method Detail
-
setColumnIdentifiers
public void setColumnIdentifiers(java.util.List<?> columnIdentifiers)
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
public TreeTableNode getRoot()
Returns the root of the tree. Returnsnullonly if the tree has no nodes.- Specified by:
getRootin interfacejavax.swing.tree.TreeModel- Overrides:
getRootin classAbstractTreeTableModel- Returns:
- the root of the tree
- Throws:
java.lang.ClassCastException- ifrootis not aTreeTableNode. Even though subclasses have direct access toroot, they should avoid accessing it directly.- See Also:
AbstractTreeTableModel.root,setRoot(TreeTableNode)
-
getValueAt
public java.lang.Object getValueAt(java.lang.Object node, int column)Gets the value for thenodeatcolumn.- 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:
java.lang.IllegalArgumentException- ifnodeis not an instance ofTreeTableNodeor is not managed by this model, orcolumnis not a valid column index- See Also:
TreeTableModel.setValueAt(java.lang.Object, java.lang.Object, int),TableModel.getValueAt(int, int)
-
setValueAt
public void setValueAt(java.lang.Object value, java.lang.Object node, int column)Sets the value for thenodeatcolumnIndextovalue.- 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:
TreeTableModel.getValueAt(java.lang.Object, int),AbstractTreeTableModel.isCellEditable(java.lang.Object, int),TableModel.setValueAt(Object, int, int)
-
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:
TableModel.getColumnCount()
-
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- Overrides:
getColumnNamein classAbstractTreeTableModel- Parameters:
column- the index of the column- Returns:
- the name of the column
- See Also:
TableModel.getColumnName(int)
-
getChild
public java.lang.Object getChild(java.lang.Object parent, int index)
-
getChildCount
public int getChildCount(java.lang.Object parent)
-
getIndexOfChild
public int getIndexOfChild(java.lang.Object parent, java.lang.Object child)
-
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- 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:
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- Overrides:
isLeafin classAbstractTreeTableModel- Parameters:
node- a node in the tree, obtained from this data source- Returns:
- true if
nodeis a leaf
-
getPathToRoot
public TreeTableNode[] getPathToRoot(TreeTableNode aNode)
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:
java.lang.NullPointerException- ifaNodeisnull
-
setRoot
public void setRoot(TreeTableNode root)
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
public void insertNodeInto(MutableTreeTableNode newChild, MutableTreeTableNode parent, int index)
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.
-
removeNodeFromParent
public void removeNodeFromParent(MutableTreeTableNode node)
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.
-
-