public final class TriggeredOperations extends AbstractOperation implements ICompositeOperation, IAdvancedUndoableOperation, IAdvancedUndoableOperation2, IContextReplacingOperation
This class may be instantiated by clients.
Constructor and Description |
---|
TriggeredOperations(IUndoableOperation operation,
IOperationHistory history)
Construct a composite triggered operations using the specified undoable
operation as the trigger.
|
Modifier and Type | Method and Description |
---|---|
void |
aboutToNotify(OperationHistoryEvent event)
An operation history notification about this operation is about to be
sent to operation history listeners.
|
void |
add(IUndoableOperation operation)
Add the specified operation as a child of this operation.
|
void |
addContext(IUndoContext context)
Add the specified context to the operation.
|
boolean |
canExecute()
Returns whether the operation can be executed in its current state.
|
boolean |
canRedo()
Returns whether the operation can be redone in its current state.
|
boolean |
canUndo()
Returns whether the operation can be undone in its current state.
|
IStatus |
computeExecutionStatus(IProgressMonitor monitor)
Return a status indicating the projected outcome of executing the
receiver.
|
IStatus |
computeRedoableStatus(IProgressMonitor monitor)
Return a status indicating the projected outcome of redoing the receiver.
|
IStatus |
computeUndoableStatus(IProgressMonitor monitor)
Return a status indicating the projected outcome of undoing the receiver.
|
void |
dispose()
Dispose of the operation.
|
IStatus |
execute(IProgressMonitor monitor,
IAdaptable info)
Execute the operation.
|
Object[] |
getAffectedObjects()
Return an array of objects that are affected by executing, undoing, or
redoing this operation.
|
IUndoableOperation |
getTriggeringOperation()
Return the operation that triggered the other operations in this
composite.
|
IStatus |
redo(IProgressMonitor monitor,
IAdaptable info)
Redo the operation.
|
void |
remove(IUndoableOperation operation)
Remove the specified operation from this operation.
|
void |
removeContext(IUndoContext context)
Remove the specified context from the receiver.
|
void |
replaceContext(IUndoContext original,
IUndoContext replacement)
Replace the undo context of the receiver with the provided replacement
undo context.
|
boolean |
runInBackground()
Return a boolean that instructs whether the operation should be executed,
undone, or redone in a background thread.
|
void |
setQuietCompute(boolean quiet)
Set a boolean that instructs whether the computation of the receiver's
execution, undo, or redo status should quietly compute status without
consulting or prompting the user.
|
IStatus |
undo(IProgressMonitor monitor,
IAdaptable info)
Undo the operation.
|
getContexts, getLabel, hasContext, setLabel, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getContexts, getLabel, hasContext
public TriggeredOperations(IUndoableOperation operation, IOperationHistory history)
operation
- the operation that will trigger other operations.history
- the operation history containing the triggered operations.public void add(IUndoableOperation operation)
ICompositeOperation
Add the specified operation as a child of this operation.
add
in interface ICompositeOperation
operation
- the operation to be added. If the operation instance has
already been added, this method will have no effect.public void remove(IUndoableOperation operation)
ICompositeOperation
Remove the specified operation from this operation.
The composite operation should dispose the operation as part of removing it.
remove
in interface ICompositeOperation
operation
- the operation to be removed. The operation should be disposed
by the receiver. This method will have no effect if the
operation instance is not already a child.public void removeContext(IUndoContext context)
removeContext
in interface IUndoableOperation
removeContext
in class AbstractOperation
context
- the undo context being removed from the receiver.public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException
IUndoableOperation
execute
in interface IUndoableOperation
execute
in class AbstractOperation
monitor
- the progress monitor (or null
) to use for
reporting progress to the user.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.OK
if the operation was successful, and
ERROR
if it was not. Any other status is assumed
to represent an incompletion of the execution.ExecutionException
- if an exception occurred during execution.public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException
IUndoableOperation
redo
in interface IUndoableOperation
redo
in class AbstractOperation
monitor
- the progress monitor (or null
) to use for
reporting progress to the user.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.OK
if the redo was successful, and
ERROR
if it was not. Any other status is assumed
to represent an incompletion of the redo.ExecutionException
- if an exception occurred during redo.public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException
IUndoableOperation
undo
in interface IUndoableOperation
undo
in class AbstractOperation
monitor
- the progress monitor (or null
) to use for
reporting progress to the user.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.OK
if the redo was successful, and
ERROR
if it was not. Any other status is assumed
to represent an incompletion of the undo.ExecutionException
- if an exception occurred during undo.public boolean canUndo()
IUndoableOperation
Returns whether the operation can be undone in its current state.
Note: The computation for this method must be fast, as it is called frequently. If necessary, this method can be optimistic in its computation (returning true) and later perform more time-consuming computations during the actual undo of the operation, returning the appropriate status if the operation cannot actually be undone at that time.
canUndo
in interface IUndoableOperation
canUndo
in class AbstractOperation
true
if the operation can be undone;
false
otherwise.public boolean canExecute()
IUndoableOperation
Returns whether the operation can be executed in its current state.
Note: The computation for this method must be fast, as it is called frequently. If necessary, this method can be optimistic in its computation (returning true) and later perform more time-consuming computations during the actual execution of the operation, returning the appropriate status if the operation cannot actually execute at that time.
canExecute
in interface IUndoableOperation
canExecute
in class AbstractOperation
true
if the operation can be executed;
false
otherwise.public boolean canRedo()
IUndoableOperation
Returns whether the operation can be redone in its current state.
Note: The computation for this method must be fast, as it is called frequently. If necessary, this method can be optimistic in its computation (returning true) and later perform more time-consuming computations during the actual redo of the operation, returning the appropriate status if the operation cannot actually be redone at that time.
canRedo
in interface IUndoableOperation
canRedo
in class AbstractOperation
true
if the operation can be redone;
false
otherwise.public void dispose()
IUndoableOperation
dispose
in interface IUndoableOperation
dispose
in class AbstractOperation
public IUndoableOperation getTriggeringOperation()
public Object[] getAffectedObjects()
IAdvancedUndoableOperation
Return an array of objects that are affected by executing, undoing, or redoing this operation. If it cannot be determined which objects are affected, return null.
getAffectedObjects
in interface IAdvancedUndoableOperation
null
if the affected objects cannot be determined.public void aboutToNotify(OperationHistoryEvent event)
IAdvancedUndoableOperation
An operation history notification about this operation is about to be sent to operation history listeners. Any preparation needed before listeners are notified about this operation should be performed here.
This method has been added to support legacy undo frameworks that are adapting to IUndoableOperation. Operations that previously relied on notification from their containing history or stack before any listeners are notified about changes to the operation should implement this interface.
aboutToNotify
in interface IAdvancedUndoableOperation
event
- the event that is about to be sent with the pending
notificationpublic IStatus computeUndoableStatus(IProgressMonitor monitor) throws ExecutionException
IAdvancedUndoableOperation
IUndoableOperation.canUndo()
. It is not called by the
operation history, but instead is used by clients (such as implementers
of IOperationApprover
) who wish to perform advanced validation of
an operation before attempting to undo it.
If the result of this method is the discovery that an operation can in
fact not be undone, then the operation is expected to correctly answer
false
on subsequent calls to
IUndoableOperation.canUndo()
.computeUndoableStatus
in interface IAdvancedUndoableOperation
monitor
- the progress monitor (or null
) to use for
reporting progress to the user while computing the validity.OK
if the undo can
successfully be performed, and ERROR
if it
cannnot. Any other status is assumed to represent an ambiguous
state.ExecutionException
- if an exception occurs while computing the validity.public IStatus computeRedoableStatus(IProgressMonitor monitor) throws ExecutionException
IAdvancedUndoableOperation
IUndoableOperation.canRedo()
. It is not called by the
operation history, but instead is used by clients (such as implementers
of IOperationApprover
) who wish to perform advanced validation of
an operation before attempting to redo it.
If the result of this method is the discovery that an operation can in
fact not be redone, then the operation is expected to correctly answer
false
on subsequent calls to
IUndoableOperation.canRedo()
.computeRedoableStatus
in interface IAdvancedUndoableOperation
monitor
- the progress monitor (or null
) to use for
reporting progress to the user while computing the validity.OK
if the redo can
successfully be performed, and ERROR
if it
cannnot. Any other status is assumed to represent an ambiguous
state.ExecutionException
- if an exception occurs while computing the validity.public void replaceContext(IUndoContext original, IUndoContext replacement)
This message has no effect if the original undo context is not present in the receiver.
replaceContext
in interface IContextReplacingOperation
original
- the undo context which is to be replacedreplacement
- the undo context which is replacing the originalpublic void addContext(IUndoContext context)
addContext
in interface IUndoableOperation
addContext
in class AbstractOperation
context
- the context to be addedpublic IStatus computeExecutionStatus(IProgressMonitor monitor) throws ExecutionException
IAdvancedUndoableOperation2
IUndoableOperation.canExecute()
. It is not called by
the operation history, but instead is used by clients (such as
implementers of IOperationApprover2
) who wish to perform
advanced validation of an operation before attempting to execute it.
If the result of this method is the discovery that an operation can in
fact not be executed, then the operation is expected to correctly answer
false
on subsequent calls to
IUndoableOperation.canExecute()
.computeExecutionStatus
in interface IAdvancedUndoableOperation2
monitor
- the progress monitor (or null
) to use for
reporting progress to the user while computing the validity.OK
if the execute can
successfully be performed, and ERROR
if it cannot.
Any other severity is assumed to represent an ambiguous state.ExecutionException
- if an exception occurs while computing the validity.public void setQuietCompute(boolean quiet)
IAdvancedUndoableOperation2
false
.
This flag should only be set to true
while the execution,
undo, or redo status computations are being performed in the background,
and should be restored to false
when complete.
If the status computation methods typically need to consult the user in
order to determine the severity of a particular situation, the least
severe status that could be chosen by the user should be returned when
this flag is true
. This can help to prevent overzealous
disposal of the operation history when an operation is in an ambiguous
state. Typically, the status computation methods are invoked with this
flag set to false
just before the actual execution, undo,
or redo occurs, so the user can be consulted for the final outcome.
setQuietCompute
in interface IAdvancedUndoableOperation2
quiet
- true
if it is inappropriate to consult or
otherwise prompt the user while computing status, and
false
if the user may be prompted.IAdvancedUndoableOperation2.computeExecutionStatus(IProgressMonitor)
,
IAdvancedUndoableOperation.computeUndoableStatus(IProgressMonitor)
,
IAdvancedUndoableOperation.computeRedoableStatus(IProgressMonitor)
public boolean runInBackground()
IAdvancedUndoableOperation2
runInBackground
in interface IAdvancedUndoableOperation2
true
if the operation should be run in the
background, false
if it should not.
Copyright (c) 2000, 2014 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.