| |||||||||||
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
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 inherited from class org.eclipse.emf.common.command.AbstractCommand |
AbstractCommand.NonDirtying |
Field Summary | |
protected List | 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,
List commandList)
Creates an instance with the given result index and list. | |
CompoundCommand(int resultIndex,
String label)
Creates an instance with the given result index and label. | |
CompoundCommand(int resultIndex,
String label,
List commandList)
Creates an instance with the given resultIndex, label, and list. | |
CompoundCommand(int resultIndex,
String label,
String description)
Creates an instance with the given result index, label, and description. | |
CompoundCommand(int resultIndex,
String label,
String description,
List commandList)
Creates an instance with the given result index, label, description, and list. | |
CompoundCommand(List commandList)
Creates an instance with the given list. | |
CompoundCommand(String label)
Creates an instance with the given label. | |
CompoundCommand(String label,
List commandList)
Creates instance with the given label and list. | |
CompoundCommand(String label,
String description)
Creates an instance with the given label and description. | |
CompoundCommand(String label,
String description,
List 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. |
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. |
List | getCommandList()
Returns an unmodifiable view of the commands in the list. |
String | getDescription()
Determines the description by composing the descriptions of the commands in the list; this is affected by the setting of resultIndex. |
String | getLabel()
Determines the label by composing the labels of the commands in the list; this is affected by the setting of resultIndex. |
protected Collection | getMergedAffectedObjectsCollection()
Returns the merged collection of all command affected objects. |
protected Collection | getMergedResultCollection()
Returns the merged collection of all command results. |
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. |
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 List commandList
public static final int LAST_COMMAND_ALL
public static final int MERGE_COMMAND_ALL
protected int resultIndex
Constructor Detail |
public CompoundCommand()
public CompoundCommand(String label)
public CompoundCommand(String label, String description)
public CompoundCommand(List commandList)
public CompoundCommand(String label, List commandList)
public CompoundCommand(String label, String description, List commandList)
public CompoundCommand(int resultIndex)
public CompoundCommand(int resultIndex, String label)
public CompoundCommand(int resultIndex, String label, String description)
public CompoundCommand(int resultIndex, List commandList)
public CompoundCommand(int resultIndex, String label, List commandList)
public CompoundCommand(int resultIndex, String label, String description, List commandList)
Method Detail |
public boolean isEmpty()
public List getCommandList()
public int getResultIndex()
protected boolean prepare()
public void execute()
public boolean canUndo()
public void undo()
public void redo()
public Collection getResult()
protected Collection getMergedResultCollection()
public Collection getAffectedObjects()
protected Collection getMergedAffectedObjectsCollection()
public String getLabel()
public String getDescription()
public void append(Command command)
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.
public boolean appendIfCanExecute(Command command)
public void dispose()
public Command unwrap()
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 String toString()
|
Copyright 2001-2004 IBM Corporation and others. All Rights Reserved. | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |