Package org.eclipse.emf.common.command
Class CommandWrapper
java.lang.Object
org.eclipse.emf.common.command.AbstractCommand
org.eclipse.emf.common.command.CommandWrapper
- All Implemented Interfaces:
Command
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
FieldsModifier and TypeFieldDescriptionprotected CommandThe 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
ConstructorsModifierConstructorDescriptionprotectedCreates a commandless proxy instance.protectedCommandWrapper(String label) Creates a commandless proxy instance, with the given label.protectedCommandWrapper(String label, String description) Creates a commandless proxy instance, with the given label and description.CommandWrapper(String label, String description, Command command) Creates a decorator instance with the given label and description for the given command.protectedCommandWrapper(String label, Command command) Creates a decorator instance with the given label for the given command.CommandWrapper(Command command) Creates a decorator instance for the given command. -
Method Summary
Modifier and TypeMethodDescriptionbooleancanUndo()Delegates to the canUndo method of the command.protected CommandCreate the command being proxied.voiddispose()Delegates to the dispose method of the command.voidexecute()Delegates to the execute method of the command.Collection<?>Delegates to the getAffectedObjects method of the command.Returns the command for which this is a proxy or decorator.Delegates to the getDescription method of the command.getLabel()Delegates to the getLabel method of the command.Collection<?>Delegates to the getResult method of the command.protected booleanprepare()Returns whether the command can execute.voidredo()Delegates to the redo method of the command.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.voidundo()Delegates to the undo method of the command.Methods inherited from class org.eclipse.emf.common.command.AbstractCommand
canExecute, chain, setDescription, setLabel
-
Field Details
-
command
The command for which this is a proxy or decorator.
-
-
Constructor Details
-
CommandWrapper
Creates a decorator instance for the given command.- Parameters:
command- the command to wrap.
-
CommandWrapper
Creates a decorator instance with the given label for the given command.- Parameters:
label- the label of the wrappercommand- the command to wrap.
-
CommandWrapper
Creates a decorator instance with the given label and description for the given command.- Parameters:
label- the label of the wrapperdescription- the description of the wrappercommand- the command to wrap.
-
CommandWrapper
protected CommandWrapper()Creates a commandless proxy instance. The wrapped command will be created by acreateCommand()callback. Since a proxy command like this is pointless unless you override some method, this constructor is protected. -
CommandWrapper
Creates a commandless proxy instance, with the given label. The command will be created by acreateCommand()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
Creates a commandless proxy instance, with the given label and description. The command will be created by acreateCommand()callback. Since a proxy command like this is pointless unless you override some method, this constructor is protected.- Parameters:
label- the label of the wrapperdescription- the description of the wrapper
-
-
Method Details
-
getCommand
Returns the command for which this is a proxy or decorator. This may benullbeforecreateCommand()is called.- Returns:
- the command for which this is a proxy or decorator.
-
createCommand
Create the command being proxied. This implementation just returnnull. It is called byprepare().- Returns:
- the command being proxied.
-
prepare
protected boolean prepare()Returns whether the command can execute. This implementation creates the command being proxied usingcreateCommand(), if the command wasn't given in the constructor.- Overrides:
preparein classAbstractCommand- 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:
canUndoin interfaceCommand- Overrides:
canUndoin classAbstractCommand- Returns:
true.
-
undo
public void undo()Delegates to the undo method of the command.- Specified by:
undoin interfaceCommand- Overrides:
undoin classAbstractCommand
-
redo
public void redo()Delegates to the redo method of the command. -
getResult
Delegates to the getResult method of the command.- Specified by:
getResultin interfaceCommand- Overrides:
getResultin classAbstractCommand- Returns:
- the result.
-
getAffectedObjects
Delegates to the getAffectedObjects method of the command.- Specified by:
getAffectedObjectsin interfaceCommand- Overrides:
getAffectedObjectsin classAbstractCommand- Returns:
- the result.
-
getLabel
Delegates to the getLabel method of the command.- Specified by:
getLabelin interfaceCommand- Overrides:
getLabelin classAbstractCommand- Returns:
- the label.
-
getDescription
Delegates to the getDescription method of the command.- Specified by:
getDescriptionin interfaceCommand- Overrides:
getDescriptionin classAbstractCommand- Returns:
- the description.
-
dispose
public void dispose()Delegates to the dispose method of the command.- Specified by:
disposein interfaceCommand- Overrides:
disposein classAbstractCommand
-
toString
Description copied from class:AbstractCommandReturns an abbreviated name using this object's own class' name, without package qualification, followed by a space separated list of field:value pairs.- Overrides:
toStringin classAbstractCommand- Returns:
- string representation.
-