org.argouml.ui.targetmanager
Class TargetManager

java.lang.Object
  extended byorg.argouml.ui.targetmanager.TargetManager

public final class TargetManager
extends Object

The manager of the target of ArgoUML. The target of ArgoUML is the element currently selected by the user. This can either be an instance of a meta-class (an Interface or a Class for example) but it can also be a diagram or anything that is shown on a diagram.

There can be multiple targets in case someone selected multiple items in the explorer or on the diagram. This can be done by shift-clicking or Ctrl-clicking items, or by drawing a box on the diagram around the items to select.

In case multiple targets are selected, the target manager will add each target to the beginning of the list of targets. This way, the first item of the list is the last selected item. Most functions in ArgoUML work on all selected items. However, a few (intentionally) only work on one target, such as the properties panels. These functions have 2 ways of retrieving the target they should work on:

Remark: There is currently no function getFigs(), returning a list of selected figs. But you can obtain such a list from GEF.

The purpose of the targetmanager is to have a central spot where we manage the list of current targets.

Via an event mechanism this manager makes sure that all objects interested in knowing wether the selection changed are acknowledged.

Note in particular that null is an invalid target.

Thanks to the architecture of ArgoUML of Modelelements and Figs, one rule has been decided upon (by mvw@tigris.org):


Method Summary
 void addTarget(Object target)
          Adds a target to the targets list.
 void addTargetListener(TargetListener listener)
          Adds a listener.
 void cleanHistory()
          Cleans the history.
 Action getAddAttributeAction()
          Get the Action for creating and adding a new attribute to the single selected target (or its owner).
 Action getAddEnumerationLiteralAction()
          Get the Action class for creating and adding a new EnumerationLiteral for the single selected target (or its owner).
 Action getAddOperationAction()
          Get the Action for creating and adding a new operation to the single selected target (or its owner).
 Action getDeleteAction()
          Get the Action for deleting the target list.
 Fig getFigTarget()
          Convenience method to return the target as fig.
static TargetManager getInstance()
          Singleton retrieval method.
 Object getModelTarget()
          Returns the target in it's 'modelform'.
 Collection getModelTargets()
           
 Object getOwner(Object o)
           
 Object getSingleModelTarget()
          If there is only one model target, then it is returned.
 Object getSingleTarget()
          If there is only one target, then it is returned.
 Object getTarget()
          Returns the current primary target, the first selected object.
 Collection getTargets()
          Returns a collection with all targets.
 boolean navigateBackPossible()
          Checks if it's possible to navigate backward.
 void navigateBackward()
          Navigates the target pointer one target backward.
 void navigateForward()
          Navigates the target pointer one target forward.
 boolean navigateForwardPossible()
          Checks if it's possible to navigate forward.
 void removeHistoryElement(Object o)
           
 void removeTarget(Object target)
          Removes the target from the targets list.
 void removeTargetListener(TargetListener listener)
          Removes a listener.
 void setTarget(Object o)
          Sets the targets to the single given object.
 void setTargets(Collection targetsCollection)
          Sets the given collection to the current targets.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static TargetManager getInstance()
Singleton retrieval method.

Returns:
the targetmanager

setTarget

public void setTarget(Object o)
Sets the targets to the single given object. If there are targets at the moment of calling this method, these will be removed as targets. To all interested targetlisteners, a TargetEvent will be fired. If the new target o equals the current target, no events will be fired, nor will the target be (re)set.

Parameters:
o - The new target, null clears all targets.

getTarget

public Object getTarget()
Returns the current primary target, the first selected object. The value will be that of the new primary target during a targetSet/ targetAdded/targetRemoved notification, since they are just that, notifications that the target(s) has just changed.

Returns:
The current target, or null if no target is selected

setTargets

public void setTargets(Collection targetsCollection)
Sets the given collection to the current targets. If the collection equals the current targets, then does nothing. When setting the targets, a TargetEvent will be fired to each interested listener. Note that the first element returned by an Iterator on targetList will be taken to be the primary target (see getTarget()), and that an event will be fired also in case that that element would not equal the element returned by getTarget(). Note also that any nulls within the Collection will be ignored.

