Class FileTreeModel

java.lang.Object
com.codename1.components.FileTreeModel
All Implemented Interfaces:
TreeModel

public class FileTreeModel extends Object implements TreeModel
A tree model representing the file system as a whole, notice that this class returns absolute file names which would result in an unreadable tree. To fix this you can create a Tree object and override functionality such as the childToDisplayLabel method like this: Tree fileTree = new Tree(new FileTreeModel(true)) { protected String childToDisplayLabel(Object child) { if (((String) child).endsWith("/")) { return ((String) child).substring(((String) child).lastIndexOf('/', ((String) child).length() - 2)); } return ((String) child).substring(((String) child).lastIndexOf('/')); } };
  • Constructor Details

    • FileTreeModel

      public FileTreeModel(boolean showFiles)

      Construct a filesystem tree model

      Parameters
      • showFiles: indicates whether this is a directory only view or a whole filesystem view
  • Method Details

    • addExtensionFilter

      public void addExtensionFilter(String extension)

      Shows only files with the given extension

      Parameters
      • extension: the file extension to display
    • getChildren

      public Vector getChildren(Object parent)

      Returns the child objects representing the given parent, null should return the root objects

      Parameters
      • parent: @param parent the parent object whose children should be returned, null would return the tree roots
      Returns

      the children of the given node within the tree

      Specified by:
      getChildren in interface TreeModel
    • isLeaf

      public boolean isLeaf(Object node)

      Is the node a leaf or a folder

      Parameters
      • node: a node within the tree
      Returns

      true if the node is a leaf that can't be expanded

      Specified by:
      isLeaf in interface TreeModel