org.argouml.ui.explorer
Class ExplorerTreeModel

java.lang.Object
  extended byjavax.swing.tree.DefaultTreeModel
      extended byorg.argouml.ui.explorer.ExplorerTreeModel
All Implemented Interfaces:
EventListener, ItemListener, Serializable, TreeModel, TreeModelUMLEventListener

public class ExplorerTreeModel
extends DefaultTreeModel
implements TreeModelUMLEventListener, ItemListener

The model for the Explorer tree view of the uml model. provides: - receives events from the uml model and updates itself and the tree ui. - responds to changes in perspetive and ordering.

Since:
0.15.2
See Also:
Serialized Form

Nested Class Summary
(package private)  class ExplorerTreeModel.ExplorerUpdater
          Help class to semi-lazily update nodes in the tree.
 
Field Summary
private static Logger LOG
           
private  Map modelElementMap
          a map used to resolve model elements to tree nodes when determining what effect a model event will have on the tree.
private  ExplorerTreeModel.ExplorerUpdater nodeUpdater
          A Runnable object that when executed does update some currently pending nodes.
private  Comparator order
          the global order for siblings in the tree.
private  Object[] rules
          an array of PerspectiveRules, that determine the tree view.
private  Vector updatingChildren
          The children currently being updated.
 
Fields inherited from class javax.swing.tree.DefaultTreeModel
asksAllowsChildren, listenerList, root
 
Constructor Summary
ExplorerTreeModel(Object root)
          Creates a new instance of ExplorerTreeModel.
 
Method Summary
private  void addNodesToMap(TreeNode node)
          Map all nodes in the subtree rooted at node
private  void addToMap(Object modelElement, TreeNode node)
          adds a new tree node and model element to the map.
private  void collectChildren(Object modelElement, List newChildren, Set deps)
          Collects the set of children modelElement should have at this point in time.
private  Collection findNodes(Object modelElement)
          node lookup for a given model element.
(package private)  ExplorerTreeModel.ExplorerUpdater getNodeUpdater()
           
 void insertNodeInto(MutableTreeNode newChild, MutableTreeNode parent, int index)
          Invoked this to insert newChild at location index in parents children.
 void itemStateChanged(ItemEvent e)
          Updates the explorer for new perspectives / orderings.
private  void mergeChildren(ExplorerTreeNode node, List children, List newChildren)
          Merges the current children with the new children removing children no longer present and adding new children in the right place.
 void modelElementAdded(Object node)
          a model element has been added to the model.
 void modelElementChanged(Object node)
          a model element has changed in some way.
 void modelElementRemoved(Object node)
          a model element has been removed from the model.
private  Set prepareAddRemoveSets(List children, List newChildren)
          Returns a Set of current children to remove and modifies newChildren to only contain the children not already in children and not subsumed by any WeakExplorerNode in children.
private  void removeFromMap(Object modelElement, TreeNode node)
          removes a new tree node and model element from the map.
 void removeNodeFromParent(MutableTreeNode node)
          Message this to remove node from its parent.
private  void removeNodesFromMap(TreeNode node)
          Unmap all nodes in the subtree rooted at node
private  Vector reorderChildren(ExplorerTreeNode node)
          Sorts the child nodes of node using the current ordering.
 void structureChanged()
          the model structure has changed, eg a new project.
private  void traverseModified(TreeNode start, Object node)
          Traverses the children, finds those affected by node, and notifies them that they are modified.
 void updateChildren(TreePath path)
          updates next level of the explorer tree for a given tree path.
 
Methods inherited from class javax.swing.tree.DefaultTreeModel
addTreeModelListener, asksAllowsChildren, fireTreeNodesChanged, fireTreeNodesInserted, fireTreeNodesRemoved, fireTreeStructureChanged, getChild, getChildCount, getIndexOfChild, getListeners, getPathToRoot, getPathToRoot, getRoot, getTreeModelListeners, isLeaf, nodeChanged, nodesChanged, nodeStructureChanged, nodesWereInserted, nodesWereRemoved, reload, reload, removeTreeModelListener, setAsksAllowsChildren, setRoot, valueForPathChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

private static final Logger LOG

rules

private Object[] rules
an array of PerspectiveRules, that determine the tree view.


modelElementMap

private Map modelElementMap
a map used to resolve model elements to tree nodes when determining what effect a model event will have on the tree.


order

private Comparator order
the global order for siblings in the tree.


updatingChildren

private Vector updatingChildren
The children currently being updated.


nodeUpdater

private ExplorerTreeModel.ExplorerUpdater nodeUpdater
A Runnable object that when executed does update some currently pending nodes.

Constructor Detail

ExplorerTreeModel

public ExplorerTreeModel(Object root)
Creates a new instance of ExplorerTreeModel.

Parameters:
root - an object to place at the root
Method Detail

modelElementChanged

public void modelElementChanged(Object node)
a model element has changed in some way.

Specified by:
modelElementChanged in interface TreeModelUMLEventListener
Parameters:
node - the modelelement that is changed
See Also:
TreeModelUMLEventListener.modelElementChanged(java.lang.Object)

modelElementAdded

public void modelElementAdded(Object node)
a model element has been added to the model.

Specified by:
modelElementAdded in interface TreeModelUMLEventListener
Parameters:
node - the modelelement that is added
See Also:
TreeModelUMLEventListener.modelElementAdded(java.lang.Object)

