edu.stanford.hci.dtools.statechart.model.commands
Class ConnectionReconnectCommand

java.lang.Object
  extended by org.eclipse.gef.commands.Command
      extended by edu.stanford.hci.dtools.statechart.model.commands.ConnectionReconnectCommand

public class ConnectionReconnectCommand
extends org.eclipse.gef.commands.Command

A command to reconnect a connection to a different start point or end point. The command can be undone or redone.

This command is designed to be used together with a GraphicalNodeEditPolicy. To use this command propertly, following steps are necessary:

  1. Create a subclass of GraphicalNodeEditPolicy.
  2. Override the getReconnectSourceCommand(...) method. Here you need to obtain the ConnectionModel model element from the ReconnectRequest, create a new ConnectionReconnectCommand, set the new connection source by calling the setNewSource(ShapeModel) method and return the command instance.
  3. Override the getReconnectTargetCommand(...) method.
  4. Here again you need to obtain the ConnectionModel model element from the ReconnectRequest, create a new ConnectionReconnectCommand, set the new connection target by calling the setNewTarget(ShapeModel) method and return the command instance.

Author:
Elias Volanakis, Michael Bernstein ( mbernst(AT)stanford.edu ), Bjoern Hartmann ( bjoern(AT)stanford.edu )
See Also:
for an example of the above procedure., GraphicalNodeEditPolicy, setNewSource(ShapeModel),

This software is distributed under the BSD License.

This code is partially based on code that is copyright (c) 2004 Elias Volanakis. See License.txt

Constructor Summary
ConnectionReconnectCommand(ConnectionModel conn)
          Instantiate a command that can reconnect a ConnectionModel instance to a different source or target endpoint.
 
Method Summary
 boolean canExecute()
           
 void execute()
          Reconnect the connection to newSource (if setNewSource(...) was invoked before) or newTarget (if setNewTarget(...) was invoked before).
 void setNewSource(ShapeModel connectionSource)
          Set a new source endpoint for this connection.
 void setNewTarget(ShapeModel connectionTarget)
          Set a new target endpoint for this connection When execute() is invoked, the target endpoint of the connection will be attached to the supplied ShapeModel instance.
 void undo()
          Reconnect the connection to its original source and target endpoints.
 
Methods inherited from class org.eclipse.gef.commands.Command
canUndo, chain, dispose, getDebugLabel, getLabel, redo, setDebugLabel, setLabel
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionReconnectCommand

public ConnectionReconnectCommand(ConnectionModel conn)
Instantiate a command that can reconnect a ConnectionModel instance to a different source or target endpoint.

Parameters:
conn - the connection instance to reconnect (non-null)
Throws:
java.lang.IllegalArgumentException - if conn is null
Method Detail

canExecute

public boolean canExecute()
Overrides:
canExecute in class org.eclipse.gef.commands.Command

execute

public void execute()
Reconnect the connection to newSource (if setNewSource(...) was invoked before) or newTarget (if setNewTarget(...) was invoked before).

Overrides:
execute in class org.eclipse.gef.commands.Command

setNewSource

public void setNewSource(ShapeModel connectionSource)
Set a new source endpoint for this connection. When execute() is invoked, the source endpoint of the connection will be attached to the supplied ShapeModel instance.

Note: Calling this method, deactivates reconnection of the target endpoint. A single instance of this command can only reconnect either the source or the target endpoint.

Parameters:
connectionSource - a non-null ShapeModel instance, to be used as a new source endpoint
Throws:
java.lang.IllegalArgumentException - if connectionSource is null

setNewTarget

public void setNewTarget(ShapeModel connectionTarget)
Set a new target endpoint for this connection When execute() is invoked, the target endpoint of the connection will be attached to the supplied ShapeModel instance.

Note: Calling this method, deactivates reconnection of the source endpoint. A single instance of this command can only reconnect either the source or the target endpoint.

Parameters:
connectionTarget - a non-null ShapeModel instance, to be used as a new target endpoint
Throws:
java.lang.IllegalArgumentException - if connectionTarget is null

undo

public void undo()
Reconnect the connection to its original source and target endpoints.

Overrides:
undo in class org.eclipse.gef.commands.Command