com.tensegrity.gui.swing.control.tree.strategy
Class AbstractTreeStrategy

java.lang.Object
  extended bycom.tensegrity.gui.swing.control.tree.strategy.AbstractTreeStrategy
All Implemented Interfaces:
OutlinerStrategy, TreeStrategy
Direct Known Subclasses:
AbstractVisualGraphTreeStrategy

public abstract class AbstractTreeStrategy
extends java.lang.Object
implements TreeStrategy

This is the implementation of TreeStrategy that all classes requiring to implement TreeStrategy should extend. It is indeed not recommanded to directly implement TreeStrategy. Note that the provided initializeModel method is intended to be overridden. It is also required to be called ( super.initializeModel()) when overridden since it sets the locally held active Graph instance. It is important to do so in order to get the getModel and setModel methods working as expected. Subclasses should overridde the public constant DOCUMENT_TYPE_KEY. Set this constant to be the Class name of the specific Document the strategy is associated to. For example, in AbstractVisualGraphTreeStrategy it is set to "GraphDocument" Note also that this class is javax.swing dependant.

Author:
S�bastien Guyon
See Also:
TreeStrategy, AbstractVisualGraphTreeStrategy

Field Summary
static java.lang.String DOCUMENT_TYPE_KEY
          represents the type of Document this strategy is associated to.
 
Constructor Summary
protected AbstractTreeStrategy(UIManager uiManager)
           Initializes instances of this class with the passed UIManager instance.
protected AbstractTreeStrategy(UIManager uiManager, TreeOutliner tree)
           Initializes instances of this class with the passed UIManager and TreeOutliner instances.
 
Method Summary
 void addNode(javax.swing.tree.DefaultMutableTreeNode parent, javax.swing.tree.DefaultMutableTreeNode node)
          Method addNode adds the given node the the given parent.
abstract  javax.swing.tree.DefaultMutableTreeNode findNodeByID(javax.swing.tree.DefaultMutableTreeNode parent, long id)
          Utility method.
protected  Document getActiveDocument()
          Returns the currently active Document.
 java.util.Map getDocumentIdNodeMap()
          Returns the Map containing Map s of VisualGraphObject s Ids /TreeNodes.
protected  java.util.HashMap getDocumentModelMap()
           Returns the local Map of Document s and DefaultTreeModels.
protected  java.util.Map getIdNodeMap(Document document)
          Returns the Map of VisualGraphObject s Ids /TreeNode s corresponding to the passed Document.
protected  javax.swing.tree.DefaultTreeModel getModel()
           Returns the DefaultTreeModel associated to the active Document.
protected  javax.swing.tree.DefaultMutableTreeNode getRoot()
           Returns the root of the Tree, null if the model is null.
protected  TreeOutliner getTree()
           Method giving access to the TreeOutliner instance to which the strategy is applied.
 UIManager getUIManager()
          Returns the local instance of UIManager
abstract  javax.swing.tree.DefaultTreeModel initializeModel(java.util.Map uiMap, Document document, java.lang.String name, boolean recreateModelEvenIfExists)
           Method initializing and returning the TreeModel associated to the passed Document.
 void removeModel(Document document)
           Removes the model associated to the passed Document from the local Map of Document s and DefaultTreeModels.
protected  void setActiveDocument(Document activeDocument)
           Sets the currently active Document.
protected  void setModel(javax.swing.tree.DefaultTreeModel model)
           Locally stores the passed model.
 void setTree(TreeOutliner tree)
           Sets the local instance of TreeOutliner.
 void updateNode(javax.swing.tree.TreeNode node)
          Method updateNode reflects the changes made on the passed TreeNode on the TreeModel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.tensegrity.gui.swing.control.tree.strategy.TreeStrategy
getNewTreeNode, getParentIndex, removeNode
 
Methods inherited from interface com.tensegrity.gui.swing.control.tree.strategy.OutlinerStrategy
getComparator
 

Field Detail

DOCUMENT_TYPE_KEY

public static final java.lang.String DOCUMENT_TYPE_KEY
represents the type of Document this strategy is associated to. Subclasses should provide override this constant

See Also:
Constant Field Values
Constructor Detail

AbstractTreeStrategy

protected AbstractTreeStrategy(UIManager uiManager,
                               TreeOutliner tree)

Initializes instances of this class with the passed UIManager and TreeOutliner instances.

Parameters:
uiManager - the application UIManager.
tree - the TreeOutliner to which this strategy is applied.

AbstractTreeStrategy

protected AbstractTreeStrategy(UIManager uiManager)

Initializes instances of this class with the passed UIManager instance.

Parameters:
uiManager - the application UIManager.
Method Detail

getIdNodeMap

protected final java.util.Map getIdNodeMap(Document document)
Returns the Map of VisualGraphObject s Ids /TreeNode s corresponding to the passed Document.

Parameters:
document - the Document for which the Map of VisualGraphObject s Ids and TreeNode s is requested.
Returns:
the Map of VisualObjects Ids / TreeNodes corresponding to the passed Document

