public class FileTreeModel
- Object
- FileTreeModel
ImplementsTreeModel
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('/')); } };Constructors
public FileTreeModel(boolean showFiles) | Construct a filesystem tree model |
Methods
public void addExtensionFilter(String extension) | Shows only files with the given extension |
public Vector getChildren(Object parent) | Returns the child objects representing the given parent, null should return the root objects |
public boolean isLeaf(Object node) | Is the node a leaf or a folder |
Inherited methods
Constructor details
FileTreeModel
public FileTreeModel(boolean showFiles)Construct a filesystem tree model
Parameters
showFilesboolean- 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
extensionString- 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
parentObject- the parent object whose children should be returned, null would return the tree roots
Returns
the children of the given node within the tree
isLeaf
public boolean isLeaf(Object node)Is the node a leaf or a folder
Parameters
nodeObject- a node within the tree
Returns
true if the node is a leaf that can’t be expanded