Class FileSystemModel

  • All Implemented Interfaces:
    TreeModel, TreeTableModel

    public class FileSystemModel
    extends AbstractTreeTableModel
    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
    • Constructor Detail

      • FileSystemModel

        public FileSystemModel()
        Creates a file system model using the root directory as the model root.
      • FileSystemModel

        public FileSystemModel​(File root)
        Creates a file system model using the specified root.
        Parameters:
        root - the root for this model; this may be different than the root directory for a file system.
    • Method Detail

      • getChild

        public File getChild​(Object parent,
                             int index)
      • getChildCount

        public int getChildCount​(Object parent)
      • getColumnClass

        public Class<?> getColumnClass​(int column)
        Returns the most specific superclass for all the cell values in the column. This is used by the JXTreeTable to set up a default renderer and editor for the column.
        Specified by:
        getColumnClass in interface TreeTableModel
        Overrides:
        getColumnClass in class AbstractTreeTableModel
        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()
        Description copied from interface: TreeTableModel
        Returns the number of columns in the model. A JXTreeTable uses 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()
      • getIndexOfChild

        public int getIndexOfChild​(Object parent,
                                   Object child)
      • setRoot

        public void setRoot​(File root)
        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

        public boolean isLeaf​(Object node)
        Returns true if node is a leaf.
        Specified by:
        isLeaf in interface TreeModel
        Overrides:
        isLeaf in class AbstractTreeTableModel
        Parameters:
        node - a node in the tree, obtained from this data source
        Returns:
        true if node is a leaf