|
Runtime | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.core.commands.operations.AbstractOperation
org.eclipse.gmf.runtime.common.core.command.AbstractCommand
org.eclipse.gmf.runtime.common.core.command.CompositeCommand
public class CompositeCommand
An undoable command that is composed of child IUndoableOperation
s
that are not known to modify EMF model resources, but can contain
model-affecting children. Execute, undo, redo and dispose result in execute,
undo, redo and dispose on each child operation. The operation provides a list
of IFile
s that may be modified when the operation is executed,
undone or redone.
The children are explicitly composed by a client before the composite is executed. Children cannot be added or removed after the composite has been executed.
The undo contexts of the composite are a union of the undo contexts of its children.
If a child command returns a cancel or an error status during execution, undo or redo, the remaining child commands are not processed and those that have already been executed are rolled back.
Constructor Summary | |
---|---|
CompositeCommand(java.lang.String label)
Initializes me with a label. |
|
CompositeCommand(java.lang.String label,
java.util.List children)
Initializes me with a label and a list of child operations. |
Method Summary | |
---|---|
void |
add(IUndoableOperation operation)
Adds a child operation to me. |
protected IStatus |
aggregateStatuses(java.util.List statuses)
Creates a suitable aggregate from these statuses. |
protected void |
assertNotExecuted()
Asserts that I have not yet been executed. |
boolean |
canExecute()
I can execute if I am not empty and all of my children can execute. |
boolean |
canRedo()
I can redo if I am not empty and all my children can all be redone. |
boolean |
canUndo()
I can undo if I am not empty and all my children can all be undone. |
static ICommand |
compose(ICommand command,
ICommand next)
Appends a command onto a (possibly) existing composeite of commands. |
ICommand |
compose(IUndoableOperation operation)
Adds command to the list of commands with which this
composite is composed. |
void |
dispose()
Disposes of each of my children. |
protected CommandResult |
doExecuteWithResult(IProgressMonitor progressMonitor,
IAdaptable info)
Implements the execution logic by sequential execution of my children. |
protected CommandResult |
doRedoWithResult(IProgressMonitor progressMonitor,
IAdaptable info)
I redo by asking my children to redo, in forward order. |
protected CommandResult |
doUndoWithResult(IProgressMonitor progressMonitor,
IAdaptable info)
I undo by asking my children to undo, in reverse order. |
java.util.List |
getAffectedFiles()
Returns a list containing all of the affected files from ICommand children. |
protected java.util.List |
getChildren()
Obtains my nested operations. |
protected java.util.List |
getReturnValues()
Returns a list containing all of the return values from ICommand children. |
boolean |
isEmpty()
Answers whether or not this composite operation has children. |
protected boolean |
isExecuted()
Answers whether or not I have been executed. |
java.util.Iterator |
iterator()
Obtains an iterator to traverse my child operations. |
java.util.ListIterator |
listIterator()
Obtains an iterator to traverse my child operations in either direction. |
java.util.ListIterator |
listIterator(int index)
Obtains an iterator to traverse my child operations in either direction, starting from the specified index . |
ICommand |
reduce()
Returns the simplest form of this command that is equivalent. |
void |
remove(IUndoableOperation operation)
Removes a child operation from me. |
int |
size()
Queries the number of child operations that I contain. |
Methods inherited from class org.eclipse.gmf.runtime.common.core.command.AbstractCommand |
---|
execute, getCommandResult, internalSetResult, redo, setResult, undo |
Methods inherited from class org.eclipse.core.commands.operations.AbstractOperation |
---|
addContext, getContexts, getLabel, hasContext, removeContext, setLabel, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.eclipse.gmf.runtime.common.core.command.ICommand |
---|
getCommandResult, setLabel |
Methods inherited from interface org.eclipse.core.commands.operations.IUndoableOperation |
---|
addContext, execute, getContexts, getLabel, hasContext, redo, removeContext, undo |
Constructor Detail |
---|
public CompositeCommand(java.lang.String label)
label
- a user-readable labelpublic CompositeCommand(java.lang.String label, java.util.List children)
label
- a user-readable labelchildren
- a list of child IUndoableOperation
sMethod Detail |
---|
public final boolean isEmpty()
isEmpty
in interface ICompositeCommand
true
if the operation does not have children,
false
otherwise.protected java.util.List getChildren()
add(IUndoableOperation)
and
remove(IUndoableOperation)
methods because these maintain the
undo contexts (or, equivalently, using the iterators).
add(IUndoableOperation)
,
remove(IUndoableOperation)
,
iterator()
,
listIterator(int)
public int size()
ICompositeCommand
size
in interface ICompositeCommand
public void add(IUndoableOperation operation)
add
in interface ICompositeCommand
operation
- a new child operation
java.lang.IllegalStateException
- if I have already been successfully executedpublic void remove(IUndoableOperation operation)
Note that I do not dispose an operation when it is removed from
me. Although this is specified in the contract of the
ICompositeOperation
interface, this would not be correct, as I
did not create that operation.
remove
in interface ICompositeCommand
operation
- a child operation to remove
java.lang.IllegalStateException
- if I have already been successfully executedpublic boolean canExecute()
canExecute
in interface IUndoableOperation
canExecute
in class AbstractOperation
public boolean canRedo()
canRedo
in interface IUndoableOperation
canRedo
in class AbstractOperation
public boolean canUndo()
canUndo
in interface IUndoableOperation
canUndo
in class AbstractOperation
public void dispose()
dispose
in interface IUndoableOperation
dispose
in class AbstractCommand
public final ICommand compose(IUndoableOperation operation)
command
to the list of commands with which this
composite is composed.
compose
in interface ICommand
compose
in class AbstractCommand
operation
- The command with which to compose this command.
this
.public static ICommand compose(ICommand command, ICommand next)
command
- an existing command, which may be a composite, a single
command, or null
next
- a command to append to the composite (may also be
null
, which produces no effect)
next
if
command
was null
public ICommand reduce()
If the composite has a single command, it returns the reduction of that single command. Otherwise, it returns itself.
reduce
in interface ICommand
reduce
in class AbstractCommand
protected java.util.List getReturnValues()
ICommand
children.
protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException
doExecuteWithResult
in class AbstractCommand
progressMonitor
- the progress monitor provided by the operation history. Must
never be null
.info
- the IAdaptable (or null
) provided by the
caller in order to supply UI information for prompting the
user if necessary. When this parameter is not
null
, it should minimally contain an adapter
for the org.eclipse.swt.widgets.Shell.class.
null
if the execution status is OK, but there is no meaningful result
to be returned.
ExecutionException
- if, for some reason, I fail to complete the operationprotected CommandResult doRedoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException
doRedoWithResult
in class AbstractCommand
progressMonitor
- the progress monitor provided by the operation history. Must
never be null
.info
- the IAdaptable (or null
) provided by the
caller in order to supply UI information for prompting the
user if necessary. When this parameter is not
null
, it should minimally contain an adapter
for the org.eclipse.swt.widgets.Shell.class.
null
if the execution status is OK, but there is no meaningful result
to be returned.
ExecutionException
- on failure to redoprotected CommandResult doUndoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException
doUndoWithResult
in class AbstractCommand
progressMonitor
- the progress monitor provided by the operation history. Must
never be null
.info
- the IAdaptable (or null
) provided by the
caller in order to supply UI information for prompting the
user if necessary. When this parameter is not
null
, it should minimally contain an adapter
for the org.eclipse.swt.widgets.Shell.class.
null
if the execution status is OK, but there is no meaningful result
to be returned.
ExecutionException
- on failure to undoprotected IStatus aggregateStatuses(java.util.List statuses)
statuses
- the statuses to aggregate. May have zero, one, or more
elements (all must be IStatus
es)
protected final boolean isExecuted()
true
if I have been executed, false
otherwise.protected final void assertNotExecuted()
public java.util.List getAffectedFiles()
ICommand
children.
getAffectedFiles
in interface ICommand
getAffectedFiles
in class AbstractCommand
IFile
s that will be modifiedpublic java.util.Iterator iterator()
iterator
in interface ICompositeCommand
public java.util.ListIterator listIterator()
Note that, unlike list iterators generally, this implementation
does not permit the addition of an operation that I already contain (the
composite does not permit duplicates). Moreover, only
IUndoableOperation
s may be added, otherwise
ClassCastException
s will result.
listIterator
in interface ICompositeCommand
public java.util.ListIterator listIterator(int index)
index
. Adding and removing
children via this iterator correctly maintains my undo contexts.
Note that, unlike list iterators generally, this implementation
does not permit the addition of an operation that I already contain (the
composite does not permit duplicates). Moreover, only
IUndoableOperation
s may be added, otherwise
ClassCastException
s will result.
listIterator
in interface ICompositeCommand
index
- the index in my children at which to start iterating
|
Runtime | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Guidelines for using Eclipse APIs.
Copyright (c) IBM Corp., Borland Software Corp., and others 2005,2006. All rights reserved.