Package org.jdesktop.swingx.treetable
Class FileSystemModel
java.lang.Object
org.jdesktop.swingx.treetable.AbstractTreeTableModel
org.jdesktop.swingx.treetable.FileSystemModel
- All Implemented Interfaces:
TreeModel,TreeTableModel
A tree table model to simulate a file system.
This tree table model implementation extends AbstractTreeTableModel.
The file system metaphor demonstrates that it is often easier to directly
implement tree structures directly instead of using intermediaries, such as
TreeTableNode.
A comparison of this class with SimpleFileSystemModel, shows that
extending AbstractTreeTableModel is often easier than creating a model
from scratch.
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 inherited from class org.jdesktop.swingx.treetable.AbstractTreeTableModel
modelSupport, root -
Constructor Summary
ConstructorsConstructorDescriptionCreates a file system model using the root directory as the model root.FileSystemModel(File root) Creates a file system model using the specifiedroot. -
Method Summary
Modifier and TypeMethodDescriptionintgetChildCount(Object parent) Class<?>getColumnClass(int column) Returns the most specific superclass for all the cell values in the column.intReturns the number of columns in the model.getColumnName(int column) Returns the name of the column atcolumnIndex.intgetIndexOfChild(Object parent, Object child) getRoot()getValueAt(Object node, int column) Returns the value for thenodeatcolumnIndex.booleanReturnstrueifnodeis a leaf.voidSets the root for this tree table model.Methods inherited from class org.jdesktop.swingx.treetable.AbstractTreeTableModel
addTreeModelListener, getHierarchicalColumn, getTreeModelListeners, isCellEditable, removeTreeModelListener, setValueAt, valueForPathChanged
-
Constructor Details
-
FileSystemModel
public FileSystemModel()Creates a file system model using the root directory as the model root. -
FileSystemModel
Creates a file system model using the specifiedroot.- Parameters:
root- the root for this model; this may be different than the root directory for a file system.
-
-
Method Details
-
getChild
-
getChildCount
-
getColumnClass
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- Overrides:
getColumnClassin classAbstractTreeTableModel- 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()Description copied from interface:TreeTableModelReturns 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
Description copied from class:AbstractTreeTableModelReturns 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:
-
getValueAt
Description copied from interface:TreeTableModelReturns the value for thenodeatcolumnIndex. Thenodemust be managed by this model. Unamanaged nodes should throw anIllegalArgumentException.- 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:
-
getIndexOfChild
-
getRoot
- Specified by:
getRootin interfaceTreeModel- Overrides:
getRootin classAbstractTreeTableModel
-
setRoot
Sets the root for this tree table model. This method will notify listeners that a change has taken place.- Parameters:
root- the new root node to set
-
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
-