getDocumentIdNodeMap

public final java.util.Map getDocumentIdNodeMap()
Returns the Map containing Map s of VisualGraphObject s Ids /TreeNodes. This Map keys are Documents.

Returns:
Map containing Maps of VisualObjects Ids / TreeNodes. This Map key is a Document.

getUIManager

public final UIManager getUIManager()

Returns the local instance of UIManager

Returns:
The local instance of UIManager

removeModel

public void removeModel(Document document)

Removes the model associated to the passed Document from the local Map of Document s and DefaultTreeModels.

Parameters:
document - the Document of which the associated DefaultTreeModel should be removed from the local Map.

getDocumentModelMap

protected final java.util.HashMap getDocumentModelMap()

Returns the local Map of Document s and DefaultTreeModels.

Returns:
the local Map of Document s and DefaultTreeModels.

setTree

public final void setTree(TreeOutliner tree)

Sets the local instance of TreeOutliner.

Parameters:
tree - the TreeOutliner to which the AbstractTreeStrategy is applied.

getRoot

protected final javax.swing.tree.DefaultMutableTreeNode getRoot()

Returns the root of the Tree, null if the model is null.

Returns:
the root of the Tree, null if the model is null.

getModel

protected final javax.swing.tree.DefaultTreeModel getModel()

Returns the DefaultTreeModel associated to the active Document. The active Document is locally stored when initializeModel(Map, Document, String, boolean) is called.

Returns:
The DefaultTreeModel associated to the active Document.

setModel

protected void setModel(javax.swing.tree.DefaultTreeModel model)

Locally stores the passed model.

Important Note

It is internally storing the model in a Map for which the key is the Document corresponding to the passed model.

It assumes that the Document local instance is set to the desired Document before this method is called. This is done by initializeModel(Map, Document, String, boolean).

Parameters:
model - the DefaultTreeModel associated to the active Docuement, if any.

getTree

protected final TreeOutliner getTree()

Method giving access to the TreeOutliner instance to which the strategy is applied.

Returns:
local instance of TreeOutliner

findNodeByID

public abstract javax.swing.tree.DefaultMutableTreeNode findNodeByID(javax.swing.tree.DefaultMutableTreeNode parent,
                                                                     long id)
Utility method. It searches all nodes under the passed tree node and returns the DefaultMutableTreeNode which matches the given id. If no such node is found, null is returned.

Parameters:
parent - DefaultMutableTreeNode representing the parent of the DefaultMutableTreeNode we are looking for.
id - unique identifier for a tree node.
Returns:
DefaultMutableTreeNode the DefaultMutableTreeNode which matches the given id, or nulll/code> if no match is found.

initializeModel

public abstract javax.swing.tree.DefaultTreeModel initializeModel(java.util.Map uiMap,
                                                                  Document document,
                                                                  java.lang.String name,
                                                                  boolean recreateModelEvenIfExists)

Method initializing and returning the TreeModel associated to the passed Document. If the document does not already have a TreeModel associated to it, the DefaultTreeModel associated to the type of this document is created and associated to the document. Note that by setting the recreateModelEvenIfExists parameter to true the TreeModel is recreated even if one was already associated to the document. IMPORTANT
First thing to do when overriding this method is to call setActiveDocument(Document). It is important to do so in order to get the getModel() and setModel(DefaultTreeModel) methods working as expected.

Parameters:
uiMap - this is the UI Map.
document - The document of which the Model is required
name - The name of the document
recreateModelEvenIfExists - True if the Model should be recreated even if a Model is already associated to the document.
Returns:
the TreeModel associated to the passed Document.

addNode

public void addNode(javax.swing.tree.DefaultMutableTreeNode parent,
                    javax.swing.tree.DefaultMutableTreeNode node)
Description copied from interface: TreeStrategy
Method addNode adds the given node the the given parent. If parent s childcount is 0 before the adding, its added to the root. The current expanded TreePath instances are saved and restored after the sucessful adding.

Specified by:
addNode in interface TreeStrategy
Parameters:
parent - the DefaultMutableTreeNode of which node is going to be added as a child
node - the DefaultMutableTreeNode to add.
See Also:
TreeStrategy.addNode(javax.swing.tree.DefaultMutableTreeNode, javax.swing.tree.DefaultMutableTreeNode)

updateNode

public final void updateNode(javax.swing.tree.TreeNode node)
Description copied from interface: TreeStrategy

Method updateNode reflects the changes made on the passed TreeNode on the TreeModel

Specified by:
updateNode in interface TreeStrategy
Parameters:
node - The TreeNode which requires to be updated
See Also:
TreeStrategy.updateNode(javax.swing.tree.TreeNode)

getActiveDocument

protected Document getActiveDocument()
Returns the currently active Document.

Returns:
the currently active Document.

setActiveDocument

protected void setActiveDocument(Document activeDocument)

Sets the currently active Document.

Parameters:
activeDocument - the currently active Document.


Copyright © 2005 Tensegrity Software GmbH. All Rights Reserved. Date of creation: 09.06.2006.