public class CompositeCommand extends java.lang.Object implements ICommand
ICommand
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
CANCELLED_MESSAGE
The status message for a cancelled command.
|
protected static java.lang.String |
EMPTY_STRING
The empty string.
|
Constructor and Description |
---|
CompositeCommand(java.lang.String label)
Creates a new composite command with the specified label.
|
CompositeCommand(java.lang.String label,
java.util.List commands)
Creates a new composite command with the specified label and list of
commands.
|
Modifier and Type | Method and Description |
---|---|
ICommand |
compose(ICommand command)
Composes this composite command with the specified command by adding the
specified command to the commands of which this composite command is
composed.
|
void |
execute(org.eclipse.core.runtime.IProgressMonitor progressMonitor)
Executes this composite command by executing each of the commands of
which this composite command is composed.
|
java.util.Collection |
getAffectedObjects()
Retrieves the collection of objects that would be affected if this
composite command were executed, undone, or redone.
|
CommandResult |
getCommandResult()
Retrieves the composite result of executing/undoing/redoing this
composite command.
|
java.util.List |
getCommands()
Retrieves the value of the
commands instance variable. |
java.lang.String |
getLabel()
Retrieves the value of the
label instance variable. |
protected java.lang.String |
getPluginId()
Retrieves the plug-in identifier to be used in command results produced
by this command.
|
protected boolean |
isCanceled()
Gets the canceled state of this command.
|
boolean |
isEmpty()
Returns whether the composite command has zero child commands
|
boolean |
isExecutable()
Retrieves a Boolean value indicating whether this composite command can
be executed.
|
boolean |
isRedoable()
Retrieves a Boolean value indicating whether this composite command can
be redone.
|
boolean |
isUndoable()
Retrieves a Boolean value indicating whether this composite command can
be undone.
|
protected CommandResult |
newCancelledCommandResult()
Creates a new command result with an ERROR status and no return value.
|
void |
redo()
Redoes this composite command by redoing each of the commands of which
this composite command is composed.
|
protected void |
setCanceled(boolean canceled)
Sets the canceled state of this command.
|
void |
undo()
Undoes this composite command by undoing each of the commands of which
this composite command is composed.
|
protected void |
undoCancelledCommands(java.util.List executedCommands)
Cancels the command execution by calling
undo() on all of
the undoable commands that were executed before the composite command was
cancelled. |
ICommand |
unwrap()
Returns the simplest form of this ICommand that is equivalent.
|
protected static final java.lang.String EMPTY_STRING
protected static final java.lang.String CANCELLED_MESSAGE
public CompositeCommand(java.lang.String label)
label
- The label for the new composite command.public CompositeCommand(java.lang.String label, java.util.List commands)
label
- The label for the new composite command.commands
- The initial list of commandspublic final java.util.List getCommands()
commands
instance variable.commands
instance variable.public final java.lang.String getLabel()
label
instance variable.getLabel
in interface ICommand
label
instance variable.ICommand.getLabel()
public CommandResult getCommandResult()
getCommandResult
in interface ICommand
ICommand.getCommandResult()
public final java.util.Collection getAffectedObjects()
getAffectedObjects
in interface ICommand
ICommand.getAffectedObjects()
public final ICommand compose(ICommand command)
compose
in interface ICommand
command
- The command with which to compose this command.this
.ICommand.compose(ICommand)
public final boolean isExecutable()
isExecutable
in interface ICommand
false
if any of the commands of which this
composite command is composed cannot be executed;
true
otherwise.ICommand.isRedoable()
public final boolean isRedoable()
isRedoable
in interface ICommand
false
if any of the commands of which this
composite command is composed cannot be redone; true
otherwise.ICommand.isRedoable()
public final boolean isUndoable()
isUndoable
in interface ICommand
false
if any of the commands of which this
composite command is composed cannot be undone; true
otherwise.ICommand.isRedoable()
public final boolean isEmpty()
public ICommand unwrap()
null
2- if the composite
had a single command, it returns the single command 3- otherwise, it
returns itselfpublic void execute(org.eclipse.core.runtime.IProgressMonitor progressMonitor)
execute
in interface ICommand
progressMonitor
- The object that monitors the progress of this command
execution. May be
NullProgressMonitor
if the
command should be executed without monitoring its progress.ICommand.execute(org.eclipse.core.runtime.IProgressMonitor)
protected void undoCancelledCommands(java.util.List executedCommands)
undo()
on all of
the undoable commands that were executed before the composite command was
cancelled. The commands are undone in the reverse order of execution.executedCommands
- the commands that have been executed and need to be undone.
This method expects that the commands in the list are in the
order in which the commands were executed. They will be undone
in the reverse order.public void redo()
redo
in interface ICommand
ICommand.redo()
public void undo()
undo
in interface ICommand
ICommand.undo()
protected java.lang.String getPluginId()
protected CommandResult newCancelledCommandResult()
protected void setCanceled(boolean canceled)
canceled
- true
if the command was canceled,
false
otherwise.protected boolean isCanceled()
true
if the command was canceled,
false
otherwise.