org.eclipse.emf.common.command
Class CommandWrapper

java.lang.Object
  extended by org.eclipse.emf.common.command.AbstractCommand
      extended by org.eclipse.emf.common.command.CommandWrapper
All Implemented Interfaces:
Command
Direct Known Subclasses:
ControlAction.SelfAffectingCommand, CreateChildCommand, CreateMappingAction.DelegateCommand, CreateOneSidedMappingAction.DelegateCommand, CutToClipboardCommand, DelegatingWrapperItemProvider.AffectedObjectsWrappingCommand, ItemProviderAdapter.ResultAndAffectedObjectsWrappingCommand, RemoveMappingAction.CommandDelegate, WrapperItemProvider.ReplacementAffectedObjectCommand, WrapperItemProvider.WrappingCopyCommand

public class CommandWrapper
extends AbstractCommand

A command that wraps another command. All the Command methods are delegated to the wrapped command.

There are two typical usage patterns. One typical use for this command is to modify the behaviour of a command that you can't subclass, i.e., a decorator pattern:

   Command decoratedCommand =
     new CommandWrapper(someOtherCommand)
     {
       public void execute()
       {
         doSomethingBeforeExecution();
         super.execute();
         doSomethingAfterExecution();
       }
       public Collection getResult()
       {
         return someOtherResult();
       }
     };
The other typical use is to act as a proxy for a command who's creation is delayed:
   Command proxyCommand =
     new CommandWrapper()
     {
       public Command createCommand()
       {
         return createACommandSomehow();
       }
     };


Nested Class Summary
 
Nested classes/interfaces inherited from class org.eclipse.emf.common.command.AbstractCommand
AbstractCommand.NonDirtying
 
Field Summary
protected  Command command
          The command for which this is a proxy or decorator.
 
Fields inherited from class org.eclipse.emf.common.command.AbstractCommand
description, isExecutable, isPrepared, label
 
Constructor Summary
protected CommandWrapper()
          Creates a commandless proxy instance.
  CommandWrapper(Command command)
          Creates a decorator instance for the given command.
protected CommandWrapper(java.lang.String label)
          Creates a commandless proxy instance, with the given label.
protected CommandWrapper(java.lang.String label, Command command)
          Creates a decorator instance with the given label for the given command.
protected CommandWrapper(java.lang.String label, java.lang.String description)
          Creates a commandless proxy instance, with the given label and description.
  CommandWrapper(java.lang.String label, java.lang.String description, Command command)
          Creates a decorator instance with the given label and description for the given command.
 
Method Summary
 boolean canUndo()
          Delegates to the canUndo method of the command.
protected  Command createCommand()
          Create the command being proxied.
 void dispose()
          Delegates to the dispose method of the command.
 void execute()
          Delegates to the execute method of the command.
 java.util.Collection<?> getAffectedObjects()
          Delegates to the getAffectedObjects method of the command.
 Command getCommand()
          Returns the command for which this is a proxy or decorator.
 java.lang.String getDescription()
          Delegates to the getDescription method of the command.
 java.lang.String getLabel()
          Delegates to the getLabel method of the command.
 java.util.Collection<?> getResult()
          Delegates to the getResult method of the command.
protected  boolean prepare()
          Returns whether the command can execute.
 void redo()
          Delegates to the redo method of the command.
 java.lang.String toString()
          Returns an abbreviated name using this object's own class' name, without package qualification, followed by a space separated list of field:value pairs.
 void undo()
          Delegates to the undo method of the command.
 
Methods inherited from class org.eclipse.emf.common.command.AbstractCommand
canExecute, chain, setDescription, setLabel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

command

protected Command command
The command for which this is a proxy or decorator.

Constructor Detail

CommandWrapper

public CommandWrapper(Command command)
Creates a decorator instance for the given command.

Parameters:
command - the command to wrap.

CommandWrapper

protected CommandWrapper(java.lang.String label,
                         Command command)
Creates a decorator instance with the given label for the given command.

Parameters:
label - the label of the wrapper
command - the command to wrap.

CommandWrapper

public CommandWrapper(java.lang.String label,
                      java.lang.String description,
                      Command command)
Creates a decorator instance with the given label and description for the given command.

Parameters:
label - the label of the wrapper
description - the description of the wrapper
command - the command to wrap.

CommandWrapper

protected CommandWrapper()
Creates a commandless proxy instance. The wrapped command will be created by a createCommand() callback. Since a proxy command like this is pointless unless you override some method, this constructor is protected.


CommandWrapper

protected CommandWrapper(java.lang.String label)
Creates a commandless proxy instance, with the given label. The command will be created by a createCommand() callback. Since a proxy command like this is pointless unless you override some method, this constructor is protected.

Parameters:
label - the label of the wrapper

CommandWrapper

protected CommandWrapper(java.lang.String label,
                         java.lang.String description)
Creates a commandless proxy instance, with the given label and description. The command will be created by a createCommand() callback. Since a proxy command like this is pointless unless you override some method, this constructor is protected.

Parameters:
label - the label of the wrapper
description - the description of the wrapper
Method Detail

getCommand

public Command getCommand()
Returns the command for which this is a proxy or decorator. This may be null before createCommand() is called.

Returns:
the command for which this is a proxy or decorator.

createCommand

protected Command createCommand()
Create the command being proxied. This implementation just return null. It is called by prepare().

Returns:
the command being proxied.

prepare

protected boolean prepare()
Returns whether the command can execute. This implementation creates the command being proxied using createCommand(), if the command wasn't given in the constructor.

Overrides:
prepare in class AbstractCommand
Returns:
whether the command can execute.

execute

public void execute()
Delegates to the execute method of the command.


canUndo

public boolean canUndo()
Delegates to the canUndo method of the command.

Specified by:
canUndo in interface Command
Overrides:
canUndo in class AbstractCommand
Returns:
true.

undo

public void undo()
Delegates to the undo method of the command.

Specified by:
undo in interface Command
Overrides:
undo in class AbstractCommand

redo

public void redo()
Delegates to the redo method of the command.


getResult

public java.util.Collection<?> getResult()
Delegates to the getResult method of the command.

Specified by:
getResult in interface Command
Overrides:
getResult in class AbstractCommand
Returns:
the result.

getAffectedObjects

public java.util.Collection<?> getAffectedObjects()
Delegates to the getAffectedObjects method of the command.

Specified by:
getAffectedObjects in interface Command
Overrides:
getAffectedObjects in class AbstractCommand
Returns:
the result.

getLabel

public java.lang.String getLabel()
Delegates to the getLabel method of the command.

Specified by:
getLabel in interface Command
Overrides:
getLabel in class AbstractCommand
Returns:
the label.

getDescription

public java.lang.String getDescription()
Delegates to the getDescription method of the command.

Specified by:
getDescription in interface Command
Overrides:
getDescription in class AbstractCommand
Returns:
the description.

dispose

public void dispose()
Delegates to the dispose method of the command.

Specified by:
dispose in interface Command
Overrides:
dispose in class AbstractCommand

toString

public java.lang.String toString()
Description copied from class: AbstractCommand
Returns an abbreviated name using this object's own class' name, without package qualification, followed by a space separated list of field:value pairs.

Overrides:
toString in class AbstractCommand
Returns:
string representation.

Copyright 2001-2012 IBM Corporation and others.
All Rights Reserved.