org.apache.excalibur.instrument.client
Class InstrumentManagerTreeModel

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.excalibur.instrument.client.InstrumentManagerTreeModel
All Implemented Interfaces:
javax.swing.tree.TreeModel, org.apache.avalon.framework.logger.LogEnabled, InstrumentManagerConnectionListener

 class InstrumentManagerTreeModel
extends org.apache.avalon.framework.logger.AbstractLogEnabled
implements InstrumentManagerConnectionListener, javax.swing.tree.TreeModel

Author:
Avalon Development Team

Field Summary
private  InstrumentManagerConnection m_connection
           
private  java.util.HashMap m_elementMap
           
private  int m_lastClientStateVersion
          The state version of the last client.
private  boolean m_lastConnected
           
private  javax.swing.tree.DefaultMutableTreeNode[] m_leasedSampleArray
           
private  java.util.HashMap m_leasedSampleMap
           
private  javax.swing.event.TreeModelListener[] m_listenerArray
           
private  java.util.ArrayList m_listeners
           
private  javax.swing.tree.DefaultMutableTreeNode m_root
           
 
Constructor Summary
InstrumentManagerTreeModel(InstrumentManagerConnection connection)
           
 
Method Summary
 void addTreeModelListener(javax.swing.event.TreeModelListener listener)
          Adds a listener for the TreeModelEvent posted after the tree changes.
 void closed(InstrumentManagerConnection connection)
          Called when the connection is closed.
 void deleted(InstrumentManagerConnection connection)
          Called when the connection is deleted.
private  void fireTreeNodesChanged(javax.swing.event.TreeModelEvent event)
           
private  void fireTreeNodesInserted(javax.swing.event.TreeModelEvent event)
           
private  void fireTreeNodesRemoved(javax.swing.event.TreeModelEvent event)
           
private  void fireTreeStructureChanged(javax.swing.event.TreeModelEvent event)
           
 java.lang.Object getChild(java.lang.Object parent, int index)
          Returns the child of parent at index 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.
 javax.swing.tree.DefaultMutableTreeNode getInstrumentableTreeNode(java.lang.String name)
          Returns a TreeNode for an Instrumentable given its name.
 javax.swing.tree.DefaultMutableTreeNode getInstrumentSampleTreeNode(java.lang.String name)
          Returns a TreeNode for an InstrumentSample given its name.
 javax.swing.tree.DefaultMutableTreeNode getInstrumentTreeNode(java.lang.String name)
          Returns a TreeNode for an Instrument given its name.
private  javax.swing.tree.DefaultMutableTreeNode[] getLeasedSampleArray()
          Returns an optimized array of TreeNodes representing the leased instrument samples in this tree model.
private  javax.swing.event.TreeModelListener[] getListeners()
          Returns an optimized array of the registered TreeModelListeners.
 java.lang.Object getRoot()
          Returns the root of the tree.
 boolean isLeaf(java.lang.Object node)
          Returns true if node is a leaf.
 void opened(InstrumentManagerConnection connection)
          Called when the connection is opened.
(package private)  void purgeExpiredSamples()
          Remove any instrument samples whose current leases have expired.
(package private)  void refreshModel()
          Refreshes the entire Tree Model with the latest information from the server.
 void removeTreeModelListener(javax.swing.event.TreeModelListener listener)
          Removes a listener previously added with addTreeModelListener().
(package private)  void renewAllSampleLeases()
          Once a minute, all of the leased samples should be updated.
(package private)  void updateInstrument(InstrumentData instrumentData)
           
(package private)  void updateInstrument(InstrumentData instrumentData, javax.swing.tree.DefaultMutableTreeNode instrumentTreeNode, int oldStateVersion)
           
private  void updateInstrumentable(InstrumentableData instrumentableData, javax.swing.tree.DefaultMutableTreeNode instrumentableTreeNode, int oldStateVersion)
           
private  void updateInstrumentManagerData(InstrumentManagerData manager, javax.swing.tree.DefaultMutableTreeNode rootTreeNode, int oldStateVersion)
          Called to update the local view of the InstrumentManagerData in the TreeeModel.
(package private)  void updateInstrumentSample(InstrumentSampleData sampleData)
           
(package private)  void updateInstrumentSample(InstrumentSampleData sampleData, javax.swing.tree.DefaultMutableTreeNode sampleTreeNode)
           
 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 org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_connection

private final InstrumentManagerConnection m_connection

m_lastClientStateVersion

private int m_lastClientStateVersion
The state version of the last client.


m_lastConnected

private boolean m_lastConnected

m_root

private javax.swing.tree.DefaultMutableTreeNode m_root

m_listeners

private java.util.ArrayList m_listeners

m_listenerArray

private javax.swing.event.TreeModelListener[] m_listenerArray

m_elementMap

private java.util.HashMap m_elementMap

m_leasedSampleMap

private java.util.HashMap m_leasedSampleMap

m_leasedSampleArray

private javax.swing.tree.DefaultMutableTreeNode[] m_leasedSampleArray
Constructor Detail

InstrumentManagerTreeModel

InstrumentManagerTreeModel(InstrumentManagerConnection connection)
Method Detail

opened

public void opened(InstrumentManagerConnection connection)
Called when the connection is opened. May be called more than once if the connection to the InstrumentManager is reopened.

