public abstract class AbstractWorkspaceOperation extends AbstractOperation implements IAdvancedUndoableOperation, IAdvancedUndoableOperation2
This class is not intended to be subclassed by clients.
Modifier and Type | Field and Description |
---|---|
protected static int |
EXECUTE |
protected boolean |
quietCompute |
protected static int |
REDO |
protected IResource[] |
resources |
protected static int |
UNDO |
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.
|
protected void |
appendDescriptiveText(StringBuffer text)
Append any descriptive text to the specified string buffer to be shown in
the receiver's
toString() text. |
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.
|
protected abstract void |
doExecute(IProgressMonitor monitor,
IAdaptable uiInfo)
Perform the specific work involved in executing this operation.
|
protected abstract void |
doUndo(IProgressMonitor monitor,
IAdaptable uiInfo)
Perform the specific work involved in undoing this operation.
|
IStatus |
execute(IProgressMonitor monitor,
IAdaptable uiInfo)
Execute the specified operation.
|
Object[] |
getAffectedObjects()
Return an array of objects that are affected by executing, undoing, or
redoing this operation.
|
protected IStatus |
getErrorStatus(String message)
Return an error status describing an invalid operation using the provided
message.
|
protected ISchedulingRule |
getExecuteSchedulingRule()
Return a scheduling rule appropriate for executing this operation.
|
protected ISchedulingRule |
getRedoSchedulingRule()
Return a scheduling rule appropriate for redoing this operation.
|
protected Shell |
getShell(IAdaptable uiInfo)
Return the shell described by the specified adaptable, or the active
shell if no shell has been specified in the adaptable.
|
protected ISchedulingRule |
getUndoSchedulingRule()
Return a scheduling rule appropriate for undoing this operation.
|
protected IStatus |
getWarningStatus(String message,
int code)
Return a warning status describing the warning state of an operation
using the provided message and code.
|
protected IWorkspace |
getWorkspace()
Return the workspace manipulated by this operation.
|
protected IResourceRuleFactory |
getWorkspaceRuleFactory()
Return the workspace rule factory associated with this operation.
|
protected boolean |
isValid()
Return whether the proposed operation is valid.
|
protected void |
markInvalid()
Mark this operation invalid due to some external change.
|
IStatus |
redo(IProgressMonitor monitor,
IAdaptable uiInfo)
Redo the specified operation.
|
protected boolean |
resourcesExist()
Return whether the resources known by this operation currently exist.
|
protected boolean |
resourcesIncludesProjects()
Return whether the resources known by this operation contain any
projects.
|
boolean |
runInBackground()
Return a boolean that instructs whether the operation should be executed,
undone, or redone in a background thread.
|
void |
setModelProviderIds(String[] ids)
Set the ids of any model providers for the resources involved.
|
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.
|
protected void |
setTargetResources(IResource[] resources)
Set the resources which are affected by this operation
|
String |
toString()
The string representation of this operation.
|
IStatus |
undo(IProgressMonitor monitor,
IAdaptable uiInfo)
Undo the specified operation.
|
protected boolean |
updateResourceChangeDescriptionFactory(IResourceChangeDescriptionFactory factory,
int operation)
Update the provided resource change description factory so it can
generate a resource delta describing the result of an undo or redo.
|
addContext, dispose, getContexts, getLabel, hasContext, removeContext, setLabel
protected static int EXECUTE
protected static int UNDO
protected static int REDO
protected IResource[] resources
protected boolean quietCompute
public void setModelProviderIds(String[] ids)
ids
- the array of String model provider ids that provide models
associated with the resources involved in this operationprotected void setTargetResources(IResource[] resources)
resources
- an array of resourcesprotected IWorkspace getWorkspace()
protected IResourceRuleFactory getWorkspaceRuleFactory()
protected void markInvalid()
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 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 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 IStatus execute(IProgressMonitor monitor, IAdaptable uiInfo) throws ExecutionException
execute
in interface IUndoableOperation
execute
in class AbstractOperation
monitor
- the progress monitor to use for the operationuiInfo
- 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 contains an adapter for the
org.eclipse.swt.widgets.Shell.classOK
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.IUndoableOperation.execute(org.eclipse.core.runtime.IProgressMonitor,
org.eclipse.core.runtime.IAdaptable)
public IStatus redo(IProgressMonitor monitor, IAdaptable uiInfo) throws ExecutionException
redo
in interface IUndoableOperation
redo
in class AbstractOperation
monitor
- the progress monitor to use for the operationuiInfo
- 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 contains an adapter for the
org.eclipse.swt.widgets.Shell.classOK
if the operation 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 execution.IUndoableOperation.redo(org.eclipse.core.runtime.IProgressMonitor,
org.eclipse.core.runtime.IAdaptable)
public IStatus undo(IProgressMonitor monitor, IAdaptable uiInfo) throws ExecutionException
undo
in interface IUndoableOperation
undo
in class AbstractOperation
monitor
- the progress monitor to use for the operationuiInfo
- 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 contains an adapter for the
org.eclipse.swt.widgets.Shell.classOK
if the operation 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 execution.IUndoableOperation.undo(org.eclipse.core.runtime.IProgressMonitor,
org.eclipse.core.runtime.IAdaptable)
protected abstract void doUndo(IProgressMonitor monitor, IAdaptable uiInfo) throws CoreException
monitor
- the progress monitor to use for the operationuiInfo
- 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 contains an adapter for the
org.eclipse.swt.widgets.Shell.classCoreException
- propagates any CoreExceptions thrown from the resources APIprotected abstract void doExecute(IProgressMonitor monitor, IAdaptable uiInfo) throws CoreException
monitor
- the progress monitor to use for the operationuiInfo
- 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 contains an adapter for the
org.eclipse.swt.widgets.Shell.classCoreException
- propagates any CoreExceptions thrown from the resources APIprotected boolean isValid()
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 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 IStatus computeExecutionStatus(IProgressMonitor monitor)
IOperationApprover2
) who
wish to perform advanced validation of an operation before attempting to
execute it.
If an ERROR status is returned, the operation will not proceed and the
user notified if deemed necessary by the caller. The validity flag on the
operation should be marked as invalid. If an OK status is returned, the
operation will proceed. The caller must interpret any other returned
status severity, and may choose to prompt the user as to how to proceed.
If there are multiple conditions that result in an ambiguous status
severity, it is best for the implementor of this method to consult the
user as to how to proceed for each one, and return an OK or ERROR status
that accurately reflects the user's wishes, or to return a multi-status
that accurately describes all of the issues at hand, so that the caller
may potentially consult the user. (Note that the user should not be
consulted at all if a client has called setQuietCompute(boolean)
with a value of true
.)
This implementation computes the validity of execution by computing the
resource delta that would be generated on execution, and checking whether
any registered model providers are affected by the operation.computeExecutionStatus
in interface IAdvancedUndoableOperation2
monitor
- the progress monitor to be used for computing the statusIAdvancedUndoableOperation.computeUndoableStatus(org.eclipse.core.runtime.IProgressMonitor)
,
setQuietCompute(boolean)
public IStatus computeUndoableStatus(IProgressMonitor monitor)
IOperationApprover2
) who
wish to perform advanced validation of an operation before attempting to
undo it.
If an ERROR status is returned, the undo will not proceed and the user
notified if deemed necessary by the caller. The validity flag on the
operation should be marked as invalid. If an OK status is returned, the
undo will proceed. The caller must interpret any other returned status
severity, and may choose to prompt the user as to how to proceed.
If there are multiple conditions that result in an ambiguous status
severity, it is best for the implementor of this method to consult the
user as to how to proceed for each one, and return an OK or ERROR status
that accurately reflects the user's wishes, or to return a multi-status
that accurately describes all of the issues at hand, so that the caller
may potentially consult the user. (Note that the user should not be
consulted at all if a client has called setQuietCompute(boolean)
with a value of true
.)
This implementation computes the validity of undo by computing the
resource delta that would be generated on undo, and checking whether any
registered model providers are affected by the operation.computeUndoableStatus
in interface IAdvancedUndoableOperation
monitor
- the progress monitor to be used for computing the statusIAdvancedUndoableOperation.computeUndoableStatus(org.eclipse.core.runtime.IProgressMonitor)
,
setQuietCompute(boolean)
public IStatus computeRedoableStatus(IProgressMonitor monitor)
IOperationApprover2
) who
wish to perform advanced validation of an operation before attempting to
redo it.
If an ERROR status is returned, the redo will not proceed and the user
notified if deemed necessary by the caller. The validity flag on the
operation should be marked as invalid. If an OK status is returned, the
redo will proceed. The caller must interpret any other returned status
severity, and may choose to prompt the user as to how to proceed.
If there are multiple conditions that result in an ambiguous status
severity, it is best for the implementor of this method to consult the
user as to how to proceed for each one, and return an OK or ERROR status
that accurately reflects the user's wishes, or to return a multi-status
that accurately describes all of the issues at hand, so that the caller
may potentially consult the user. (Note that the user should not be
consulted at all if a client has called setQuietCompute(boolean)
with a value of true
.)
This implementation computes the validity of redo by computing the
resource delta that would be generated on redo, and checking whether any
registered model providers are affected by the operation.computeRedoableStatus
in interface IAdvancedUndoableOperation
monitor
- the progress monitor to be used for computing the statusIAdvancedUndoableOperation.computeUndoableStatus(org.eclipse.core.runtime.IProgressMonitor)
,
setQuietCompute(boolean)
protected boolean updateResourceChangeDescriptionFactory(IResourceChangeDescriptionFactory factory, int operation)
factory
- the factory to updateoperation
- an integer indicating whether the change is part of an
execute, undo, or redoprotected IStatus getErrorStatus(String message)
message
- the message to be used in the status, or null
if a generic message should be usedprotected IStatus getWarningStatus(String message, int code)
message
- the message to be used in the status, or null
if a generic message should be usedcode
- the integer code to be assigned to the statusprotected boolean resourcesExist()
true
if there are existing resources and
false
if there are no known resources or any one
of them does not existprotected boolean resourcesIncludesProjects()
true
if there is one or more projects known by
this operation and false if there are no projects.protected ISchedulingRule getExecuteSchedulingRule()
null
if there are no scheduling restrictions for
this operation.IWorkspace.run(IWorkspaceRunnable, ISchedulingRule, int,
IProgressMonitor)
protected ISchedulingRule getUndoSchedulingRule()
null
if there are no scheduling restrictions for
this operation.IWorkspace.run(IWorkspaceRunnable, ISchedulingRule, int,
IProgressMonitor)
protected ISchedulingRule getRedoSchedulingRule()
null
if there are no scheduling restrictions for
this operation.IWorkspace.run(IWorkspaceRunnable, ISchedulingRule, int,
IProgressMonitor)
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 String toString()
AbstractOperation
toString
in class AbstractOperation
protected void appendDescriptiveText(StringBuffer text)
toString()
text.
Note that this method is not intend to be subclassed by clients.
text
- the StringBuffer on which to append the textprotected Shell getShell(IAdaptable uiInfo)
uiInfo
- 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 contains an adapter for the
org.eclipse.swt.widgets.Shell.classpublic 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, 2015 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.