org.argouml.ui.targetmanager
Class TargetManager

java.lang.Object
  |
  +--org.argouml.ui.targetmanager.TargetManager

public final class TargetManager
extends java.lang.Object

The manager of the target of argouml. The target of argouml is the selected element in the model. 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 a figure on a diagram.

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

Note in particular that null is an invalid target.


Nested Class Summary
private  class TargetManager.HistoryManager
          The manager of the history of targets.
 
Field Summary
private  Fig _figTarget
          Cache for the figTarget.
private  TargetManager.HistoryManager _historyManager
          The history manager of argouml.
private  boolean _inTransaction
          Flag to indicate that there is a setTarget method running
private  javax.swing.event.EventListenerList _listenerList
          The list with targetlisteners
private  Logger _log
          The log4j logger to log messages to
private  java.lang.Object _modelTarget
          Cache for the modeltarget.
private  java.util.List _targets
          The targets
private static TargetManager instance
          The singleton instance
 
Constructor Summary
TargetManager()
           
 
Method Summary
 void addTarget(java.lang.Object target)
          Adds a target to the targets list.
 void addTargetListener(TargetListener listener)
          Adds a listener.
 void cleanHistory()
          Cleans the history.
private  Fig determineFigTarget(java.lang.Object target)
          Calculates the most probable 'fig-form' of some target.
private  java.lang.Object determineModelTarget(java.lang.Object target)
          Calculates the modeltarget.
private  void endTargetTransaction()
           
private  void fireTargetAdded(TargetEvent targetEvent)
           
private  void fireTargetRemoved(TargetEvent targetEvent)
           
private  void fireTargetSet(TargetEvent targetEvent)
           
 Fig getFigTarget()
          Convenience method to return the target as fig.
static TargetManager getInstance()
          Singleton retrieval method
 java.lang.Object getModelTarget()
          Returns the target in it's 'modelform'.
 java.util.Collection getModelTargets()
           
 java.lang.Object getTarget()
          Returns the current primary target, the first selected object.
 java.util.Collection getTargets()
          Returns a collection with all targets.
private  void internalOnSetTarget(java.lang.String eventName, java.lang.Object[] oldTargets)
           
private  boolean isInTargetTransaction()
           
 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(java.lang.Object o)
           
 void removeTarget(java.lang.Object target)
          Removes the target from the targets list.
 void removeTargetListener(TargetListener listener)
          Removes a listener.
 void setTarget(java.lang.Object o)
          Sets the targets to the single given object.
 void setTargets(java.util.Collection targetsList)
          Sets the given collection to the current targets.
private  void startTargetTransaction()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_log

private Logger _log
The log4j logger to log messages to


instance

private static TargetManager instance
The singleton instance


_targets

private java.util.List _targets
The targets


_modelTarget

private java.lang.Object _modelTarget
Cache for the modeltarget. See getModelTarget


_figTarget

private Fig _figTarget
Cache for the figTarget. See getFigTarget


_listenerList

private javax.swing.event.EventListenerList _listenerList
The list with targetlisteners


_historyManager

private TargetManager.HistoryManager _historyManager
The history manager of argouml. Via the historymanager browser behaviour is emulated


_inTransaction

private boolean _inTransaction
Flag to indicate that there is a setTarget method running

Constructor Detail

TargetManager

public TargetManager()
Method Detail

getInstance

public static TargetManager getInstance()
Singleton retrieval method

Returns:
The targetmanager

setTarget

public void setTarget(java.lang.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.

internalOnSetTarget

private void internalOnSetTarget(java.lang.String eventName,
                                 java.lang.Object[] oldTargets)

getTarget

public java.lang.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(java.util.Collection targetsList)
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:
targetsList - The new targets list.

addTarget

public void addTarget(java.lang.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(java.lang.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.

getTargets

public java.util.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.

getModelTargets

public java.util.Collection getModelTargets()

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

fireTargetSet

private void fireTargetSet(TargetEvent targetEvent)

fireTargetAdded

private void fireTargetAdded(TargetEvent targetEvent)

fireTargetRemoved

private void fireTargetRemoved(TargetEvent targetEvent)

startTargetTransaction

private void startTargetTransaction()

isInTargetTransaction

private boolean isInTargetTransaction()

endTargetTransaction

private void endTargetTransaction()

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'

determineFigTarget

private Fig determineFigTarget(java.lang.Object target)
Calculates the most probable 'fig-form' of some target.

Parameters:
target - the target to calculate the 'fig-form' for.
Returns:
The fig-form.

getModelTarget

public java.lang.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'.

determineModelTarget

private java.lang.Object determineModelTarget(java.lang.Object target)
Calculates the modeltarget.

Parameters:
target - The target to calculate the modeltarget for
Returns:
The modeltarget

navigateForward

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

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

navigateBackward

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

Throws:
java.lang.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(java.lang.Object o)


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