Specified by:
opened in interface InstrumentManagerConnectionListener
Parameters:
connection - Connection which was opened.

closed

public void closed(InstrumentManagerConnection connection)
Called when the connection is closed. May be called more than once if the connection to the InstrumentManager is reopened.

Specified by:
closed in interface InstrumentManagerConnectionListener
Parameters:
connection - Connection which was closed.

deleted

public void deleted(InstrumentManagerConnection connection)
Called when the connection is deleted. All references should be removed.

Specified by:
deleted in interface InstrumentManagerConnectionListener
Parameters:
connection - Connection which was deleted.

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
Returns:
the root of the tree

getChild

public java.lang.Object getChild(java.lang.Object parent,
                                 int index)
Returns the child of parent at index 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
Parameters:
parent - a node in the tree, obtained from this data source
Returns:
the child of parent at index index

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
Parameters:
parent - a node in the tree, obtained from this data source
Returns:
the number of children of the node parent

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
Parameters:
node - a node in the tree, obtained from this data source
Returns:
true if node is a leaf

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
Parameters:
path - path to the node that the user has altered.
newValue - the new value from the TreeCellEditor.

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

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
Parameters:
listener - the listener to add

removeTreeModelListener

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

Specified by:
removeTreeModelListener in interface javax.swing.tree.TreeModel
Parameters:
listener - the listener to remove

getListeners

private javax.swing.event.TreeModelListener[] getListeners()
Returns an optimized array of the registered TreeModelListeners.

Returns:
An array of the registered TreeModelListeners

fireTreeNodesChanged

private void fireTreeNodesChanged(javax.swing.event.TreeModelEvent event)

fireTreeNodesInserted

private void fireTreeNodesInserted(javax.swing.event.TreeModelEvent event)

fireTreeNodesRemoved

private void fireTreeNodesRemoved(javax.swing.event.TreeModelEvent event)

fireTreeStructureChanged

private void fireTreeStructureChanged(javax.swing.event.TreeModelEvent event)

getInstrumentableTreeNode

public javax.swing.tree.DefaultMutableTreeNode getInstrumentableTreeNode(java.lang.String name)
Returns a TreeNode for an Instrumentable given its name.

Parameters:
name - Name of the Instrumentable.
Returns:
The named TreeNode.

getInstrumentTreeNode

public javax.swing.tree.DefaultMutableTreeNode getInstrumentTreeNode(java.lang.String name)
Returns a TreeNode for an Instrument given its name.

Parameters:
name - Name of the Instrument.
Returns:
The named TreeNode.

getInstrumentSampleTreeNode

public javax.swing.tree.DefaultMutableTreeNode getInstrumentSampleTreeNode(java.lang.String name)
Returns a TreeNode for an InstrumentSample given its name.

Parameters:
name - Name of the InstrumentSample.
Returns:
The named TreeNode.

getLeasedSampleArray

private javax.swing.tree.DefaultMutableTreeNode[] getLeasedSampleArray()
Returns an optimized array of TreeNodes representing the leased instrument samples in this tree model.

Returns:
An array of TreeNodes for the leased instrument samples in the TreeModel.

renewAllSampleLeases

void renewAllSampleLeases()
Once a minute, all of the leased samples should be updated. This is necessary to get the latest expiration times in case other processes are also updating the leases. Called from InstrumentManagerConnection.handleLeasedSamples.


purgeExpiredSamples

void purgeExpiredSamples()
Remove any instrument samples whose current leases have expired.


refreshModel

void refreshModel()
Refreshes the entire Tree Model with the latest information from the server. This should be called whenever a refresh is needed, or whenever the status of the connection to the server changes.


updateInstrumentManagerData

private void updateInstrumentManagerData(InstrumentManagerData manager,
                                         javax.swing.tree.DefaultMutableTreeNode rootTreeNode,
                                         int oldStateVersion)
Called to update the local view of the InstrumentManagerData in the TreeeModel.

Parameters:
manager - The InstrumentManagerData to use for the update.
roorTreeNode - The TreeNode representing the client.
oldStateVersion - The state version at the time of the last update.

updateInstrumentable

private void updateInstrumentable(InstrumentableData instrumentableData,
                                  javax.swing.tree.DefaultMutableTreeNode instrumentableTreeNode,
                                  int oldStateVersion)
Parameters:
instrumentableData - The Instrumentable to update.
instrumentableTreeNode - The tree node of the Instrumentable to update.
oldStateVersion - The state version at the time of the last update.

updateInstrument

void updateInstrument(InstrumentData instrumentData)
Parameters:
instrumentData - The Instrument to update.

updateInstrument

void updateInstrument(InstrumentData instrumentData,
                      javax.swing.tree.DefaultMutableTreeNode instrumentTreeNode,
                      int oldStateVersion)
Parameters:
instrumentData - The Instrument to update.
instrumentTreeNode - The tree node of the Instrument to update.

updateInstrumentSample

void updateInstrumentSample(InstrumentSampleData sampleData)
Parameters:
sampleData - The Instrument Sample to update.

updateInstrumentSample

void updateInstrumentSample(InstrumentSampleData sampleData,
                            javax.swing.tree.DefaultMutableTreeNode sampleTreeNode)
Parameters:
sampleData - The Instrument Sample to update.
sampleTreeNode - The tree node of the Instrument Sample to update.