org.eclipse.gmt.umlx.editor.command
Class AbstractCommand

java.lang.Object
  extended by org.eclipse.gef.commands.Command
      extended by org.eclipse.gmt.umlx.editor.command.AbstractCommand
All Implemented Interfaces:
IAbstractCommand
Direct Known Subclasses:
AbstractModelCommand, AbstractValueCommand, ChangeParentCommand, CompoundCommand, CopyByReferenceCommand, CopyByValueCommand, ModelStateCommand

public abstract class AbstractCommand
extends org.eclipse.gef.commands.Command
implements IAbstractCommand

This AbstractCommand adds the concepts of a preparation phase resulting in prefix commands, modified resources and unmodifiable objects. The preparation phase must be performed exactly once before either canExecute() or execute() can successfully occur. The preparation may result in the determination of nested commands that must be executed before this command (or undone after). The preparation should result in a requestModication invocation of every object that might be modified. This enables permission for the command to be determined and diagnosed, and the affected resources to be marked modified, or unmodified after an undo.


Constructor Summary
AbstractCommand(java.lang.String label)
           
 
Method Summary
 void addSelectedObjects(java.util.Collection<java.lang.Object> selectedObjects, boolean isDone)
           
 boolean canExecute()
           
 boolean canUndo()
           
 org.eclipse.emf.ecore.resource.Resource couldNotUnlock()
          Unlock all resources to facilitate sucvcessgful command execution.
 void diagnoseCannotExecute(boolean isUndo)
           
 void dispose()
           
 void execute()
           
 org.eclipse.gef.commands.Command getCommand()
           
 void prepare()
          Prepare the command for execution.
 void prepare(IAbstractCommand rootCommand)
          Prepare the command for execution.
 void redo()
          (re)-execute the command and its prefix chain.
<T> boolean
requestModification(T object)
          Request modification of object by the derived command.
 java.lang.String toString()
           
 void undo()
          un-execute the command and its prefix chain.
 
Methods inherited from class org.eclipse.gef.commands.Command
chain, getDebugLabel, getLabel, setDebugLabel, setLabel
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.eclipse.gmt.umlx.editor.command.IAbstractCommand
getLabel
 

Constructor Detail

AbstractCommand

public AbstractCommand(java.lang.String label)
Method Detail

addSelectedObjects

public void addSelectedObjects(java.util.Collection<java.lang.Object> selectedObjects,
                               boolean isDone)
Specified by:
addSelectedObjects in interface IAbstractCommand

canExecute

public boolean canExecute()
Specified by:
canExecute in interface IAbstractCommand
Overrides:
canExecute in class org.eclipse.gef.commands.Command

canUndo

public boolean canUndo()
Specified by:
canUndo in interface IAbstractCommand
Overrides:
canUndo in class org.eclipse.gef.commands.Command

couldNotUnlock

public org.eclipse.emf.ecore.resource.Resource couldNotUnlock()
Unlock all resources to facilitate sucvcessgful command execution.

Specified by:
couldNotUnlock in interface IAbstractCommand
Returns:
a non-null stubbornly locked rsource if any resource cannot be unlocked

diagnoseCannotExecute

public void diagnoseCannotExecute(boolean isUndo)
                           throws AbstractFailureException
Specified by:
diagnoseCannotExecute in interface IAbstractCommand
Throws:
AbstractFailureException

dispose

public void dispose()
Specified by:
dispose in interface IAbstractCommand
Overrides:
dispose in class org.eclipse.gef.commands.Command

execute

public final void execute()
Specified by:
execute in interface IAbstractCommand
Overrides:
execute in class org.eclipse.gef.commands.Command

getCommand

public org.eclipse.gef.commands.Command getCommand()
Specified by:
getCommand in interface IAbstractCommand

prepare

public final void prepare()
Prepare the command for execution. The local method invokes doPrepare() to require derived commands to request any modifications that they require. Derived implementations should additionally invoke appendToPrefixChain() for any commands that must be executed before this command. Then any resulting prefix chain is prepared.

Specified by:
prepare in interface IAbstractCommand

prepare

public final void prepare(IAbstractCommand rootCommand)
Prepare the command for execution. The local method invokes doPrepare() to require derived commands to request any modifications that they require. Derived implementations should additionally invoke appendToPrefixChain() for any commands that must be executed before this command. Then any resulting prefix chain is prepared.

Specified by:
prepare in interface IAbstractCommand

redo

public final void redo()
(re)-execute the command and its prefix chain.

Specified by:
redo in interface IAbstractCommand
Overrides:
redo in class org.eclipse.gef.commands.Command

requestModification

public <T> boolean requestModification(T object)
Request modification of object by the derived command. Returns null if allowed, after accumulating the containing resource in the list of potentially newly modifdied resources so that the state can be restored on undo. Return the non-null object if the object if is part of an unmodifiable resource.

Specified by:
requestModification in interface IAbstractCommand
Parameters:
object -
Returns:
non-null to prohibit modification

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

undo

public final void undo()
un-execute the command and its prefix chain. Derived functionality must be prefix.

Specified by:
undo in interface IAbstractCommand
Overrides:
undo in class org.eclipse.gef.commands.Command