public abstract class AbstractCommand extends java.lang.Object implements ICommand
execute()
,
undo()
, and redo()
methods. Concrete
subclasses must provide a definition of the doExecute()
method
to perform some operation. If a concrete command is to be undoable, the
subclass must override the isUndoable()
and
doUndo()
methods. If a concrete command is to be redoable, the
subclass must override the isRedoable()
and doRedo() methods.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.
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractCommand(java.lang.String label)
Creates a new command with the specified label.
|
Modifier and Type | Method and Description |
---|---|
ICommand |
compose(ICommand command)
Composes this command with the specified command by creating a composite
command composed of this command and the specified command.
|
protected abstract CommandResult |
doExecute(org.eclipse.core.runtime.IProgressMonitor progressMonitor)
Performs the actual work of executing this command.
|
protected CommandResult |
doRedo()
Performs the actual work of redoing this command.
|
protected CommandResult |
doUndo()
Performs the actual work of undoing this command.
|
void |
execute(org.eclipse.core.runtime.IProgressMonitor progressMonitor)
Executes this command.
|
java.util.Collection |
getAffectedObjects()
Retrieves the collection of objects that would be affected if this
command were executed, undone, or redone.
|
CommandResult |
getCommandResult()
Retrieves the value of the
result 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 void |
handle(java.lang.Exception exception)
Handles the specified exception.
|
boolean |
isExecutable()
Retrieves a Boolean indicating whether this command can be executed.
|
boolean |
isRedoable()
Retrieves a Boolean indicating whether this command can be redone.
|
boolean |
isUndoable()
Retrieves a Boolean indicating whether this command can be undone.
|
protected CommandResult |
newCancelledCommandResult()
Creates a new command result with an ERROR status and no return value.
|
protected CommandResult |
newErrorCommandResult(java.lang.String errorMessage)
Creates a new command result with an ERROR status, a COMMAND_FAILURE
status code, and no return value.
|
protected CommandResult |
newOKCommandResult()
Creates a new command result with an OK status.
|
protected CommandResult |
newOKCommandResult(java.lang.Object returnValue)
Creates a new command result with an OK status and the specified return
value.
|
void |
redo()
Redoes this command.
|
protected void |
setResult(CommandResult result)
Sets the
result instance variable to the specified value. |
void |
undo()
Undoes this command.
|
protected static final java.lang.String EMPTY_STRING
protected static final java.lang.String CANCELLED_MESSAGE
protected AbstractCommand(java.lang.String label)
label
- The label for the new command.public java.lang.String getLabel()
label
instance variable.getLabel
in interface ICommand
label
instance variable.ICommand.getLabel()
public final CommandResult getCommandResult()
result
instance variable.getCommandResult
in interface ICommand
result
instance variable.ICommand.getCommandResult()
protected final void setResult(CommandResult result)
result
instance variable to the specified value.result
- The new value for the result
instance variable.public java.util.Collection getAffectedObjects()
getAffectedObjects
in interface ICommand
ICommand.getAffectedObjects()
protected java.lang.String getPluginId()
public ICommand compose(ICommand command)
compose
in interface ICommand
command
- The command with which to compose this command.ICommand.compose(ICommand)
public boolean isExecutable()
isExecutable
in interface ICommand
true
.ICommand.isExecutable()
public boolean isRedoable()
isRedoable
in interface ICommand
false
.ICommand.isRedoable()
public boolean isUndoable()
isUndoable
in interface ICommand
false
.ICommand.isUndoable()
public 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)
public void redo()
redo
in interface ICommand
ICommand.redo()
public void undo()
undo
in interface ICommand
ICommand.undo()
protected CommandResult newOKCommandResult()
protected CommandResult newOKCommandResult(java.lang.Object returnValue)
returnValue
- The return value for the new command result.protected CommandResult newCancelledCommandResult()
protected CommandResult newErrorCommandResult(java.lang.String errorMessage)
errorMessage
- error messageprotected void handle(java.lang.Exception exception)
exception
- The exception to be handled.protected abstract CommandResult doExecute(org.eclipse.core.runtime.IProgressMonitor progressMonitor)
progressMonitor
- The object that monitors the progress of this command
execution. May be
NullProgressMonitor
if the
command should be executed without monitoring its progress.protected CommandResult doRedo()
java.lang.UnsupportedOperationException
- If this command isn't redoable.protected CommandResult doUndo()
java.lang.UnsupportedOperationException
- If this command isn't undoable.