Class ProgressCompoundCommand
- java.lang.Object
-
- org.eclipse.emf.common.command.AbstractCommand
-
- org.eclipse.emf.common.command.CompoundCommand
-
- org.eclipse.emf.ecp.edit.spi.swt.commands.ProgressCompoundCommand
-
- All Implemented Interfaces:
org.eclipse.emf.common.command.Command
public class ProgressCompoundCommand extends org.eclipse.emf.common.command.CompoundCommand
Extension of theCompoundCommand
which reports progress.- Since:
- 1.11
- Author:
- Johannes Faltermeier
-
-
Constructor Summary
Constructors Constructor Description ProgressCompoundCommand(int resultIndex, IProgressMonitorProvider monitor)
Creates an empty instance with the given result index.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
append(org.eclipse.emf.common.command.Command command)
Adds a command to this compound command's list of commands.boolean
appendAndExecute(org.eclipse.emf.common.command.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(org.eclipse.emf.common.command.Command command)
Adds a command to this compound command's the list of commands and returnstrue
, ifcommand.
returns true; otherwise, it simply callscanExecute()
command.
and returnsdispose()
false
.boolean
canUndo()
Returnsfalse
if any of the commands returnfalse
forCommand.canUndo()
.void
dispose()
CallsCommand.dispose()
for each command in the list.void
execute()
CallsCommand.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 ofCompoundCommand.resultIndex
.java.util.List<org.eclipse.emf.common.command.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 ofCompoundCommand.resultIndex
.java.lang.String
getLabel()
Determines the label by composing the labels of the commands in the list; this is affected by the setting ofCompoundCommand.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 ofCompoundCommand.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 thatAbstractCommand.isExecutable
can be cached.void
redo()
CallsCommand.redo()
for each command in the list.java.lang.String
toString()
void
undo()
CallsCommand.undo()
for each command in the list, in reverse order.org.eclipse.emf.common.command.Command
unwrap()
Returns one of three things:UnexecutableCommand.INSTANCE
, if there are no commands, the one command, if there is exactly one command, orthis
, if there are multiple commands; this command isdispose()
d in the first two cases.
-
-
-
Constructor Detail
-
ProgressCompoundCommand
public ProgressCompoundCommand(int resultIndex, IProgressMonitorProvider monitor)
Creates an empty instance with the given result index.- Parameters:
resultIndex
- theCompoundCommand.resultIndex
.monitor
- the progress monitor
-
-
Method Detail
-
isEmpty
public boolean isEmpty()
Returns whether there are commands in the list.- Overrides:
isEmpty
in classorg.eclipse.emf.common.command.CompoundCommand
- Returns:
- whether there are commands in the list.
-
getCommandList
public java.util.List<org.eclipse.emf.common.command.Command> getCommandList()
Returns an unmodifiable view of the commands in the list.- Overrides:
getCommandList
in classorg.eclipse.emf.common.command.CompoundCommand
- Returns:
- an unmodifiable view of the commands in the list.
-
getResultIndex
public int getResultIndex()
Returns the index of the command whose result and affected objects are forwarded. Negative values have special meaning, as defined by the static constants.- Overrides:
getResultIndex
in classorg.eclipse.emf.common.command.CompoundCommand
- Returns:
- the index of the command whose result and affected objects are forwarded.
- See Also:
CompoundCommand.LAST_COMMAND_ALL
,CompoundCommand.MERGE_COMMAND_ALL
-
prepare
protected boolean prepare()
Returns whether all the commands can execute so thatAbstractCommand.isExecutable
can be cached. An empty command list causesfalse
to be returned.- Overrides:
prepare
in classorg.eclipse.emf.common.command.CompoundCommand
- Returns:
- whether all the commands can execute.
-
execute
public void execute()
CallsCommand.execute()
for each command in the list.- Specified by:
execute
in interfaceorg.eclipse.emf.common.command.Command
- Overrides:
execute
in classorg.eclipse.emf.common.command.CompoundCommand
-
canUndo
public boolean canUndo()
Returnsfalse
if any of the commands returnfalse
forCommand.canUndo()
.- Specified by:
canUndo
in interfaceorg.eclipse.emf.common.command.Command
- Overrides:
canUndo
in classorg.eclipse.emf.common.command.CompoundCommand
- Returns:
false
if any of the commands returnfalse
forcanUndo
.
-
undo
public void undo()
CallsCommand.undo()
for each command in the list, in reverse order.- Specified by:
undo
in interfaceorg.eclipse.emf.common.command.Command
- Overrides:
undo
in classorg.eclipse.emf.common.command.CompoundCommand
-
redo
public void redo()
CallsCommand.redo()
for each command in the list.- Specified by:
redo
in interfaceorg.eclipse.emf.common.command.Command
- Overrides:
redo
in classorg.eclipse.emf.common.command.CompoundCommand
-
getResult
public java.util.Collection<?> getResult()
Determines the result by composing the results of the commands in the list; this is affected by the setting ofCompoundCommand.resultIndex
.- Specified by:
getResult
in interfaceorg.eclipse.emf.common.command.Command
- Overrides:
getResult
in classorg.eclipse.emf.common.command.CompoundCommand
- Returns:
- the result.
-
getMergedResultCollection
protected java.util.Collection<?> getMergedResultCollection()
Returns the merged collection of all command results.- Overrides:
getMergedResultCollection
in classorg.eclipse.emf.common.command.CompoundCommand
- Returns:
- the merged collection of all command results.
-
getAffectedObjects
public 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 ofCompoundCommand.resultIndex
.- Specified by:
getAffectedObjects
in interfaceorg.eclipse.emf.common.command.Command
- Overrides:
getAffectedObjects
in classorg.eclipse.emf.common.command.CompoundCommand
- Returns:
- the affected objects.
-
getMergedAffectedObjectsCollection
protected java.util.Collection<?> getMergedAffectedObjectsCollection()
Returns the merged collection of all command affected objects.- Overrides:
getMergedAffectedObjectsCollection
in classorg.eclipse.emf.common.command.CompoundCommand
- Returns:
- the merged collection of all command affected objects.
-
getLabel
public java.lang.String getLabel()
Determines the label by composing the labels of the commands in the list; this is affected by the setting ofCompoundCommand.resultIndex
.- Specified by:
getLabel
in interfaceorg.eclipse.emf.common.command.Command
- Overrides:
getLabel
in classorg.eclipse.emf.common.command.CompoundCommand
- Returns:
- the label.
-
getDescription
public java.lang.String getDescription()
Determines the description by composing the descriptions of the commands in the list; this is affected by the setting ofCompoundCommand.resultIndex
.- Specified by:
getDescription
in interfaceorg.eclipse.emf.common.command.Command
- Overrides:
getDescription
in classorg.eclipse.emf.common.command.CompoundCommand
- Returns:
- the description.
-
append
public void append(org.eclipse.emf.common.command.Command command)
Adds a command to this compound command's list of commands.- Overrides:
append
in classorg.eclipse.emf.common.command.CompoundCommand
- Parameters:
command
- the command to append.
-
appendAndExecute
public boolean appendAndExecute(org.eclipse.emf.common.command.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. A typical use for this is to execute commands created during the execution of another command, e.g.,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.- Overrides:
appendAndExecute
in classorg.eclipse.emf.common.command.CompoundCommand
- Parameters:
command
- the command.- Returns:
- whether the command was successfully executed and appended.
-
appendIfCanExecute
public boolean appendIfCanExecute(org.eclipse.emf.common.command.Command command)
Adds a command to this compound command's the list of commands and returnstrue
, ifcommand.
returns true; otherwise, it simply callscanExecute()
command.
and returnsdispose()
false
.- Overrides:
appendIfCanExecute
in classorg.eclipse.emf.common.command.CompoundCommand
- Parameters:
command
- the command.- Returns:
- whether the command was executed and appended.
-
dispose
public void dispose()
CallsCommand.dispose()
for each command in the list.- Specified by:
dispose
in interfaceorg.eclipse.emf.common.command.Command
- Overrides:
dispose
in classorg.eclipse.emf.common.command.CompoundCommand
-
unwrap
public org.eclipse.emf.common.command.Command unwrap()
Returns one of three things:UnexecutableCommand.INSTANCE
, if there are no commands, the one command, if there is exactly one command, orthis
, if there are multiple commands; this command isdispose()
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.- Overrides:
unwrap
in classorg.eclipse.emf.common.command.CompoundCommand
- Returns:
- the unwrapped command.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classorg.eclipse.emf.common.command.CompoundCommand
-
-