public class DefaultTreeTableModel extends AbstractTreeTableModel
DefaultTreeTableModel
is a concrete implementation of
AbstractTreeTableModel
and is provided purely as a convenience for
use with TreeTableNode
s. Applications that use JXTreeTable
without TreeTableNode
s are expected to provide their own
implementation of a TreeTableModel
.
The DefaultTreeTableModel
is designed to be used with
TreeTableNode
s. 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.
Modifier and Type | Field and Description |
---|---|
protected List<?> |
columnIdentifiers
The
List of column identifiers. |
private boolean |
useAutoCalculatedIdentifiers |
modelSupport, root
Constructor and Description |
---|
DefaultTreeTableModel()
Creates a new
DefaultTreeTableModel with a null root. |
DefaultTreeTableModel(TreeTableNode root)
Creates a new
DefaultTreeTableModel with the specified
root . |
DefaultTreeTableModel(TreeTableNode root,
List<?> columnNames)
Creates a new
DefaultTreeTableModel with the specified root and column names. |
Modifier and Type | Method and Description |
---|---|
private static List<String> |
getAutoCalculatedIdentifiers(TreeTableNode exemplar) |
Object |
getChild(Object parent,
int index) |
int |
getChildCount(Object parent) |
int |
getColumnCount()
Returns the number of columns in the model.
|
String |
getColumnName(int column)
Returns the name of the column at
columnIndex . |
int |
getIndexOfChild(Object parent,
Object child) |
TreeTableNode[] |
getPathToRoot(TreeTableNode aNode)
Gets the path from the root to the specified node.
|
TreeTableNode |
getRoot()
Returns the root of the tree.
|
Object |
getValueAt(Object node,
int column)
Gets the value for the
node at column . |
void |
insertNodeInto(MutableTreeTableNode newChild,
MutableTreeTableNode parent,
int index)
Invoked this to insert newChild at location index in parents children.
|
boolean |
isCellEditable(Object node,
int column)
Returns true if the cell for the
node at columnIndex is
editable. |
boolean |
isLeaf(Object node)
Returns
true if node is a leaf. |
private boolean |
isValidTreeTableNode(Object node) |
void |
removeNodeFromParent(MutableTreeTableNode node)
Message this to remove node from its parent.
|
void |
setColumnIdentifiers(List<?> columnIdentifiers)
Replaces the column identifiers in the model.
|
void |
setRoot(TreeTableNode root)
Sets the root for this table model.
|
void |
setUserObject(TreeTableNode node,
Object userObject)
Sets the user object for a node.
|
void |
setValueAt(Object value,
Object node,
int column)
Sets the value for the
node at columnIndex to
value . |
void |
valueForPathChanged(TreePath path,
Object newValue)
Called when value for the item identified by path has been changed.
|
addTreeModelListener, getColumnClass, getHierarchicalColumn, getTreeModelListeners, removeTreeModelListener
protected List<?> columnIdentifiers
List
of column identifiers.private boolean useAutoCalculatedIdentifiers
public DefaultTreeTableModel()
DefaultTreeTableModel
with a null
root.public DefaultTreeTableModel(TreeTableNode root)
DefaultTreeTableModel
with the specified
root
.root
- the root node of the treepublic DefaultTreeTableModel(TreeTableNode root, List<?> columnNames)
DefaultTreeTableModel
with the specified root
and column names.root
- the root node of the treecolumnNames
- the names of the columns used by this modelsetColumnIdentifiers(List)
private boolean isValidTreeTableNode(Object node)
public void setColumnIdentifiers(List<?> columnIdentifiers)
newIdentifier
s is greater than the current number of
columns, new columns are added to the end of each row in the model. If
the number of newIdentifier
s is less than the current
number of columns, all the extra columns at the end of a row are
discarded.
columnIdentifiers
- vector of column identifiers. If null
, set the
model to zero columnsprivate static List<String> getAutoCalculatedIdentifiers(TreeTableNode exemplar)
public TreeTableNode getRoot()
null
only if the tree has
no nodes.getRoot
in interface TreeModel
getRoot
in class AbstractTreeTableModel
ClassCastException
- if root
is not a TreeTableNode
. Even though
subclasses have direct access to root
, they should
avoid accessing it directly.AbstractTreeTableModel.root
,
setRoot(TreeTableNode)
public Object getValueAt(Object node, int column)
node
at column
.node
- the node whose value is to be queriedcolumn
- the column whose value is to be queriedIllegalArgumentException
- if node
is not an instance of TreeTableNode
or is not managed by this model, or column
is not a
valid column indexTreeTableModel.setValueAt(java.lang.Object, java.lang.Object, int)
,
TableModel.getValueAt(int, int)
public void setValueAt(Object value, Object node, int column)
node
at columnIndex
to
value
.setValueAt
in interface TreeTableModel
setValueAt
in class AbstractTreeTableModel
value
- the new valuenode
- the node whose value is to be changedcolumn
- the column whose value is to be changedTreeTableModel.getValueAt(java.lang.Object, int)
,
AbstractTreeTableModel.isCellEditable(java.lang.Object, int)
,
TableModel.setValueAt(Object, int, int)
public int getColumnCount()
JXTreeTable
uses
this method to determine how many columns it should create and display by
default.TableModel.getColumnCount()
public String getColumnName(int column)
columnIndex
. 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.getColumnName
in interface TreeTableModel
getColumnName
in class AbstractTreeTableModel
column
- the index of the columnTableModel.getColumnName(int)
public int getChildCount(Object parent)
public int getIndexOfChild(Object parent, Object child)
public boolean isCellEditable(Object node, int column)
node
at columnIndex
is
editable. Otherwise, setValueAt
on the cell will not change the
value of that cell. The node
must be managed by this model.
Unamanaged nodes should throw an IllegalArgumentException
.isCellEditable
in interface TreeTableModel
isCellEditable
in class AbstractTreeTableModel
node
- the node whose value to be queriedcolumn
- the column whose value to be queriedTreeTableModel.setValueAt(java.lang.Object, java.lang.Object, int)
,
TableModel.isCellEditable(int, int)
public boolean isLeaf(Object node)
true
if node
is a leaf.isLeaf
in interface TreeModel
isLeaf
in class AbstractTreeTableModel
node
- a node in the tree, obtained from this data sourcenode
is a leafpublic TreeTableNode[] getPathToRoot(TreeTableNode aNode)
aNode
- the node to queryTreeTableNode
s, where
arr[0].equals(getRoot())
and
arr[arr.length - 1].equals(aNode)
, or an empty array if
the node is not found.NullPointerException
- if aNode
is null
public void setRoot(TreeTableNode root)
root
as
an examplar of the table.root
- the node to set as rootpublic void insertNodeInto(MutableTreeTableNode newChild, MutableTreeTableNode parent, int index)
public void removeNodeFromParent(MutableTreeTableNode node)
public void valueForPathChanged(TreePath path, Object newValue)
treeNodesChanged
event.
This changes the object backing the TreeTableNode
described 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.
valueForPathChanged
in interface TreeModel
valueForPathChanged
in class AbstractTreeTableModel
path
- path to the node that has changednewValue
- the new valueNullPointerException
- if path
is null
IllegalArgumentException
- if path
is not a path managed by this modelClassCastException
- if path.getLastPathComponent()
is not a TreeTableNode
public void setUserObject(TreeTableNode node, Object userObject)
This method is a convenient cover for
valueForPathChanged(TreePath, Object)
.
node
- the node to modifyuserObject
- the new user object to setNullPointerException
- if node
is null
IllegalArgumentException
- if node
is not a node managed by this modelWebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses