edu.sdsc.grid.gui
Class JargonTreeModel

java.lang.Object
  extended by edu.sdsc.grid.gui.JargonTreeModel
All Implemented Interfaces:
javax.swing.tree.TreeModel

public class JargonTreeModel
extends java.lang.Object
implements javax.swing.tree.TreeModel

The class extends the default tree model to use GeneralFiles as the nodes of the tree. Optimization code was added to reduce the number of remote system calls made during the building, expanding or redrawing of the tree.

This class uses a non-thread-safe storage, to keep the javax.swing classes from constantly querying the filesystem for every refresh and change. All those network calls really hurt performance. Unfortunately, as this class is no longer thread safe, changes to the filesystem won't be displayed until the model is updated.

Since:
version 1.4
See Also:
JargonGui

Field Summary
static javax.swing.Icon FILE_ICON
          The icon displayed for file nodes, leaf nodes.
static javax.swing.Icon FOLDER_ICON
          The icon displayed for folder nodes, non-leaf nodes.
protected  javax.swing.event.EventListenerList listenerList
          The listeners
static java.lang.String TOP_LEVEL
          Top level name for trees with multiple GeneralFile roots.
 
Constructor Summary
JargonTreeModel(GeneralFile root)
          Starts the tree with this GeneralFile as the root node.
JargonTreeModel(GeneralFile[] roots)
          Starts the tree with a fake root node, TOP_LEVEL, with the roots as children to that root.
JargonTreeModel(GeneralFile[] roots, MetaDataCondition[] conditions)
          Starts the tree with a fake root node, TOP_LEVEL, with the roots as children to that root.
JargonTreeModel(GeneralFile[] roots, MetaDataCondition[] conditions, MetaDataSelect[] selects)
          Starts the tree with a fake root node, TOP_LEVEL, with the roots as children to that root.
JargonTreeModel(GeneralFile[] roots, MetaDataSelect[] selects)
          Starts the tree with a fake root node, TOP_LEVEL, with the roots as children to that root.
JargonTreeModel(GeneralFile root, MetaDataCondition[] conditions)
          Starts the tree with this GeneralFile as the root node.
JargonTreeModel(GeneralFile root, MetaDataCondition[] conditions, MetaDataSelect[] selects)
          Starts the tree with this GeneralFile as the root node.
JargonTreeModel(GeneralFile root, MetaDataSelect[] selects)
          Starts the tree with this GeneralFile as the root node.
 
Method Summary
 void addTreeModelListener(javax.swing.event.TreeModelListener listener)
          Adds a listener for the TreeModelEvent posted after the tree changes.
protected  void fireTreeStructureChanged(java.lang.Object oldRoot)
          The only event raised by this model is TreeStructureChanged with the root as path, i.e.
 java.lang.Object getChild(java.lang.Object parent, int index)
          Returns the child of parent at index in the parent's child array.
 int getChildCount(java.lang.Object parent)
          Returns the number of children of parent.
 int getIndexOfChild(java.lang.Object parent, java.lang.Object child)
          Returns the index of child in parent.
 MetaDataRecordList getMetaDataRecordList(java.lang.Object node)
          Returns the metadata query result associated with this node of the tree.
 java.lang.Object getRoot()
          Returns the root of the tree.
 boolean isLeaf(java.lang.Object node)
          Returns true if node is a leaf.
 void removeTreeModelListener(javax.swing.event.TreeModelListener l)
          Removes a listener previously added with addTreeModelListener().
 void setRoot(java.lang.Object newRoot)
          Change the root of the tree.
 boolean showMetaData()
          Returns if this treemodel will show metadata.
 void valueForPathChanged(javax.swing.tree.TreePath path, java.lang.Object newValue)
          Messaged when the user has altered the value for the item identified by path to newValue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TOP_LEVEL

public static java.lang.String TOP_LEVEL
Top level name for trees with multiple GeneralFile roots.


listenerList

protected javax.swing.event.EventListenerList listenerList
The listeners


FOLDER_ICON

public static javax.swing.Icon FOLDER_ICON
The icon displayed for folder nodes, non-leaf nodes.


FILE_ICON

public static javax.swing.Icon FILE_ICON
The icon displayed for file nodes, leaf nodes.

Constructor Detail

JargonTreeModel

public JargonTreeModel(GeneralFile root)
Starts the tree with this GeneralFile as the root node.


JargonTreeModel

public JargonTreeModel(GeneralFile[] roots)
Starts the tree with a fake root node, TOP_LEVEL, with the roots as children to that root.


JargonTreeModel

public JargonTreeModel(GeneralFile root,
                       MetaDataCondition[] conditions)
                throws java.io.IOException
Starts the tree with this GeneralFile as the root node. Only file nodes which fit the conditions will be displayed on the tree.

