org.jupe.editors.classdiagram.model.commands
Class ConnectionReconnectCommand

java.lang.Object
  extended by org.eclipse.gef.commands.Command
      extended by org.jupe.editors.classdiagram.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 Connection model element from the ReconnectRequest, create a new ConnectionReconnectCommand, set the new connection source by calling the setNewSource(Shape) method and return the command instance.
  3. Override the getReconnectTargetCommand(...) method.
  4. Here again you need to obtain the Connection model element from the ReconnectRequest, create a new ConnectionReconnectCommand, set the new connection target by calling the setNewTarget(Shape) method and return the command instance.

Author:
Steffen Klüpfel

Constructor Summary
ConnectionReconnectCommand(ConnectionElement conn)
          Instantiate a command that can reconnect a Connection 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(NodeModelElement connectionSource)
          Set a new source endpoint for this connection.
 void setNewTarget(NodeModelElement 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 Shape 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(ConnectionElement conn)
Instantiate a command that can reconnect a Connection 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(NodeModelElement 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 Shape 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 Shape instance, to be used as a new source endpoint
Throws:
java.lang.IllegalArgumentException - if connectionSource is null

setNewTarget

public void setNewTarget(NodeModelElement 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 Shape 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 Shape 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