Class ComplexOperation

All Implemented Interfaces:
IComplexOperation, IUndoableOperation

public class ComplexOperation extends AbstractOperation implements IComplexOperation
The Complex operation can bundle advanced combination of operation between property containers. The operation is constructed with the property containers involved in the operation. Then the operation is executed. As it is executed, the undo/redo operations is built up.
Author:
Christopher Mindus
  • Constructor Details

    • ComplexOperation

      public ComplexOperation(String descr, IComplexOperationSelection selectionImpl, IPropUndoRedo undoRedo)
      Constructor of Add Operation.
      Parameters:
      descr - Description of the operation.
      selectionImpl - Selection to set in the Viewer of "undoRedo" when operation completes (also for undo), null for none.
      undoRedo - The undo/redo provider, null for no undo/redo support.
  • Method Details

    • getGlobal

      public ComplexOperation getGlobal()
      Gets the global complex operation in progress.
      Returns:
      The global operation, or null for none.
    • setSelectionBefore

      public void setSelectionBefore(ContainerSelection[] selection)
      Sets the selection before the operation has been performed so that it can be restored at a undo operation, before or after it has been executed.

      Use the method newContainerSelection(GProp) to create the array elements.

      Parameters:
      selection - The selection.
    • setSelectionAfter

      public void setSelectionAfter(ContainerSelection[] selection)
      Sets the selection after the operation has been performed so that it can be restored at a redo operation, before or after it has been executed.

      Use the method newContainerSelection(GProp) to create the array elements.

      Parameters:
      selection - The selection.
    • setProvenance

      public void setProvenance(boolean on)
      Sets the provenance switch of this operation. It is off by default.

      While the switch is on, what this operation produces carries the provenance mark (GProp.setPropProvenance(boolean)): a property it inserts - the property itself and, for a container, every container below it - and a plain property, i.e. one that is not a container, whose value it sets, also when the value set is the one the property has. While the switch is off, a value this operation sets clears the mark of that plain property. The mark of a container is never cleared. Undo and redo put the marks back as they were before and after each step.

      The switch applies to the sub-operations performed after the call.

      Parameters:
      on - true to mark what this operation produces from now on, false not to.
    • isProvenance

      public boolean isProvenance()
      Checks the provenance switch of this operation, see setProvenance(boolean).
      Returns:
      true if the switch is on.
    • setPropValue

      public void setPropValue(GProp<?> gp, Object newValue)
      Sets a property value.
      Specified by:
      setPropValue in interface IComplexOperation
    • addProp

      public void addProp(PropCnr pc, GProp<?> gp)
      Adds a property.
      Specified by:
      addProp in interface IComplexOperation
    • insertProp

      public void insertProp(PropCnr pc, GProp<?> gp, int index)
      Inserts a property.
      Specified by:
      insertProp in interface IComplexOperation
    • removeProp

      public void removeProp(GProp<?> gp)
      Removes a property.
      Specified by:
      removeProp in interface IComplexOperation
    • renameProp

      public void renameProp(GProp<?> gp, Atom newName)
      Renames a property.
      Specified by:
      renameProp in interface IComplexOperation
    • setPropError

      public void setPropError(GProp<?> gp, PropError pe)
      Sets all errors in a property.
      Specified by:
      setPropError in interface IComplexOperation
    • addPropError

      public void addPropError(GProp<?> gp, IPropErrorItem pei)
      Adds a property error.
      Specified by:
      addPropError in interface IComplexOperation
    • removePropError

      public void removePropError(GProp<?> gp, String errorID)
      Removes a property error.
      Specified by:
      removePropError in interface IComplexOperation
    • moveProp

      public void moveProp(GProp<?> gp, PropCnr toContainer, Atom newName, int toIndex)
      Moves a property to another container.
      Specified by:
      moveProp in interface IComplexOperation
    • reorderProps

      public void reorderProps(PropCnr pc, Atom[] order)
      Reorder a property container.
      Specified by:
      reorderProps in interface IComplexOperation
    • hasPerformedAnOperation

      public boolean hasPerformedAnOperation()
      Checks if an operation has been performed successfully or if it's an empty operation for undo.
      Specified by:
      hasPerformedAnOperation in interface IComplexOperation
    • getContainerParticipant

      public ContainerParticipant getContainerParticipant(PropCnr pc)
      Gets a container participant or creates one.
      Parameters:
      pc - The property container.
      Returns:
      The container participant.
    • newContainerSelection

      public ContainerSelection newContainerSelection(GProp<?> prop)
      Creates a new ContainerSelection instance for a property container involved in the operation.
      Parameters:
      prop - A selected property.
      Returns:
      The ContainerSelection instance.
    • newContainerSelection

      public ContainerSelection newContainerSelection(PropCnr parent, Atom childAtom)
      Creates a new ContainerSelection instance for a property container involved in the operation.
      Parameters:
      parent - The parent of the selected property.
      childAtom - The atom of the selected property.
      Returns:
      The ContainerSelection instance.
    • addOperation

      public void addOperation(IComplexSubOperation oper)
      Adds a sub operation.
    • canExecute

      public boolean canExecute()
      Returns whether the operation can be executed in its current state.
      Specified by:
      canExecute in interface IUndoableOperation
      Overrides:
      canExecute in class AbstractOperation
    • execute

      public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException
      Executes the Paste.
      Specified by:
      execute in interface IUndoableOperation
      Specified by:
      execute in class AbstractOperation
      Throws:
      ExecutionException
    • canRedo

      public boolean canRedo()
      Returns whether the operation can be redone in its current state.
      Specified by:
      canRedo in interface IUndoableOperation
      Overrides:
      canRedo in class AbstractOperation
    • redo

      public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException
      Redoes the Paste operation: same as Execute.
      Specified by:
      redo in interface IUndoableOperation
      Specified by:
      redo in class AbstractOperation
      Throws:
      ExecutionException
    • canUndo

      public boolean canUndo()
      Returns whether the operation can be undone in its current state.
      Specified by:
      canUndo in interface IUndoableOperation
      Overrides:
      canUndo in class AbstractOperation
    • undo

      public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException
      Performs the undo of a Paste operation.
      Specified by:
      undo in interface IUndoableOperation
      Specified by:
      undo in class AbstractOperation
      Throws:
      ExecutionException
    • setGlobal

      public boolean setGlobal()
      Sets this operation as the current one for global operations.
      Returns:
      true for single global operation assigned, false if another one has been replaced.
    • unsetGlobal

      public boolean unsetGlobal()
      Removes this operation as the current one for global operations. If this operation is not the global one, nothing happens.
      Returns:
      true for success, false if this operation was not the global one.