Throws:
java.io.IOException

JargonTreeModel

public JargonTreeModel(GeneralFile[] roots,
                       MetaDataCondition[] conditions)
                throws java.io.IOException
Starts the tree with a fake root node, TOP_LEVEL, with the roots as children to that root. Only file nodes which fit the conditions will be displayed on the tree.

Throws:
java.io.IOException

JargonTreeModel

public JargonTreeModel(GeneralFile root,
                       MetaDataSelect[] selects)
                throws java.io.IOException
Starts the tree with this GeneralFile as the root node. File nodes on the tree will list the metadata described by selects

Throws:
java.io.IOException

JargonTreeModel

public JargonTreeModel(GeneralFile[] roots,
                       MetaDataSelect[] selects)
                throws java.io.IOException
Starts the tree with a fake root node, TOP_LEVEL, with the roots as children to that root. File nodes on the tree will list the metadata described by selects

Throws:
java.io.IOException

JargonTreeModel

public JargonTreeModel(GeneralFile root,
                       MetaDataCondition[] conditions,
                       MetaDataSelect[] selects)
                throws java.io.IOException
Starts the tree with this GeneralFile as the root node. Only file nodes which fit the conditions will be displayed on the tree. File nodes on the tree will list the metadata described by selects

Throws:
java.io.IOException

JargonTreeModel

public JargonTreeModel(GeneralFile[] roots,
                       MetaDataCondition[] conditions,
                       MetaDataSelect[] selects)
                throws java.io.IOException
Starts the tree with a fake root node, TOP_LEVEL, with the roots as children to that root. Only file nodes which fit the conditions will be displayed on the tree. File nodes on the tree will list the metadata described by selects

Throws:
java.io.IOException
Method Detail

addTreeModelListener

public void addTreeModelListener(javax.swing.event.TreeModelListener listener)
Adds a listener for the TreeModelEvent posted after the tree changes.

Specified by:
addTreeModelListener in interface javax.swing.tree.TreeModel

fireTreeStructureChanged

protected void fireTreeStructureChanged(java.lang.Object oldRoot)
The only event raised by this model is TreeStructureChanged with the root as path, i.e. the whole tree has changed.


removeTreeModelListener

public void removeTreeModelListener(javax.swing.event.TreeModelListener l)
Removes a listener previously added with addTreeModelListener().

Specified by:
removeTreeModelListener in interface javax.swing.tree.TreeModel

setRoot

public void setRoot(java.lang.Object newRoot)
Change the root of the tree.

Throws:
java.lang.ClassCastException - if newRoot is not a GeneralFile
java.lang.NullPointerException - if newRoot is null

getRoot

public java.lang.Object getRoot()
Returns the root of the tree. Returns null only if the tree has no nodes.

Specified by:
getRoot in interface javax.swing.tree.TreeModel

getChild

public java.lang.Object getChild(java.lang.Object parent,
                                 int index)
Returns the child of parent at index in the parent's child array. Parent must be a node previously obtained from this data source. This should not return null if index is a valid index for parent (that is index >= 0 && index < getChildCount(parent)).

Specified by:
getChild in interface javax.swing.tree.TreeModel

getChildCount

public int getChildCount(java.lang.Object parent)
Returns the number of children of parent. Returns 0 if the node is a leaf or if it has no children. Parent must be a node previously obtained from this data source.

Specified by:
getChildCount in interface javax.swing.tree.TreeModel

getIndexOfChild

public int getIndexOfChild(java.lang.Object parent,
                           java.lang.Object child)
Returns the index of child in parent.

Specified by:
getIndexOfChild in interface javax.swing.tree.TreeModel

isLeaf

public boolean isLeaf(java.lang.Object node)
Returns true if node is a leaf. It is possible for this method to return false even if node has no children. A directory in a filesystem, for example, may contain no files; the node representing the directory is not a leaf, but it also has no children.

Specified by:
isLeaf in interface javax.swing.tree.TreeModel

valueForPathChanged

public void valueForPathChanged(javax.swing.tree.TreePath path,
                                java.lang.Object newValue)
Messaged when the user has altered the value for the item identified by path to newValue. If newValue signifies a truly new value the model should post a treeNodesChanged event.

Specified by:
valueForPathChanged in interface javax.swing.tree.TreeModel

getMetaDataRecordList

public MetaDataRecordList getMetaDataRecordList(java.lang.Object node)
Returns the metadata query result associated with this node of the tree. Or null if node has not been queried or does not exist.

See Also:
JargonTreeCellEditor.getTreeCellEditorComponent(javax.swing.JTree, java.lang.Object, boolean, boolean, boolean, int)

showMetaData

public boolean showMetaData()
Returns if this treemodel will show metadata.