Interface IUndoableOperation

All Known Subinterfaces:
ICompositeOperation
All Known Implementing Classes:
AbstractOperation, AbstractWorkspaceOperation, CopyProjectOperation, CopyResourcesOperation, CreateFileOperation, CreateFolderOperation, CreateMarkersOperation, CreateProjectOperation, DeleteMarkersOperation, DeleteResourcesOperation, MoveProjectOperation, MoveResourcesOperation, TriggeredOperations, UpdateMarkersOperation

public interface IUndoableOperation

IUndoableOperation defines an operation that can be executed, undone, and redone. Operations typically have fully defined parameters. That is, they are usually created after the user has been queried for any input needed to define the operation.

Operations determine their ability to execute, undo, or redo according to the current state of the application. They do not make decisions about their validity based on where they occur in the operation history. That is left to the particular operation history.

Since:
3.1
  • Method Details

    • addContext

      void addContext(IUndoContext context)

      Add the specified context to the operation. If a context equal to the specified context is already present, do not add it again. Note that determining whether a context is already present is based on equality, not whether the context matches (IUndoContext.matches(IUndoContext)) another context.

      Parameters:
      context - the context to be added
    • canExecute

      boolean canExecute()

      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.

      Returns:
      true if the operation can be executed; false otherwise.
    • canRedo

      boolean canRedo()

      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.

      Returns:
      true if the operation can be redone; false otherwise.
    • canUndo

      boolean canUndo()

      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.

      Returns:
      true if the operation can be undone; false otherwise.
    • dispose

      void dispose()
      Dispose of the operation. This method is used when the operation is no longer kept in the history. Implementers of this method typically unregister any listeners.
    • execute

      IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException
      Execute the operation. This method should only be called the first time that an operation is executed.
      Parameters:
      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.
      Returns:
      the IStatus of the execution. The status severity should be set to OK if the operation was successful, and ERROR if it was not. Any other status is assumed to represent an incompletion of the execution.
      Throws:
      ExecutionException - if an exception occurred during execution.
    • getContexts

      IUndoContext[] getContexts()

      Returns the array of contexts that have been assigned to the operation.

      This method may be called by the operation history from inside a synchronized block. To avoid deadlock conditions, implementers of this method must avoid dispatching and waiting on threads that modify the operation history during this method.

      Returns:
      the array of contexts
    • getLabel

      String getLabel()
      Return the label that should be used to show the name of the operation to the user. This label is typically combined with the command strings shown to the user in "Undo" and "Redo" user interfaces.
      Returns:
      the String label. Should never be null.
    • hasContext

      boolean hasContext(IUndoContext context)

      Returns whether the operation has a matching context for the specified context.

      This method may be called by the operation history from inside a synchronized block. To avoid deadlock conditions, implementers of this method must avoid dispatching and waiting on threads that modify the operation history during this method.

      Parameters:
      context - the context in question
      Returns:
      true if the context is present, false if it is not.
      See Also:
    • redo

      Redo the operation. This method should only be called after an operation has been undone.
      Parameters:
      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.
      Returns:
      the IStatus of the redo. The status severity should be set to OK if the redo was successful, and ERROR if it was not. Any other status is assumed to represent an incompletion of the redo.
      Throws:
      ExecutionException - if an exception occurred during redo.
    • removeContext

      void removeContext(IUndoContext context)
      Remove the specified context from the operation. This method has no effect if the context is not equal to another context in the context list. Note that determining whether a context is present when removing it is based on equality, not whether the context matches (IUndoContext.matches(IUndoContext)) another context.
      Parameters:
      context - the context to be removed
    • undo

      Undo the operation. This method should only be called after an operation has been executed.
      Parameters:
      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.
      Returns:
      the IStatus of the undo. The status severity should be set to OK if the redo was successful, and ERROR if it was not. Any other status is assumed to represent an incompletion of the undo.
      Throws:
      ExecutionException - if an exception occurred during undo.