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 java
.util
.UUID
;
13 import org
.eclipse
.core
.commands
.operations
.AbstractOperation
;
14 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
15 import org
.eclipse
.core
.runtime
.IStatus
;
16 import org
.eclipse
.core
.runtime
.Status
;
18 import eu
.etaxonomy
.cdm
.model
.common
.ICdmBase
;
19 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySessionEnabled
;
26 public abstract class AbstractPostOperation
<T
extends ICdmBase
> extends AbstractOperation
{
30 * A reference to the {@link ICdmBase} element the concrete operation is working on
34 protected UUID elementUuid
;
36 protected IPostOperationEnabled postOperationEnabled
;
38 private ICdmEntitySessionEnabled cdmEntitySessionEnabled
;
44 * @param postOperationEnabled
46 public AbstractPostOperation(String label
, IUndoContext undoContext
,
47 T element
, IPostOperationEnabled postOperationEnabled
) {
48 this(label
, undoContext
, element
, postOperationEnabled
, null);
51 public AbstractPostOperation(String label
, IUndoContext undoContext
,
52 T element
, IPostOperationEnabled postOperationEnabled
,
53 ICdmEntitySessionEnabled cdmEntitySessionEnabled
) {
55 addContext(undoContext
);
56 this.element
= element
;
58 this.elementUuid
= element
.getUuid();
60 this.postOperationEnabled
= postOperationEnabled
;
61 this.cdmEntitySessionEnabled
= cdmEntitySessionEnabled
;
64 public AbstractPostOperation(String label
, UUID elementUuid
, IUndoContext undoContext
,
65 IPostOperationEnabled postOperationEnabled
,
66 ICdmEntitySessionEnabled cdmEntitySessionEnabled
) {
68 addContext(undoContext
);
70 this.elementUuid
= elementUuid
;
71 this.postOperationEnabled
= postOperationEnabled
;
72 this.cdmEntitySessionEnabled
= cdmEntitySessionEnabled
;
75 public T
getElement() {
79 public UUID
getElementUuid(){
85 * This method will try to call the post operation on a possibly registered
86 * IPostOperationEnabled implementor. Objects that were affected by the operation
87 * may be passed to the registered IPostOperationEnabled implementor.
89 * @param objectAffectedByOperation the affected object. Should be <code>null</code> if not needed
90 * @return a {@link org.eclipse.core.runtime.IStatus} object.
92 protected IStatus
postExecute(Object objectAffectedByOperation
) {
94 if(postOperationEnabled
!= null){
95 return postOperationEnabled
.postOperation(objectAffectedByOperation
) ? Status
.OK_STATUS
: Status
.CANCEL_STATUS
;
97 return Status
.OK_STATUS
;
101 * <p>Getter for the field <code>postOperationEnabled</code>.</p>
103 * @return a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
105 public IPostOperationEnabled
getPostOperationEnabled() {
106 return postOperationEnabled
;
109 // protected IStatus updateSession(CdmBase clientObjectAffectedByOperation, UpdateResult updateResult) {
110 // Set<CdmBase> affectedObjects;
111 // if(updateResult == null) {
112 // affectedObjects = new HashSet<CdmBase>();
114 // affectedObjects = updateResult.getUpdatedObjects();
117 // if(cdmEntitySessionEnabled != null) {
118 // cdmEntitySessionEnabled.getCdmEntitySession().update(clientObjectAffectedByOperation, affectedObjects);
120 // return Status.OK_STATUS;
123 // protected IStatus updateSession(UUID uuid) {
125 // if(cdmEntitySessionEnabled != null) {
126 // CdmBase cdmBase = cdmEntitySessionEnabled.getCdmEntitySession().remoteLoad(CdmStore.getService(IService.class),uuid);
127 // cdmEntitySessionEnabled.getCdmEntitySession().update(null, cdmBase);
129 // return Status.OK_STATUS;
132 public ICdmEntitySessionEnabled
getCdmEntitySessionEnabled() {
133 return cdmEntitySessionEnabled
;