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 Summary

    Constructors
    Constructor
    Description
    FileTreeModel(boolean showFiles)
    Construct a filesystem tree model
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Shows only files with the given extension
    Returns the child objects representing the given parent, null should return the root objects
    boolean
    isLeaf(Object node)
    Is the node a leaf or a folder

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    Modifier and Type
    Method
    Description
    protected Object
     
    boolean
    Indicates whether some other object is "equal to" this one.
    final Class
    Returns the runtime class of an object.
    int
    Returns a hash code value for the object.
    final void
    Wakes up a single thread that is waiting on this object's monitor.
    final void
    Wakes up all threads that are waiting on this object's monitor.
    Returns a string representation of the object.
    final void
    Causes current thread to wait until another thread invokes the method or the method for this object.
    final void
    wait(long timeout)
    Causes current thread to wait until either another thread invokes the method or the method for this object, or a specified amount of time has elapsed.
    final void
    wait(long timeout, int nanos)
    Causes current thread to wait until another thread invokes the method or the method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.
  • 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