|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object uk.ac.essex.common.io.tree.AbstractTreeTableModel uk.ac.essex.common.io.tree.FileSystemModel2
public class FileSystemModel2
FileSystemModel2 is a TreeTableModel
representing a hierarchical file
system.
This will recursively load all the children from the path it is created with. The loading is done with the method reloadChildren, and happens in another thread. The method isReloading can be invoked to check if there are active threads. The total size of all the files are also accumulated.
By default links are not descended. java.io.File does not have a way to distinguish links, so a file is assumed to be a link if its canonical path does not start with its parent path. This may not cover all cases, but works for the time being.
Reloading happens such that all the files of the directory are loaded and immediately available. The background thread then recursively loads all the files of each of those directories. When each directory has finished loading all its sub files they are attached and an event is generated in the event dispatching thread. A more ambitious approach would be to attach each set of directories as they are loaded and generate an event. Then, once all the direct descendants of the directory being reloaded have finished loading, it is resorted based on total size.
While you can invoke reloadChildren as many times as you want, care should be taken in doing this. You should not invoke reloadChildren on a node that is already being reloaded, or going to be reloaded (meaning its parent is reloading but it hasn't started reloading that directory yet). If this is done odd results may happen. FileSystemModel2 does not enforce any policy in this manner, and it is up to the user of FileSystemModel2 to ensure it doesn't happen.
Field Summary | |
---|---|
protected static java.lang.String[] |
cNames
|
protected static java.lang.Class[] |
cTypes
|
protected boolean |
descendLinks
Returns true if links are to be descended. |
protected static uk.ac.essex.common.io.tree.FileSystemModel2.FileNode[] |
EMPTY_CHILDREN
|
protected boolean |
isValid
True if the receiver is valid, once set to false all Threads loading files will stop. |
protected uk.ac.essex.common.io.tree.FileSystemModel2.FileNode |
reloadNode
Node currently being reloaded, this becomes somewhat muddy if reloading is happening in multiple threads. |
static java.lang.Integer |
ZERO
|
Fields inherited from class uk.ac.essex.common.io.tree.AbstractTreeTableModel |
---|
listenerList, root |
Constructor Summary | |
---|---|
FileSystemModel2()
Creates a uk.ac.essex.common.io.tree.FileSystemModel2 rooted at File.separator, which is usually the root of the file system. |
|
FileSystemModel2(java.lang.String rootPath)
Creates a uk.ac.essex.common.io.tree.FileSystemModel2 with the root being rootPath . |
Method Summary | |
---|---|
java.lang.Object |
getChild(java.lang.Object node,
int i)
Returns the child of node at index i . |
int |
getChildCount(java.lang.Object node)
Returns the number of children of node . |
protected java.lang.Object[] |
getChildren(java.lang.Object node)
|
java.lang.Class |
getColumnClass(int column)
Returns the class for the particular column. |
int |
getColumnCount()
Returns the number of columns. |
java.lang.String |
getColumnName(int column)
Returns the name for a particular column. |
boolean |
getDescendsLinks()
Returns true if links are to be automatically descended. |
protected java.io.File |
getFile(java.lang.Object node)
|
java.lang.Object |
getNodeLoading()
Returns the node being loaded. |
java.lang.String |
getPath(java.lang.Object node)
Returns the path node represents. |
javax.swing.tree.TreePath |
getPathLoading()
Returns the path to the node that is being loaded. |
protected static MergeSort |
getSizeSorter()
Returns a uk.ac.essex.common.io.tree.MergeSort that can sort on the totalSize of a FileNode. |
long |
getTotalSize(java.lang.Object node)
Returns the total size of the receiver. |
java.lang.Object |
getValueAt(java.lang.Object node,
int column)
Returns the value of the particular column. |
boolean |
isLeaf(java.lang.Object node)
Returns true if the passed in object represents a leaf, false otherwise. |
boolean |
isReloading()
Returns true if the receiver is loading any children. |
protected static void |
recycleSorter(MergeSort sorter)
Should be invoked when a uk.ac.essex.common.io.tree.MergeSort is no longer needed. |
void |
reloadChildren(java.lang.Object node)
Reloads the children of the specified node. |
void |
setDescendsLinks(boolean newValue)
If newValue is true, links are descended. |
void |
stopLoading()
Stops and waits for all threads to finish loading. |
Methods inherited from class uk.ac.essex.common.io.tree.AbstractTreeTableModel |
---|
addTreeModelListener, fireTreeNodesChanged, fireTreeNodesInserted, fireTreeNodesRemoved, fireTreeStructureChanged, getIndexOfChild, getRoot, isCellEditable, removeTreeModelListener, setValueAt, valueForPathChanged |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static java.lang.String[] cNames
protected static java.lang.Class[] cTypes
public static final java.lang.Integer ZERO
protected boolean isValid
protected uk.ac.essex.common.io.tree.FileSystemModel2.FileNode reloadNode
protected boolean descendLinks
protected static uk.ac.essex.common.io.tree.FileSystemModel2.FileNode[] EMPTY_CHILDREN
Constructor Detail |
---|
public FileSystemModel2()
reloadChildren
with the root to start loading.
public FileSystemModel2(java.lang.String rootPath)
rootPath
.
This does not load it, you should invoke
reloadChildren
with the root to start loading.
Method Detail |
---|
protected static MergeSort getSizeSorter()
protected static void recycleSorter(MergeSort sorter)
public int getChildCount(java.lang.Object node)
node
.
public java.lang.Object getChild(java.lang.Object node, int i)
node
at index i
.
public boolean isLeaf(java.lang.Object node)
isLeaf
in interface javax.swing.tree.TreeModel
isLeaf
in class AbstractTreeTableModel
public int getColumnCount()
public java.lang.String getColumnName(int column)
public java.lang.Class getColumnClass(int column)
getColumnClass
in interface TreeTableModel
getColumnClass
in class AbstractTreeTableModel
public java.lang.Object getValueAt(java.lang.Object node, int column)
public void reloadChildren(java.lang.Object node)
public void stopLoading()
public void setDescendsLinks(boolean newValue)
newValue
is true, links are descended. Odd results
may happen if you set this while other threads are loading.
public boolean getDescendsLinks()
public java.lang.String getPath(java.lang.Object node)
node
represents.
public long getTotalSize(java.lang.Object node)
public boolean isReloading()
public javax.swing.tree.TreePath getPathLoading()
public java.lang.Object getNodeLoading()
protected java.io.File getFile(java.lang.Object node)
protected java.lang.Object[] getChildren(java.lang.Object node)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |