|
||||||||||
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
public class CompoundCommand
A command that comprises a sequence of subcommands. Derived classes can control the way results are accumulated from the individual commands; the default behaviour is to return the result of the last command.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class org.eclipse.emf.common.command.AbstractCommand |
---|
AbstractCommand.NonDirtying |
Field Summary | |
---|---|
protected java.util.List<Command> |
commandList
The list of subcommands. |
static int |
LAST_COMMAND_ALL
When resultIndex is set to this,
getResult() and getAffectedObjects() are delegated to the last command, if any, in the list. |
static int |
MERGE_COMMAND_ALL
When resultIndex is set to this,
getResult() and getAffectedObjects()
are set to the result of merging the corresponding collection of each command in the list. |
protected int |
resultIndex
The index of the command whose result and affected objects are forwarded. |
Fields inherited from class org.eclipse.emf.common.command.AbstractCommand |
---|
description, isExecutable, isPrepared, label |
Constructor Summary | |
---|---|
CompoundCommand()
Creates an empty instance. |
|
CompoundCommand(int resultIndex)
Creates an empty instance with the given result index. |
|
CompoundCommand(int resultIndex,
java.util.List<Command> commandList)
Creates an instance with the given result index and list. |
|
CompoundCommand(int resultIndex,
java.lang.String label)
Creates an instance with the given result index and label. |
|
CompoundCommand(int resultIndex,
java.lang.String label,
java.util.List<Command> commandList)
Creates an instance with the given resultIndex, label, and list. |
|
CompoundCommand(int resultIndex,
java.lang.String label,
java.lang.String description)
Creates an instance with the given result index, label, and description. |
|
CompoundCommand(int resultIndex,
java.lang.String label,
java.lang.String description,
java.util.List<Command> commandList)
Creates an instance with the given result index, label, description, and list. |
|
CompoundCommand(java.util.List<Command> commandList)
Creates an instance with the given list. |
|
CompoundCommand(java.lang.String label)
Creates an instance with the given label. |
|
CompoundCommand(java.lang.String label,
java.util.List<Command> commandList)
Creates instance with the given label and list. |
|
CompoundCommand(java.lang.String label,
java.lang.String description)
Creates an instance with the given label and description. |
|
CompoundCommand(java.lang.String label,
java.lang.String description,
java.util.List<Command> commandList)
Creates an instance with the given label, description, and list. |
Method Summary | |
---|---|
void |
append(Command command)
Adds a command to this compound command's list of commands. |
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. |
boolean |
appendIfCanExecute(Command command)
Adds a command to this compound command's the list of commands and returns true ,
if command. |
boolean |
canUndo()
Returns false if any of the commands return false for Command.canUndo() . |
void |
dispose()
Calls Command.dispose() for each command in the list. |
void |
execute()
Calls Command.execute() for each command in the list. |
java.util.Collection<?> |
getAffectedObjects()
Determines the affected objects by composing the affected objects of the commands in the list; this is affected by the setting of resultIndex . |
java.util.List<Command> |
getCommandList()
Returns an unmodifiable view of the commands in the list. |
java.lang.String |
getDescription()
Determines the description by composing the descriptions of the commands in the list; this is affected by the setting of resultIndex . |
java.lang.String |
getLabel()
Determines the label by composing the labels of the commands in the list; this is affected by the setting of resultIndex . |
protected java.util.Collection<?> |
getMergedAffectedObjectsCollection()
Returns the merged collection of all command affected objects. |
protected java.util.Collection<?> |
getMergedResultCollection()
Returns the merged collection of all command results. |
java.util.Collection<?> |
getResult()
Determines the result by composing the results of the commands in the list; this is affected by the setting of resultIndex . |
int |
getResultIndex()
Returns the index of the command whose result and affected objects are forwarded. |
boolean |
isEmpty()
Returns whether there are commands in the list. |
protected boolean |
prepare()
Returns whether all the commands can execute so that AbstractCommand.isExecutable can be cached. |
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, in reverse order. |
Command |
unwrap()
Returns one of three things: UnexecutableCommand.INSTANCE , if there are no commands,
the one command, if there is exactly one command,
or this , if there are multiple commands;
this command is dispose() d in the first two cases. |
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 java.util.List<Command> commandList
public static final int LAST_COMMAND_ALL
resultIndex
is set to this,
getResult()
and getAffectedObjects()
are delegated to the last command, if any, in the list.
public static final int MERGE_COMMAND_ALL
resultIndex
is set to this,
getResult()
and getAffectedObjects()
are set to the result of merging the corresponding collection of each command in the list.
protected int resultIndex
Constructor Detail |
---|
public CompoundCommand()
public CompoundCommand(java.lang.String label)
label
- the label.public CompoundCommand(java.lang.String label, java.lang.String description)
label
- the label.description
- the description.public CompoundCommand(java.util.List<Command> commandList)
commandList
- the list of commands.public CompoundCommand(java.lang.String label, java.util.List<Command> commandList)
label
- the label.commandList
- the list of commands.public CompoundCommand(java.lang.String label, java.lang.String description, java.util.List<Command> commandList)
label
- the label.description
- the description.commandList
- the list of commands.public CompoundCommand(int resultIndex)
resultIndex
- the resultIndex
.public CompoundCommand(int resultIndex, java.lang.String label)
resultIndex
- the resultIndex
.label
- the label.public CompoundCommand(int resultIndex, java.lang.String label, java.lang.String description)
resultIndex
- the resultIndex
.label
- the label.description
- the description.public CompoundCommand(int resultIndex, java.util.List<Command> commandList)
resultIndex
- the resultIndex
.commandList
- the list of commands.public CompoundCommand(int resultIndex, java.lang.String label, java.util.List<Command> commandList)
resultIndex
- the resultIndex
.label
- the label.commandList
- the list of commands.public CompoundCommand(int resultIndex, java.lang.String label, java.lang.String description, java.util.List<Command> commandList)
resultIndex
- the resultIndex
.label
- the label.description
- the description.commandList
- the list of commands.Method Detail |
---|
public boolean isEmpty()
public java.util.List<Command> getCommandList()
public int getResultIndex()
LAST_COMMAND_ALL
,
MERGE_COMMAND_ALL
protected boolean prepare()
AbstractCommand.isExecutable
can be cached.
An empty command list causes false
to be returned.
prepare
in class AbstractCommand
public void execute()
Command.execute()
for each command in the list.
public boolean canUndo()
false
if any of the commands return false
for Command.canUndo()
.
canUndo
in interface Command
canUndo
in class AbstractCommand
false
if any of the commands return false
for canUndo
.public void undo()
Command.undo()
for each command in the list, in reverse order.
undo
in interface Command
undo
in class AbstractCommand
public void redo()
Command.redo()
for each command in the list.
public java.util.Collection<?> getResult()
resultIndex
.
getResult
in interface Command
getResult
in class AbstractCommand
protected java.util.Collection<?> getMergedResultCollection()
public java.util.Collection<?> getAffectedObjects()
resultIndex
.
getAffectedObjects
in interface Command
getAffectedObjects
in class AbstractCommand
protected java.util.Collection<?> getMergedAffectedObjectsCollection()
public java.lang.String getLabel()
resultIndex
.
getLabel
in interface Command
getLabel
in class AbstractCommand
public java.lang.String getDescription()
resultIndex
.
getDescription
in interface Command
getDescription
in class AbstractCommand
public void append(Command command)
command
- the command to append.public boolean appendAndExecute(Command command)
class MyCommand extends CommandBase { protected Command subcommand; //... public void execute() { // ... Compound subcommands = new CompoundCommand(); 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(); } } }Another use is in an execute override of compound command itself:
class MyCommand extends CompoundCommand { public void execute() { // ... appendAndExecute(new AddCommand(...)); if (condition) appendAndExecute(new AddCommand(...)); } }Note that appending commands will modify what getResult and getAffectedObjects return, so you may want to set the resultIndex flag.
command
- the command.
public boolean appendIfCanExecute(Command command)
true
,
if command.canExecute()
returns true;
otherwise, it simply calls command.dispose()
and returns false
.
command
- the command.
public void dispose()
Command.dispose()
for each command in the list.
dispose
in interface Command
dispose
in class AbstractCommand
public Command unwrap()
UnexecutableCommand.INSTANCE
, if there are no commands,
the one command, if there is exactly one command,
or this
, if there are multiple commands;
this command is dispose()
d in the first two cases.
You should only unwrap a compound command if you created it for that purpose, e.g.,
CompoundCommand subcommands = new CompoundCommand(); subcommands.append(x); if (condition) subcommands.append(y); Command result = subcommands.unwrap();is a good way to create an efficient accumulated result.
public java.lang.String toString()
AbstractCommand
toString
in class AbstractCommand
|
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 |