traverseModified

private void traverseModified(TreeNode start,
                              Object node)
Traverses the children, finds those affected by node, and notifies them that they are modified.


modelElementRemoved

public void modelElementRemoved(Object node)
a model element has been removed from the model.

Specified by:
modelElementRemoved in interface TreeModelUMLEventListener
Parameters:
node - the modelelement that is removed
See Also:
TreeModelUMLEventListener.modelElementRemoved(java.lang.Object)

structureChanged

public void structureChanged()
the model structure has changed, eg a new project.

Specified by:
structureChanged in interface TreeModelUMLEventListener

updateChildren

public void updateChildren(TreePath path)
updates next level of the explorer tree for a given tree path.

Parameters:
path - the path to the node whose children to update.
Throws:
IllegalArgumentException - if node has a child that is not a (descendant of) DefaultMutableTreeNode.

reorderChildren

private Vector reorderChildren(ExplorerTreeNode node)
Sorts the child nodes of node using the current ordering.

Note: UserObject is only available from descendants of DefaultMutableTreeNode, so any other children couldn't be sorted. Thus these are currently forbidden. But currently no such node is ever inserted into the tree.

Parameters:
node - the node whose children to sort
Returns:
the UserObjects of the children, in the same order as the children.
Throws:
IllegalArgumentException - if node has a child that is not a (descendant of) DefaultMutableTreeNode.

collectChildren

private void collectChildren(Object modelElement,
                             List newChildren,
                             Set deps)
Collects the set of children modelElement should have at this point in time. The children are added to newChildren.

Note: Both newChildren and deps are modified by this function, it is in fact it's primary purpose to modify these collections. It is your responsibility to make sure that they are empty when it is called, or to know what you are doing if they are not.

Parameters:
modelElement - the element to collect children for.
newChildren - the new children of modelElement.
deps - the set of objects that should be monitored for changes since these could affect this list.
Throws:
UnsupportedOperationException - if add is not supported by newChildren or addAll isn't supported by deps.
NullPointerException - if newChildren or deps is null.
ClassCastException - if newChildren or deps rejects some element.
IllegalArgumentException - if newChildren or deps rejects some element.

prepareAddRemoveSets

private Set prepareAddRemoveSets(List children,
                                 List newChildren)
Returns a Set of current children to remove and modifies newChildren to only contain the children not already in children and not subsumed by any WeakExplorerNode in children.

Note: newChildren will be modified by this call.

Note: It is expected that a WeakExplorerNode will not be reused and thus they will always initially be slated for removal, and only those nodes are in fact used to check subsumption of new nodes. New nodes are not checked among themselves for subsumtion.

Parameters:
children - is the list of current children.
newChildren - is the list of expected children.
Returns:
the Set of current children to remove.
Throws:
UnsupportedOperationException - if newChildren doesn't support remove or removeAll.
NullPointerException - if either argument is null.

mergeChildren

private void mergeChildren(ExplorerTreeNode node,
                           List children,
                           List newChildren)
Merges the current children with the new children removing children no longer present and adding new children in the right place.

Parameters:
node - the TreeNode were merging lists for.
children - the current child UserObjects, in order.
newChildren - the expected child UserObjects, in order.
Throws:
UnsupportedOperationException - if the Iterator returned by newChildren doesn't support the remove operation, or if newChildren itself doesn't support remove or removeAll.
NullPointerException - if node, children or newChildren are null.

insertNodeInto

public void insertNodeInto(MutableTreeNode newChild,
                           MutableTreeNode parent,
                           int index)
Invoked this to insert newChild at location index in parents children. This will then message nodesWereInserted to create the appropriate event. This is the preferred way to add children as it will create the appropriate event.

Also performs subclass specific initialization.

Parameters:
newChild - The new child node.
parent - The parent node.
index - The index.

removeNodeFromParent

public void removeNodeFromParent(MutableTreeNode node)
Message this to remove node from its parent. This will message nodesWereRemoved to create the appropriate event. This is the preferred way to remove a node as it handles the event creation for you.

Also performs subclass specific uninitialization.

Parameters:
node - The node to remove.

addNodesToMap

private void addNodesToMap(TreeNode node)
Map all nodes in the subtree rooted at node


removeNodesFromMap

private void removeNodesFromMap(TreeNode node)
Unmap all nodes in the subtree rooted at node


addToMap

private void addToMap(Object modelElement,
                      TreeNode node)
adds a new tree node and model element to the map. nodes are removed from the map when a modelElementRemoved event is received.


removeFromMap

private void removeFromMap(Object modelElement,
                           TreeNode node)
removes a new tree node and model element from the map.


findNodes

private Collection findNodes(Object modelElement)
node lookup for a given model element.


itemStateChanged

public void itemStateChanged(ItemEvent e)
Updates the explorer for new perspectives / orderings.

Specified by:
itemStateChanged in interface ItemListener
See Also:
ItemListener.itemStateChanged(java.awt.event.ItemEvent)

getNodeUpdater

ExplorerTreeModel.ExplorerUpdater getNodeUpdater()
Returns:
Returns the nodeUpdater.


ArgoUML © 1996-2004 (20050222)ArgoUML HomepageArgoUML Developers' pageArgoUML Cookbook