Package org.jdesktop.swingx.treetable
Class SimpleFileSystemModel
- java.lang.Object
-
- org.jdesktop.swingx.treetable.SimpleFileSystemModel
-
- All Implemented Interfaces:
TreeModel,TreeTableModel
public class SimpleFileSystemModel extends Object implements 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 asTreeNode.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 Modifier and Type Field Description protected EventListenerListlistenerList
-
Constructor Summary
Constructors Constructor Description SimpleFileSystemModel()Creates a file system model, using the root directory as the model root.SimpleFileSystemModel(File root)Creates a file system model, using the specifiedrootas the model root.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddTreeModelListener(TreeModelListener l)FilegetChild(Object parent, int index)intgetChildCount(Object parent)Class<?>getColumnClass(int column)Returns the most specific superclass for all the cell values in the column.intgetColumnCount()Returns the number of columns in the model.StringgetColumnName(int column)Returns the name of the column atcolumnIndex.intgetHierarchicalColumn()Returns the column that is the "tree" column.intgetIndexOfChild(Object parent, Object child)FilegetRoot()TreeModelListener[]getTreeModelListeners()Gets a an array of all the listeners attached to this model.ObjectgetValueAt(Object node, int column)Returns the value for thenodeatcolumnIndex.booleanisCellEditable(Object node, int column)Returns true if the cell for thenodeatcolumnIndexis editable.booleanisLeaf(Object node)voidremoveTreeModelListener(TreeModelListener l)voidsetValueAt(Object value, Object node, int column)Sets the value for thenodeatcolumnIndextovalue.voidvalueForPathChanged(TreePath path, Object newValue)
-
-
-
Field Detail
-
listenerList
protected EventListenerList listenerList
-
-
Constructor Detail
-
SimpleFileSystemModel
public SimpleFileSystemModel()
Creates a file system model, using the root directory as the model root.
-
SimpleFileSystemModel
public SimpleFileSystemModel(File root)
Creates a file system model, using the specifiedrootas the model root.
-
-
Method Detail
-
getChildCount
public int getChildCount(Object parent)
- Specified by:
getChildCountin interfaceTreeModel
-
getColumnClass
public Class<?> getColumnClass(int column)
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- Parameters:
column- the index of the column- Returns:
- the common ancestor class of the object values in the model.
- See Also:
TableModel.getColumnClass(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.- Specified by:
getColumnCountin interfaceTreeTableModel- Returns:
- the number of columns in the model
- See Also:
TableModel.getColumnCount()
-
getColumnName
public 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- Parameters:
column- the index of the column- Returns:
- the name of the column
- See Also:
TableModel.getColumnName(int)
-
getValueAt
public Object getValueAt(Object node, int column)
Returns the value for thenodeatcolumnIndex. Thenodemust be managed by this model. Unamanaged nodes should throw anIllegalArgumentException.- Specified by:
getValueAtin 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:
TreeTableModel.setValueAt(java.lang.Object, java.lang.Object, int),TableModel.getValueAt(int, int)
-
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:
getHierarchicalColumnin interfaceTreeTableModel- Returns:
- the index of the hierarchical column or -1 if no column is the hierarchical column.
-
isCellEditable
public boolean isCellEditable(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- 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)
-
setValueAt
public void setValueAt(Object value, Object node, int column)
Sets the value for thenodeatcolumnIndextovalue. Thenodemust be managed by this model. Unamanaged nodes should throw anIllegalArgumentException.- Specified by:
setValueAtin interfaceTreeTableModel- 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),TreeTableModel.isCellEditable(java.lang.Object, int),TableModel.setValueAt(Object, int, int)
-
addTreeModelListener
public void addTreeModelListener(TreeModelListener l)
- Specified by:
addTreeModelListenerin interfaceTreeModel
-
getIndexOfChild
public int getIndexOfChild(Object parent, Object child)
- Specified by:
getIndexOfChildin interfaceTreeModel
-
removeTreeModelListener
public void removeTreeModelListener(TreeModelListener l)
- Specified by:
removeTreeModelListenerin interfaceTreeModel
-
valueForPathChanged
public void valueForPathChanged(TreePath path, Object newValue)
- Specified by:
valueForPathChangedin interfaceTreeModel
-
getTreeModelListeners
public TreeModelListener[] 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
-
-