public class CommandWrapper extends AbstractCommand
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();
}
};
AbstractCommand.NonDirtying| Modifier and Type | Field and Description |
|---|---|
protected Command |
command
The command for which this is a proxy or decorator.
|
description, isExecutable, isPrepared, label| Modifier | Constructor and Description |
|---|---|
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.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
canExecute, chain, setDescription, setLabelprotected Command command
public CommandWrapper(Command command)
command - the command to wrap.protected CommandWrapper(java.lang.String label,
Command command)
label - the label of the wrappercommand - the command to wrap.public CommandWrapper(java.lang.String label,
java.lang.String description,
Command command)
label - the label of the wrapperdescription - the description of the wrappercommand - the command to wrap.protected CommandWrapper()
createCommand() callback.
Since a proxy command like this is pointless unless you override some method, this constructor is protected.protected CommandWrapper(java.lang.String label)
createCommand() callback.
Since a proxy command like this is pointless unless you override some method, this constructor is protected.label - the label of the wrapperprotected CommandWrapper(java.lang.String label,
java.lang.String description)
createCommand() callback.
Since a proxy command like this is pointless unless you override some method, this constructor is protected.label - the label of the wrapperdescription - the description of the wrapperpublic Command getCommand()
null before createCommand() is called.protected Command createCommand()
null.
It is called by prepare().protected boolean prepare()
createCommand(),
if the command wasn't given in the constructor.prepare in class AbstractCommandpublic void execute()
public boolean canUndo()
canUndo in interface CommandcanUndo in class AbstractCommandtrue.public void undo()
undo in interface Commandundo in class AbstractCommandpublic void redo()
public java.util.Collection<?> getResult()
getResult in interface CommandgetResult in class AbstractCommandpublic java.util.Collection<?> getAffectedObjects()
getAffectedObjects in interface CommandgetAffectedObjects in class AbstractCommandpublic java.lang.String getLabel()
getLabel in interface CommandgetLabel in class AbstractCommandpublic java.lang.String getDescription()
getDescription in interface CommandgetDescription in class AbstractCommandpublic void dispose()
dispose in interface Commanddispose in class AbstractCommandpublic java.lang.String toString()
AbstractCommandtoString in class AbstractCommandCopyright © 2018. Licensed under the Eclipse Public License v1.0. All rights reserved.
Submit a bug or feature