2 * Copyright (C) 2013 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.operation
;
11 import org
.eclipse
.core
.commands
.operations
.AbstractOperation
;
12 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
13 import org
.eclipse
.core
.runtime
.IStatus
;
14 import org
.eclipse
.core
.runtime
.Status
;
16 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
17 import eu
.etaxonomy
.cdm
.model
.common
.ICdmBase
;
18 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySessionEnabled
;
25 public abstract class AbstractPostOperation
<T
extends ICdmBase
> extends AbstractOperation
{
29 * A reference to the {@link ICdmBase} element the concrete operation is working on
36 protected IPostOperationEnabled postOperationEnabled
;
38 private ICdmEntitySessionEnabled cdmEntitySessionEnabled
;
42 * <p>Constructor for AbstractPostOperation.</p>
44 * @param label a {@link java.lang.String} object.
45 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
47 protected AbstractPostOperation(String label
, IUndoContext undoContext
) {
49 addContext(undoContext
);
53 * <p>Constructor for AbstractPostOperation.</p>
55 * @param label a {@link java.lang.String} object.
56 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
57 * @param element a {@link ICdmBase} object on which this operation is working.
59 public AbstractPostOperation(String label
, IUndoContext undoContext
, T element
) {
60 this(label
, undoContext
);
61 this.element
= element
;
67 * @param postOperationEnabled
69 public AbstractPostOperation(String label
, IUndoContext undoContext
,
70 T element
, IPostOperationEnabled postOperationEnabled
) {
71 this(label
, undoContext
);
72 this.element
= element
;
73 this.postOperationEnabled
= postOperationEnabled
;
76 public AbstractPostOperation(String label
, IUndoContext undoContext
,
77 T element
, IPostOperationEnabled postOperationEnabled
,
78 ICdmEntitySessionEnabled cdmEntitySessionEnabled
) {
79 this(label
, undoContext
);
80 this.element
= element
;
81 this.postOperationEnabled
= postOperationEnabled
;
82 this.cdmEntitySessionEnabled
= cdmEntitySessionEnabled
;
86 * This method will try to call the post operation on a possibly registered
87 * IPostOperationEnabled implementor. Objects that were affected by the operation
88 * may be passed to the registered IPostOperationEnabled implementor.
90 * @param objectAffectedByOperation the affected object. Should be <code>null</code> if not needed
91 * @return a {@link org.eclipse.core.runtime.IStatus} object.
93 protected IStatus
postExecute(CdmBase objectAffectedByOperation
) {
95 if(postOperationEnabled
!= null){
96 return postOperationEnabled
.postOperation(objectAffectedByOperation
) ? Status
.OK_STATUS
: Status
.CANCEL_STATUS
;
98 return Status
.OK_STATUS
;
102 * <p>Getter for the field <code>postOperationEnabled</code>.</p>
104 * @return a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
106 public IPostOperationEnabled
getPostOperationEnabled() {
107 return postOperationEnabled
;
110 // protected IStatus updateSession(CdmBase clientObjectAffectedByOperation, UpdateResult updateResult) {
111 // Set<CdmBase> affectedObjects;
112 // if(updateResult == null) {
113 // affectedObjects = new HashSet<CdmBase>();
115 // affectedObjects = updateResult.getUpdatedObjects();
118 // if(cdmEntitySessionEnabled != null) {
119 // cdmEntitySessionEnabled.getCdmEntitySession().update(clientObjectAffectedByOperation, affectedObjects);
121 // return Status.OK_STATUS;
124 // protected IStatus updateSession(UUID uuid) {
126 // if(cdmEntitySessionEnabled != null) {
127 // CdmBase cdmBase = cdmEntitySessionEnabled.getCdmEntitySession().remoteLoad(CdmStore.getService(IService.class),uuid);
128 // cdmEntitySessionEnabled.getCdmEntitySession().update(null, cdmBase);
130 // return Status.OK_STATUS;
133 public ICdmEntitySessionEnabled
getCdmEntitySessionEnabled() {
134 return cdmEntitySessionEnabled
;