org.peace_tools.data
Class DataSetTreeModel

java.lang.Object
  extended by org.peace_tools.data.DataSetTreeModel
All Implemented Interfaces:
javax.swing.tree.TreeModel, WorkspaceListener

public class DataSetTreeModel
extends java.lang.Object
implements javax.swing.tree.TreeModel, WorkspaceListener

A bridge class between a Workspace and a JTree. This class serves as a bridge between the in-memory representation of a Workspace (represented by the set of classes in the workspace package. This class enables reusing the data set hierarchy maintained by the Workspace object to display it in a JTree. In addition, this class also acts to monitor and update data set views.


Field Summary
private  java.util.ArrayList<javax.swing.event.TreeModelListener> treeModelListeners
          The list of tree mode listeners that were added to this tree model.
 
Constructor Summary
DataSetTreeModel()
          The default constructor.
 
Method Summary
 void addTreeModelListener(javax.swing.event.TreeModelListener tml)
          Adds a listener to be notified when the data associated with the data set changes.
protected  void fireTreeStructureChanged(java.lang.Object oldRoot)
          The only event raised by this model is TreeStructureChanged with the appropriate entry to be
 java.lang.Object getChild(java.lang.Object parent, int index)
          This method provides the actual child object to be displayed in a JTree depending on the data in the Workspace.
 int getChildCount(java.lang.Object parent)
          This method provides the child count depending on the data in the Workspace.
 int getIndexOfChild(java.lang.Object parent, java.lang.Object child)
          This method provides the zero-based logical index of a child node.
 javax.swing.tree.TreePath getPath(java.lang.Object entry)
          This is a helper method to determine path to a given entry.
 java.lang.Object getRoot()
          Obtain the root of the data set tree.
 boolean isLeaf(java.lang.Object entry)
          Method to determine if a given entry is a leaf object.
 void removeTreeModelListener(javax.swing.event.TreeModelListener tml)
          Removes a listener from the list of listeners maintained by this class.
 void valueForPathChanged(javax.swing.tree.TreePath arg0, java.lang.Object arg1)
          This data model is meant to be used with a read-only type JTree.
 void workspaceChanged(WorkspaceEvent event)
          This method is invoked on all workspace listeners registered with the current Workspace.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

treeModelListeners

private java.util.ArrayList<javax.swing.event.TreeModelListener> treeModelListeners
The list of tree mode listeners that were added to this tree model. This list is used to notify listeners that the tree has changed.

Constructor Detail

DataSetTreeModel

public DataSetTreeModel()
The default constructor. The constructor registers this object with the work space to receive notifications on Job status updates.

Method Detail

addTreeModelListener

public void addTreeModelListener(javax.swing.event.TreeModelListener tml)
Adds a listener to be notified when the data associated with the data set changes.

Specified by:
addTreeModelListener in interface javax.swing.tree.TreeModel
Parameters:
tml - The listener to be added to the list of listeners to be notified when the data associated with the workspace changes.

removeTreeModelListener

public void removeTreeModelListener(javax.swing.event.TreeModelListener tml)
Removes a listener from the list of listeners maintained by this class.

Specified by:
removeTreeModelListener in interface javax.swing.tree.TreeModel
Parameters:
tml - The listener to be removed from the list of listeners to receive updates.

getChild

public java.lang.Object getChild(java.lang.Object parent,
                                 int index)
This method provides the actual child object to be displayed in a JTree depending on the data in the Workspace. Specifically this method returns the following object depending on the data type of parent:

Specified by:
getChild in interface javax.swing.tree.TreeModel
Parameters:
parent - The object whose child is to be returned.
index - The index of the child to be returned by this method.
See Also:
TreeModel.getChildCount(java.lang.Object)

getChildCount

public int getChildCount(java.lang.Object parent)
This method provides the child count depending on the data in the Workspace. Specifically this method returns the following child counts depending on the data type of parent:

Specified by:
getChildCount in interface javax.swing.tree.TreeModel
Parameters:
parent - The object whose child counts is to be determined.
See Also:
TreeModel.getChildCount(java.lang.Object)

getIndexOfChild

public int getIndexOfChild(java.lang.Object parent,
                           java.lang.Object child)
This method provides the zero-based logical index of a child node. The child node must have been obtained through a prior call to the getChild() method in this class. Specifically this method returns the following child counts depending on the data type of parent:

Specified by:
getIndexOfChild in interface javax.swing.tree.TreeModel
Parameters:
parent - The object whose child counts is to be determined.
See Also:
TreeModel.getChildCount(java.lang.Object)

getRoot

public java.lang.Object getRoot()
Obtain the root of the data set tree. The workspace entry is simply used as the root of the JTree tree.

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

isLeaf

public boolean isLeaf(java.lang.Object entry)
Method to determine if a given entry is a leaf object. This method returns false, if the entry is a Workspace or a DataSet. In all other cases, it returns true.

Specified by:
isLeaf in interface javax.swing.tree.TreeModel
Returns:
This method returns true if the entry is to be treated as a leaf node.

valueForPathChanged

public void valueForPathChanged(javax.swing.tree.TreePath arg0,
                                java.lang.Object arg1)
This data model is meant to be used with a read-only type JTree. Consequently, this method (that is meant to change the value in the tree) is not implemented and must not be called.

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

getPath

public javax.swing.tree.TreePath getPath(java.lang.Object entry)
This is a helper method to determine path to a given entry. This method can be used to obtain the path within the data set for a given data set entry. This is

Parameters:
entry - The entry for which the tree path is required.
Returns:
The complete path to the specified entry. If the specified path could not be determined then this method returns null.

fireTreeStructureChanged

protected void fireTreeStructureChanged(java.lang.Object oldRoot)
The only event raised by this model is TreeStructureChanged with the appropriate entry to be


workspaceChanged

public void workspaceChanged(WorkspaceEvent event)
Description copied from interface: WorkspaceListener
This method is invoked on all workspace listeners registered with the current Workspace. The event contains the necessary information to report the change that has occured to a workspace.

Specified by:
workspaceChanged in interface WorkspaceListener
Parameters:
event - The event that contains the information regarding the change that has occured to the workspace.