|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eclipse.core.commands.operations.AbstractOperation org.eclipse.emf.workspace.AbstractEMFOperation org.eclipse.emf.workspace.CompositeEMFOperation
public class CompositeEMFOperation
An implementation of a composite undoable operation for composition of
operations which may include AbstractEMFOperation
s. The composite
ensures that all of the nested operations are executed in a single
transaction context. The composite can combine EMF and non-EMF operations
freely, and even include nested CompositeEMFOperation
s.
Although a CompositeEMFOperation
provides a single root
transaction context for all of its children, these children open nested
transactions of their own, by default. This can be disabled by turning off
the transactionNestingEnabled
property.
This is a hint that child operations should just execute in the transaction
that is already open, unless they require a nested transaction. In
consequence, child operations would not be able to depend on changes being
triggered by
previous operations, as triggers will be deferred to the end of the composite
(when it commits).
Note that this kind of a composite is different from the
IOperationHistory
's notion of a TriggeredOperations
, because
the children of a composite are not "triggered" by any primary operation.
Rather, it is assumed that the children are explicitly composed by a client.
The undo contexts of the composite are a union of the undo contexts of its
children.
Note: This class cannot be used with the
IOperationHistory.openOperation(ICompositeOperation, int)
API
because it does not implement the ICompositeOperation
interface.
This prevents the possibility of open-ended transactions on the operation
history that any listener can contribute additional changes to, on the
same editing domain or a different editing domain. The transaction API
provides a tightly-regulated triggered change mechanism via the
ResourceSetListener
interface.
This class is intended to be instantiated by clients and supports a limited form of subclassing.
Constructor Summary | |
---|---|
CompositeEMFOperation(TransactionalEditingDomain domain,
String label)
Initializes me with the editing domain in which I am making model changes and a label. |
|
CompositeEMFOperation(TransactionalEditingDomain domain,
String label,
List<? extends IUndoableOperation> children)
Initializes me with the editing domain, a label, and child operations. |
|
CompositeEMFOperation(TransactionalEditingDomain domain,
String label,
List<? extends IUndoableOperation> children,
Map<?,?> options)
Initializes me with the editing domain, a label, and child operations, and transaction options. |
|
CompositeEMFOperation(TransactionalEditingDomain domain,
String label,
Map<?,?> options)
Initializes me with the editing domain, a label, and transaction options. |
Method Summary | |
---|---|
void |
add(IUndoableOperation operation)
Adds a child operation to me. |
protected void |
assertNotExecuted()
Asserts that I have not yet been executed. |
boolean |
canExecute()
I can execute if all of my children can execute. |
boolean |
canRedo()
I can redo if my transaction successfully completed with changes recorded and my children can all be redone. |
boolean |
canUndo()
I can undo if my transaction successfully completed with changes recorded and my children can all be undone. |
protected void |
didCommit(Transaction transaction)
Hook for subclasses to learn that the specified transaction
has been successfully committed and, if necessary, to extract information
from it. |
void |
dispose()
Removes all of my children and disposes them. |
protected IStatus |
doExecute(IProgressMonitor monitor,
IAdaptable info)
Implements the execution logic by sequential execution of my children. |
protected IStatus |
doRedo(IProgressMonitor monitor,
IAdaptable info)
I undo by asking my children to redo, in forward order. |
protected IStatus |
doUndo(IProgressMonitor monitor,
IAdaptable info)
I undo by asking my children to undo, in reverse order. |
protected List<IUndoableOperation> |
getChildren()
Obtains my nested operations. |
boolean |
isTransactionNestingEnabled()
Queries whether nesting of transactions is enabled, meaning that all child operations (recursively) execute in their own (nested) transactions. |
Iterator<IUndoableOperation> |
iterator()
Obtains an iterator to traverse my child operations. |
ListIterator<IUndoableOperation> |
listIterator()
Obtains an iterator to traverse my child operations in either direction. |
ListIterator<IUndoableOperation> |
listIterator(int index)
Obtains an iterator to traverse my child operations in either direction, starting from the specified index . |
void |
remove(IUndoableOperation operation)
Removes a child operation from me. |
void |
setReuseParentTransaction(boolean reuseParentTransaction)
Extends the inherited method to toggle my transaction nesting
state accordingly. |
void |
setTransactionNestingEnabled(boolean enable)
Sets whether nesting of transactions is enabled. |
int |
size()
Queries the number of child operations that I contain. |
Methods inherited from class org.eclipse.emf.workspace.AbstractEMFOperation |
---|
aggregateStatuses, canSetOptions, didRedo, didUndo, execute, getChange, getEditingDomain, getOptions, isReuseParentTransaction, redo, setOptions, 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 |
Constructor Detail |
---|
public CompositeEMFOperation(TransactionalEditingDomain domain, String label)
domain
- my editing domainlabel
- my user-readable labelpublic CompositeEMFOperation(TransactionalEditingDomain domain, String label, Map<?,?> options)
domain
- my editing domainlabel
- my user-readable labeloptions
- for the transaction in which I execute myself, or
null
for the default optionspublic CompositeEMFOperation(TransactionalEditingDomain domain, String label, List<? extends IUndoableOperation> children)
domain
- my editing domainlabel
- my user-readable labelchildren
- a list of operations to composepublic CompositeEMFOperation(TransactionalEditingDomain domain, String label, List<? extends IUndoableOperation> children, Map<?,?> options)
domain
- my editing domainlabel
- my user-readable labelchildren
- a list of operations to composeoptions
- for the transaction in which I execute myself, or
null
for the default optionsMethod Detail |
---|
protected final IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException
doExecute
in class AbstractEMFOperation
monitor
- the progress monitor provided by the operation history.
Will never be null
because the
AbstractEMFOperation.execute(IProgressMonitor, IAdaptable)
method would substitute
a NullProgressMonitor
in that caseinfo
- the adaptable provided by the operation history
ExecutionException
- if, for some reason, I fail to complete
the operationprotected void didCommit(Transaction transaction)
AbstractEMFOperation
Hook for subclasses to learn that the specified transaction
has been successfully committed and, if necessary, to extract information
from it.
Note: subclasses should call this super implementation to get some default behaviours.
didCommit
in class AbstractEMFOperation
transaction
- a transaction that has committed, which has recorded
our changespublic boolean canExecute()
canExecute
in interface IUndoableOperation
canExecute
in class AbstractOperation
public boolean canUndo()
canUndo
in interface IUndoableOperation
canUndo
in class AbstractEMFOperation
protected final IStatus doUndo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException
doUndo
in class AbstractEMFOperation
monitor
- the progress monitor provided by the operation history
Will never be null
because the
AbstractEMFOperation.undo(IProgressMonitor, IAdaptable)
method would substitute
a NullProgressMonitor
in that caseinfo
- the adaptable provided by the operation history
ExecutionException
- on failure to undopublic boolean canRedo()
canRedo
in interface IUndoableOperation
canRedo
in class AbstractEMFOperation
protected final IStatus doRedo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException
doRedo
in class AbstractEMFOperation
monitor
- the progress monitor provided by the operation history
Will never be null
because the
AbstractEMFOperation.redo(IProgressMonitor, IAdaptable)
method would substitute
a NullProgressMonitor
in that caseinfo
- the adaptable provided by the operation history
ExecutionException
- on failure to redopublic void dispose()
dispose
in interface IUndoableOperation
dispose
in class AbstractEMFOperation
protected List<IUndoableOperation> 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 void add(IUndoableOperation operation)
operation
- a new child operation
IllegalStateException
- if I have already been successfully
executedprotected final void assertNotExecuted()
public void remove(IUndoableOperation operation)
Note that, unlike the ICompositeOperation
interface (which
I do not implement), I do not dispose an operation when it is removed
from me. This would not be correct, as I did not create that operation.
operation
- a child operation to remove
IllegalStateException
- if I have already been successfully
executedpublic void setReuseParentTransaction(boolean reuseParentTransaction)
transaction nesting
state accordingly.
setReuseParentTransaction
in class AbstractEMFOperation
reuseParentTransaction
- whether to reuse parent transactionsisTransactionNestingEnabled()
public boolean isTransactionNestingEnabled()
false
if child operations execute in a single (flat)
transaction where possible; false
, otherwisesetTransactionNestingEnabled(boolean)
public void setTransactionNestingEnabled(boolean enable)
Note that this is really only a hint: there are exceptions where child operation will still create nested transactions. These are:
AbstractEMFOperation
. Non-EMF
operations are given special transactions that capture their changes
as change descriptions in the parent transactiontransaction options
than
the parent composite operation
enable
- whether to force all child operations to create nested
transactions
IllegalStateException
- if I have already been
executed
, after which
time transaction nesting cannot be changedpublic int size()
public Iterator<IUndoableOperation> iterator()
public ListIterator<IUndoableOperation> 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.
public ListIterator<IUndoableOperation> 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.
index
- the index in my children at which to start iterating
|
Copyright 2002, 2007 IBM Corporation and others. All Rights Reserved. |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |