|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.emf.common.command.AbstractCommand
org.eclipse.emf.common.command.CompoundCommand
org.eclipse.emf.common.command.StrictCompoundCommand
public class StrictCompoundCommand
A composite command which assumes that later commands in the list
may depend on the results and side-effects of earlier commands in the list.
Because of this, it must implement Command.canExecute()
more carefully,
i.e., in order to determine canExecute for the composite, it doesn't simply test each command.
It tests the first command to see if it can execute;
then, if there is another command in the list, it checks if the first command can undo and then goes ahead and executes it!
This process is repeated until the last command that is not followed by another, which then determines the final result.
(For efficiency, when this processing gets to the last command, that command is tested for canUndo too and that result is cached.)
All the commands that have been executed are then undone, if isPessimistic
is true
;
by default it's false
.
It is important for all but the last command to have no visible side-effect!
Multiple commands with visible side-effects must be composed into a single command using just a CompoundCommand
and that composite could be the last command of a strict composite.
Here is an example of how this can be used in conjunction with a CommandWrapper
.
Command strictCompoundCommand = new StrictCompoundCommand(); Command copyCommand = new CopyCommand(...); strictCompoundCommand.add(copyCommand); Command addCommand = new CommandWrapper() { public Command createCommand() { new AddCommand(parent, copyCommand.getResult()); } }; strictCompoundCommand.append(addCommand);Here the add command won't know which command to create until it has the result of the copy command. The proxy makes sure the creation of the add command is deferred and the strict composite ensures that execution dependencies are met.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class org.eclipse.emf.common.command.AbstractCommand |
---|
AbstractCommand.NonDirtying |
Field Summary | |
---|---|
protected boolean |
isPessimistic
Whether commands that have been tentatively executed need to be undone. |
protected boolean |
isUndoable
The result for Command.canUndo() . |
protected int |
rightMostExecutedCommandIndex
Remember to call redo instead of execute for any command at or before this index in the list. |
Fields inherited from class org.eclipse.emf.common.command.CompoundCommand |
---|
commandList, LAST_COMMAND_ALL, MERGE_COMMAND_ALL, resultIndex |
Fields inherited from class org.eclipse.emf.common.command.AbstractCommand |
---|
description, isExecutable, isPrepared, label |
Constructor Summary | |
---|---|
StrictCompoundCommand()
Creates an empty instance. |
|
StrictCompoundCommand(java.util.List<Command> commandList)
Creates an instance with the given command list. |
|
StrictCompoundCommand(java.lang.String label)
Creates an instance with the given label. |
|
StrictCompoundCommand(java.lang.String label,
java.util.List<Command> commandList)
Creates an instance with the given label and command list. |
|
StrictCompoundCommand(java.lang.String label,
java.lang.String description)
Creates an instance with the given label and description. |
|
StrictCompoundCommand(java.lang.String label,
java.lang.String description,
java.util.List<Command> commandList)
Creates an instance with the given label, description, and command list. |
Method Summary | |
---|---|
boolean |
appendAndExecute(Command command)
Checks if the command can execute; if so, it is executed, appended to the list, and true is returned,
if not, it is just disposed and false is returned. |
void |
execute()
Calls Command.execute() for each command in the list,
but makes sure to call redo for any commands that were previously executed to compute canExecute. |
protected boolean |
prepare()
Returns false if any command on the list returns false for Command.canExecute() ,
or if some command before the last one can't be undone and hence we can't test all the commands for executability. |
void |
redo()
Calls Command.redo() for each command in the list. |
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()
Calls Command.undo() for each command in the list. |
Methods inherited from class org.eclipse.emf.common.command.CompoundCommand |
---|
append, appendIfCanExecute, canUndo, dispose, getAffectedObjects, getCommandList, getDescription, getLabel, getMergedAffectedObjectsCollection, getMergedResultCollection, getResult, getResultIndex, isEmpty, unwrap |
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 |
---|
protected boolean isUndoable
Command.canUndo()
.
protected boolean isPessimistic
protected int rightMostExecutedCommandIndex
Constructor Detail |
---|
public StrictCompoundCommand()
public StrictCompoundCommand(java.lang.String label)
label
- the label.public StrictCompoundCommand(java.lang.String label, java.lang.String description)
label
- the label.description
- the description.public StrictCompoundCommand(java.util.List<Command> commandList)
commandList
- the list of commands.public StrictCompoundCommand(java.lang.String label, java.util.List<Command> commandList)
label
- the label.commandList
- the list of commands.public StrictCompoundCommand(java.lang.String label, java.lang.String description, java.util.List<Command> commandList)
label
- the label.description
- the description.commandList
- the list of commands.Method Detail |
---|
protected boolean prepare()
false
if any command on the list returns false
for Command.canExecute()
,
or if some command before the last one can't be undone and hence we can't test all the commands for executability.
prepare
in class CompoundCommand
public void execute()
Command.execute()
for each command in the list,
but makes sure to call redo for any commands that were previously executed to compute canExecute.
In the case that isPessimistic
is false, only the last command will be executed
since the others will have been executed but not undone during prepare()
.
execute
in interface Command
execute
in class CompoundCommand
public void undo()
Command.undo()
for each command in the list.
In the case that isPessimistic
is false, only the last command will be undone
since the others will have been executed and not undo during prepare()
.
undo
in interface Command
undo
in class CompoundCommand
public void redo()
Command.redo()
for each command in the list.
In the case that isPessimistic
is false, only the last command will be redone
since the others will have been executed and not undo during prepare()
.
redo
in interface Command
redo
in class CompoundCommand
public boolean appendAndExecute(Command command)
true
is returned,
if not, it is just disposed and false
is returned.
A typical use for this is to execute commands created during the execution of another command, e.g.,
class MyCommand extends AbstractCommand { protected Command subcommand; //... public void execute() { // ... StrictCompoundCommand subcommands = new StrictCompoundCommand(); subcommands.appendAndExecute(new AddCommand(...)); if (condition) subcommands.appendAndExecute(new AddCommand(...)); subcommand = subcommands.unwrap(); } public void undo() { // ... subcommand.undo(); } public void redo() { // ... subcommand.redo(); } public void dispose() { // ... if (subcommand != null) { subcommand.dispose(); } } }
appendAndExecute
in class CompoundCommand
command
- the command.
public java.lang.String toString()
AbstractCommand
toString
in class CompoundCommand
|
Copyright 2001-2006 IBM Corporation and others. All Rights Reserved. |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |