public class ProgressCompoundCommand
extends org.eclipse.emf.common.command.CompoundCommand
CompoundCommand
which reports progress.Constructor and Description |
---|
ProgressCompoundCommand(int resultIndex,
IProgressMonitorProvider monitor)
Creates an empty instance with the given result index.
|
Modifier and Type | Method and 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 returns
true ,
if command. returns true;
otherwise, it simply calls
command.
and returns false . |
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
CompoundCommand.resultIndex . |
List<org.eclipse.emf.common.command.Command> |
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
CompoundCommand.resultIndex . |
String |
getLabel()
Determines the label by composing the labels of the commands in the list;
this is affected by the setting of
CompoundCommand.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
CompoundCommand.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() |
void |
undo()
Calls
Command.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,
or this , if there are multiple commands;
this command is dispose() d in the first two cases. |
public ProgressCompoundCommand(int resultIndex, IProgressMonitorProvider monitor)
resultIndex
- the CompoundCommand.resultIndex
.monitor
- the progress monitorpublic boolean isEmpty()
isEmpty
in class org.eclipse.emf.common.command.CompoundCommand
public List<org.eclipse.emf.common.command.Command> getCommandList()
getCommandList
in class org.eclipse.emf.common.command.CompoundCommand
public int getResultIndex()
getResultIndex
in class org.eclipse.emf.common.command.CompoundCommand
CompoundCommand.LAST_COMMAND_ALL
,
CompoundCommand.MERGE_COMMAND_ALL
protected boolean prepare()
AbstractCommand.isExecutable
can be cached.
An empty command list causes false
to be returned.prepare
in class org.eclipse.emf.common.command.CompoundCommand
public void execute()
Command.execute()
for each command in the list.execute
in interface org.eclipse.emf.common.command.Command
execute
in class org.eclipse.emf.common.command.CompoundCommand
public boolean canUndo()
false
if any of the commands return false
for Command.canUndo()
.canUndo
in interface org.eclipse.emf.common.command.Command
canUndo
in class org.eclipse.emf.common.command.CompoundCommand
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 org.eclipse.emf.common.command.Command
undo
in class org.eclipse.emf.common.command.CompoundCommand
public void redo()
Command.redo()
for each command in the list.redo
in interface org.eclipse.emf.common.command.Command
redo
in class org.eclipse.emf.common.command.CompoundCommand
public Collection<?> getResult()
CompoundCommand.resultIndex
.getResult
in interface org.eclipse.emf.common.command.Command
getResult
in class org.eclipse.emf.common.command.CompoundCommand
protected Collection<?> getMergedResultCollection()
getMergedResultCollection
in class org.eclipse.emf.common.command.CompoundCommand
public Collection<?> getAffectedObjects()
CompoundCommand.resultIndex
.getAffectedObjects
in interface org.eclipse.emf.common.command.Command
getAffectedObjects
in class org.eclipse.emf.common.command.CompoundCommand
protected Collection<?> getMergedAffectedObjectsCollection()
getMergedAffectedObjectsCollection
in class org.eclipse.emf.common.command.CompoundCommand
public String getLabel()
CompoundCommand.resultIndex
.getLabel
in interface org.eclipse.emf.common.command.Command
getLabel
in class org.eclipse.emf.common.command.CompoundCommand
public String getDescription()
CompoundCommand.resultIndex
.getDescription
in interface org.eclipse.emf.common.command.Command
getDescription
in class org.eclipse.emf.common.command.CompoundCommand
public void append(org.eclipse.emf.common.command.Command command)
append
in class org.eclipse.emf.common.command.CompoundCommand
command
- the command to append.public boolean appendAndExecute(org.eclipse.emf.common.command.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.
appendAndExecute
in class org.eclipse.emf.common.command.CompoundCommand
command
- the command.public boolean appendIfCanExecute(org.eclipse.emf.common.command.Command command)
true
,
if command.canExecute()
returns true;
otherwise, it simply calls
command.dispose()
and returns false
.appendIfCanExecute
in class org.eclipse.emf.common.command.CompoundCommand
command
- the command.public void dispose()
Command.dispose()
for each command in the list.dispose
in interface org.eclipse.emf.common.command.Command
dispose
in class org.eclipse.emf.common.command.CompoundCommand
public org.eclipse.emf.common.command.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.
unwrap
in class org.eclipse.emf.common.command.CompoundCommand
public String toString()
toString
in class org.eclipse.emf.common.command.CompoundCommand
Copyright © 2019. All rights reserved.