Package org.jdesktop.swingx.treetable
Class SimpleFileSystemModel
java.lang.Object
org.jdesktop.swingx.treetable.SimpleFileSystemModel
- All Implemented Interfaces:
TreeModel
,TreeTableModel
A tree table model to simulate a file system.
This tree table model implementation does not extends
AbstractTreeTableModel
. The file system metaphor demonstrates that
it is often easier to directly implement tree structures directly instead of
using intermediaries, such as TreeNode
.
It would be possible to create this same class by extending
AbstractTreeTableModel
, however the number of methods that you would
need to override almost precludes that means of implementation.
A "full" version of this model might allow editing of file names, the deletion of files, and the movement of files. This simple implementation does not intend to tackle such problems, but this implementation may be extended to handle such details.
- Author:
- Ramesh Gupta, Karl Schaefer
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a file system model, using the root directory as the model root.SimpleFileSystemModel
(File root) Creates a file system model, using the specifiedroot
as the model root. -
Method Summary
Modifier and TypeMethodDescriptionvoid
int
getChildCount
(Object parent) Class<?>
getColumnClass
(int column) Returns the most specific superclass for all the cell values in the column.int
Returns the number of columns in the model.getColumnName
(int column) Returns the name of the column atcolumnIndex
.int
Returns the column that is the "tree" column.int
getIndexOfChild
(Object parent, Object child) getRoot()
Gets a an array of all the listeners attached to this model.getValueAt
(Object node, int column) Returns the value for thenode
atcolumnIndex
.boolean
isCellEditable
(Object node, int column) Returns true if the cell for thenode
atcolumnIndex
is editable.boolean
void
void
setValueAt
(Object value, Object node, int column) Sets the value for thenode
atcolumnIndex
tovalue
.void
valueForPathChanged
(TreePath path, Object newValue)
-
Field Details
-
listenerList
-
-
Constructor Details
-
SimpleFileSystemModel
public SimpleFileSystemModel()Creates a file system model, using the root directory as the model root. -
SimpleFileSystemModel
Creates a file system model, using the specifiedroot
as the model root.
-
-
Method Details
-
getChild
-
getChildCount
- Specified by:
getChildCount
in interfaceTreeModel
-
getColumnClass
Returns the most specific superclass for all the cell values in the column. This is used by theJXTreeTable
to set up a default renderer and editor for the column.- Specified by:
getColumnClass
in interfaceTreeTableModel
- Parameters:
column
- the index of the column- Returns:
- the common ancestor class of the object values in the model.
- See Also:
-
getColumnCount
public int getColumnCount()Returns the number of columns in the model. AJXTreeTable
uses this method to determine how many columns it should create and display by default.- Specified by:
getColumnCount
in interfaceTreeTableModel
- 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:
getColumnName
in interfaceTreeTableModel
- Parameters:
column
- the index of the column- Returns:
- the name of the column
- See Also:
-
getValueAt
Returns the value for thenode
atcolumnIndex
. Thenode
must be managed by this model. Unamanaged nodes should throw anIllegalArgumentException
.- Specified by:
getValueAt
in interfaceTreeTableModel
- 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
- 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:
getHierarchicalColumn
in interfaceTreeTableModel
- Returns:
- the index of the hierarchical column or -1 if no column is the hierarchical column.
-
isCellEditable
Returns true if the cell for thenode
atcolumnIndex
is editable. Otherwise,setValueAt
on the cell will not change the value of that cell. Thenode
must be managed by this model. Unamanaged nodes should throw anIllegalArgumentException
.- Specified by:
isCellEditable
in 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:
-
setValueAt
Sets the value for thenode
atcolumnIndex
tovalue
. Thenode
must be managed by this model. Unamanaged nodes should throw anIllegalArgumentException
.- Specified by:
setValueAt
in interfaceTreeTableModel
- Parameters:
value
- the new valuenode
- the node whose value is to be changedcolumn
- the column whose value is to be changed- See Also:
-
addTreeModelListener
- Specified by:
addTreeModelListener
in interfaceTreeModel
-
getIndexOfChild
- Specified by:
getIndexOfChild
in interfaceTreeModel
-
getRoot
-
isLeaf
-
removeTreeModelListener
- Specified by:
removeTreeModelListener
in interfaceTreeModel
-
valueForPathChanged
- Specified by:
valueForPathChanged
in interfaceTreeModel
-
getTreeModelListeners
Gets a an array of all the listeners attached to this model.- Returns:
- an array of listeners; this array is guaranteed to be
non-
null
-