- adapted sub classes of AbstractPostOperation
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / operation / AbstractPostOperation.java
index 9506bd4b4046af111523e119e1f0725f50d660e1..5b7c68ec8230074a7de6ef72c0fd5ae812bb3636 100644 (file)
 package eu.etaxonomy.taxeditor.operation;
 
 import org.eclipse.core.commands.operations.AbstractOperation;
+import org.eclipse.core.commands.operations.IUndoContext;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
 
 import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.common.ICdmBase;
 
 /**
  * @author pplitzner
  * @date 03.12.2013
  *
  */
-public abstract class AbstractPostOperation extends AbstractOperation {
+public abstract class AbstractPostOperation<T extends ICdmBase> extends AbstractOperation {
+
 
     /**
-     * 
+     * A reference to the {@link ICdmBase} element the concrete operation is working on
+     */
+    protected T element;
+
+    /**
+     *
      */
     protected IPostOperationEnabled postOperationEnabled;
 
+
     /**
-     * @param label
+     * <p>Constructor for AbstractPostOperation.</p>
+     *
+     * @param label a {@link java.lang.String} object.
+     * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
      */
-    public AbstractPostOperation(String label) {
+    protected AbstractPostOperation(String label, IUndoContext undoContext) {
         super(label);
+        addContext(undoContext);
+    }
+
+    /**
+     * <p>Constructor for AbstractPostOperation.</p>
+     *
+     * @param label a {@link java.lang.String} object.
+     * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
+     * @param element a {@link ICdmBase} object on which this operation is working.
+     */
+    public AbstractPostOperation(String label, IUndoContext undoContext, T element) {
+        this(label, undoContext);
+        this.element = element;
+    }
+
+    /**
+     * @param label
+     * @param element
+     * @param postOperationEnabled
+     */
+    public AbstractPostOperation(String label, IUndoContext undoContext,
+            T element, IPostOperationEnabled postOperationEnabled) {
+        this(label, undoContext);
+        this.element = element;
+        this.postOperationEnabled = postOperationEnabled;
     }
 
     /**
@@ -42,7 +79,7 @@ public abstract class AbstractPostOperation extends AbstractOperation {
      * @param objectAffectedByOperation the affected object. Should be <code>null</code> if not needed
      * @return a {@link org.eclipse.core.runtime.IStatus} object.
      */
-    protected IStatus postExecute(CdmBase objectAffectedByOperation) { 
+    protected IStatus postExecute(CdmBase objectAffectedByOperation) {
        if(postOperationEnabled != null){
                return postOperationEnabled.postOperation(objectAffectedByOperation) ? Status.OK_STATUS : Status.CANCEL_STATUS;
        }