Parameters:
targetsCollection - The new targets list.

addTarget

public void addTarget(Object target)
Adds a target to the targets list. If the target is already in the targets list then does nothing. Otherwise the target will be added and an appropriate TargetEvent will be fired to all interested listeners. Since null can never be a target, adding null will never do anything.

Parameters:
target - the target to be added.

removeTarget

public void removeTarget(Object target)
Removes the target from the targets list. Does nothing if the target does not exist in the targets list. Fires an appropriate TargetEvent to all interested listeners. Since null can never be a target, removing null will never do anything.

Parameters:
target - The target to remove.

getOwner

public Object getOwner(Object o)
Parameters:
o - the object
Returns:
the owner of the fig, or if it didn't exist, the object itself

getTargets

public Collection getTargets()
Returns a collection with all targets. Returns an empty collection if there are no targets. If there are several targets then the first Object by an Iterator on the returned Collection or the zero'th Object in an array on this Collection is guaranteed to be the object returned by getTarget. The value will be that of the new target(s) during a targetSet/ targetAdded/targetRemoved notification, since they are just that, notifications that the target(s) has just changed.

Returns:
A collection with all targets.

getSingleTarget

public Object getSingleTarget()
If there is only one target, then it is returned. Otherwise null.

Returns:
the one and only target

getModelTargets

public Collection getModelTargets()
Returns:
the target from the model

getSingleModelTarget

public Object getSingleModelTarget()
If there is only one model target, then it is returned. Otherwise null.

Returns:
the single model target

addTargetListener

public void addTargetListener(TargetListener listener)
Adds a listener.

Parameters:
listener - the listener to add

removeTargetListener

public void removeTargetListener(TargetListener listener)
Removes a listener.

Parameters:
listener - the listener to remove

getAddAttributeAction

public Action getAddAttributeAction()
Get the Action for creating and adding a new attribute to the single selected target (or its owner).

Returns:
the action

getAddOperationAction

public Action getAddOperationAction()
Get the Action for creating and adding a new operation to the single selected target (or its owner).

Returns:
the action

getDeleteAction

public Action getDeleteAction()
Get the Action for deleting the target list.

Returns:
the action

getAddEnumerationLiteralAction

public Action getAddEnumerationLiteralAction()
Get the Action class for creating and adding a new EnumerationLiteral for the single selected target (or its owner).

Returns:
the action

getFigTarget

public Fig getFigTarget()
Convenience method to return the target as fig. If the current target (retrieved by getTarget) is either a fig itself or the owner of a fig this fig will be returned. Otherwise null will be returned.

Returns:
the target in it's 'fig-form'

getModelTarget

public Object getModelTarget()
Returns the target in it's 'modelform'. If the target retrieved by getTarget is an UMLDiagram or a modelelement the target will be returned. If the target is a fig but owned by a modelelement that modelelement will be returned. Otherwise null will be returned.

Returns:
the target in it's 'modelform'.

navigateForward

public void navigateForward()
                     throws IllegalStateException
Navigates the target pointer one target forward. This implements together with navigateBackward browser like functionality.

Throws:
IllegalStateException - If the target pointer is at the end of the history.

navigateBackward

public void navigateBackward()
                      throws IllegalStateException
Navigates the target pointer one target backward. This implements together with navigateForward browser like functionality

Throws:
IllegalStateException - If the target pointer is at the beginning of the history.

navigateForwardPossible

public boolean navigateForwardPossible()
Checks if it's possible to navigate forward.

Returns:
true if it is possible to navigate forward.

navigateBackPossible

public boolean navigateBackPossible()
Checks if it's possible to navigate backward.

Returns:
true if it's possible to navigate backward

cleanHistory

public void cleanHistory()
Cleans the history. Needed for the JUnit tests and when instantiating a new project.


removeHistoryElement

public void removeHistoryElement(Object o)
Parameters:
o - the object to be removed


ArgoUML © 1996-2006ArgoUML HomepageArgoUML Developers' pageArgoUML Cookbook