+// $Id$
/**
-* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
-
+ * Copyright (C) 2013 EDIT
+ * European Distributed Institute of Taxonomy
+ * http://www.e-taxonomy.eu
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * See LICENSE.TXT at the top of this package for the full license terms.
+ */
package eu.etaxonomy.taxeditor.operation;
-import java.util.UUID;
-
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.taxon.Taxon;
-import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.cdm.model.common.ICdmBase;
+import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
/**
- * <p>Abstract AbstractPostOperation class.</p>
+ * @author pplitzner
+ * @date 03.12.2013
*
- * @author p.ciardelli
- * @author n.hoffmann
- * @created 14.01.2009
- * @version 1.0
*/
-public abstract class AbstractPostOperation extends AbstractOperation {
-
- /**
- *
- */
- private IPostOperationEnabled postOperationEnabled;
-
- /**
- * A reference to the taxon the concrete operation is working on
- */
- protected Taxon taxon;
-
- /**
- * A reference to the taxons TaxonNode
- */
- protected TaxonNode taxonNode;
-
- protected UUID parentNodeUuid;
-
- /**
- * <p>Constructor for AbstractPostOperation.</p>
- *
- * @param label a {@link java.lang.String} object.
- * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
- */
- 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 taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
- */
- public AbstractPostOperation(String label, IUndoContext undoContext,
- Taxon taxon) {
- this(label, undoContext);
-
- this.taxon = taxon;
- }
-
- /**
- * <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 taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
- * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
- */
- public AbstractPostOperation(String label, IUndoContext undoContext,
- Taxon taxon, IPostOperationEnabled postOperationEnabled) {
- this(label, undoContext, taxon);
- this.postOperationEnabled = postOperationEnabled;
- }
-
- /**
- * <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 taxonNode a {@link eu.etaxonomy.cdm.model.taxon.TaxonNode} object.
- * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
- */
- public AbstractPostOperation(String label, IUndoContext undoContext, TaxonNode taxonNode, IPostOperationEnabled postOperationEnabled){
- this(label, undoContext, taxonNode.getTaxon(), postOperationEnabled);
- this.taxonNode = taxonNode;
- }
-
- /**
- * <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 parentNodeUuid a {@link java.util.UUID} object.
- * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
- */
- public AbstractPostOperation(String label, IUndoContext undoContext, UUID parentNodeUuid, IPostOperationEnabled postOperationEnabled){
- this(label, undoContext);
-
- this.parentNodeUuid = parentNodeUuid;
- this.postOperationEnabled = postOperationEnabled;
- }
-
- /**
- * <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 postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
- */
- public AbstractPostOperation(String label, IUndoContext undoContext,
- IPostOperationEnabled postOperationEnabled) {
- this(label, undoContext);
- this.postOperationEnabled = postOperationEnabled;
- }
-
- /**
- * This method will try to call the post operation on a possibly registered
- * IPostOperationEnabled implementor. Objects that were affected by the operation
- * may be passed to the registered IPostOperationEnabled implementor.
- *
- * @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) {
- if(postOperationEnabled != null){
- return postOperationEnabled.postOperation(objectAffectedByOperation) ? Status.OK_STATUS : Status.CANCEL_STATUS;
- }
- return Status.OK_STATUS;
- }
-
- /**
- * <p>Getter for the field <code>postOperationEnabled</code>.</p>
- *
- * @return a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
- */
- public IPostOperationEnabled getPostOperationEnabled() {
- return postOperationEnabled;
- }
-}
+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;
+
+ private ICdmEntitySessionEnabled cdmEntitySessionEnabled;
+
+
+ /**
+ * <p>Constructor for AbstractPostOperation.</p>
+ *
+ * @param label a {@link java.lang.String} object.
+ * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
+ */
+ 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;
+ }
+
+ public AbstractPostOperation(String label, IUndoContext undoContext,
+ T element, IPostOperationEnabled postOperationEnabled,
+ ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
+ this(label, undoContext);
+ this.element = element;
+ this.postOperationEnabled = postOperationEnabled;
+ this.cdmEntitySessionEnabled = cdmEntitySessionEnabled;
+ }
+
+ /**
+ * This method will try to call the post operation on a possibly registered
+ * IPostOperationEnabled implementor. Objects that were affected by the operation
+ * may be passed to the registered IPostOperationEnabled implementor.
+ *
+ * @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) {
+
+ if(postOperationEnabled != null){
+ return postOperationEnabled.postOperation(objectAffectedByOperation) ? Status.OK_STATUS : Status.CANCEL_STATUS;
+ }
+ return Status.OK_STATUS;
+ }
+
+ /**
+ * <p>Getter for the field <code>postOperationEnabled</code>.</p>
+ *
+ * @return a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
+ */
+ public IPostOperationEnabled getPostOperationEnabled() {
+ return postOperationEnabled;
+ }
+
+// protected IStatus updateSession(CdmBase clientObjectAffectedByOperation, UpdateResult updateResult) {
+// Set<CdmBase> affectedObjects;
+// if(updateResult == null) {
+// affectedObjects = new HashSet<CdmBase>();
+// } else {
+// affectedObjects = updateResult.getUpdatedObjects();
+// }
+//
+// if(cdmEntitySessionEnabled != null) {
+// cdmEntitySessionEnabled.getCdmEntitySession().update(clientObjectAffectedByOperation, affectedObjects);
+// }
+// return Status.OK_STATUS;
+// }
+//
+// protected IStatus updateSession(UUID uuid) {
+//
+// if(cdmEntitySessionEnabled != null) {
+// CdmBase cdmBase = cdmEntitySessionEnabled.getCdmEntitySession().remoteLoad(CdmStore.getService(IService.class),uuid);
+// cdmEntitySessionEnabled.getCdmEntitySession().update(null, cdmBase);
+// }
+// return Status.OK_STATUS;
+// }
+
+ public ICdmEntitySessionEnabled getCdmEntitySessionEnabled() {
+ return cdmEntitySessionEnabled;
+ }
+
+}
\ No newline at end of file