Merge branch 'release/5.18.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / operation / AbstractPostOperation.java
1 /**
2 * Copyright (C) 2013 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9 package eu.etaxonomy.taxeditor.operation;
10
11 import java.util.UUID;
12
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;
17
18 import eu.etaxonomy.cdm.model.common.ICdmBase;
19 import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
20
21 /**
22 * @author pplitzner
23 * @date 03.12.2013
24 *
25 */
26 public abstract class AbstractPostOperation<T extends ICdmBase> extends AbstractOperation {
27
28
29 /**
30 * A reference to the {@link ICdmBase} element the concrete operation is working on
31 */
32 protected T element;
33
34 protected UUID elementUuid;
35
36 protected IPostOperationEnabled postOperationEnabled;
37
38 private ICdmEntitySessionEnabled cdmEntitySessionEnabled;
39
40
41 /**
42 * @param label
43 * @param element
44 * @param postOperationEnabled
45 */
46 public AbstractPostOperation(String label, IUndoContext undoContext,
47 T element, IPostOperationEnabled postOperationEnabled) {
48 this(label, undoContext, element, postOperationEnabled, null);
49 }
50
51 public AbstractPostOperation(String label, IUndoContext undoContext,
52 T element, IPostOperationEnabled postOperationEnabled,
53 ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
54 super(label);
55 addContext(undoContext);
56 this.element = element;
57 if (element != null){
58 this.elementUuid = element.getUuid();
59 }
60 this.postOperationEnabled = postOperationEnabled;
61 this.cdmEntitySessionEnabled = cdmEntitySessionEnabled;
62 }
63
64 public AbstractPostOperation(String label, UUID elementUuid, IUndoContext undoContext,
65 IPostOperationEnabled postOperationEnabled,
66 ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
67 super(label);
68 addContext(undoContext);
69 this.element = null;
70 this.elementUuid = elementUuid;
71 this.postOperationEnabled = postOperationEnabled;
72 this.cdmEntitySessionEnabled = cdmEntitySessionEnabled;
73 }
74
75 public T getElement() {
76 return element;
77 }
78
79 public UUID getElementUuid(){
80 return elementUuid;
81 }
82
83
84 /**
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.
88 *
89 * @param objectAffectedByOperation the affected object. Should be <code>null</code> if not needed
90 * @return a {@link org.eclipse.core.runtime.IStatus} object.
91 */
92 protected IStatus postExecute(Object objectAffectedByOperation) {
93
94 if(postOperationEnabled != null){
95 return postOperationEnabled.postOperation(objectAffectedByOperation) ? Status.OK_STATUS : Status.CANCEL_STATUS;
96 }
97 return Status.OK_STATUS;
98 }
99
100 /**
101 * <p>Getter for the field <code>postOperationEnabled</code>.</p>
102 *
103 * @return a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
104 */
105 public IPostOperationEnabled getPostOperationEnabled() {
106 return postOperationEnabled;
107 }
108
109 // protected IStatus updateSession(CdmBase clientObjectAffectedByOperation, UpdateResult updateResult) {
110 // Set<CdmBase> affectedObjects;
111 // if(updateResult == null) {
112 // affectedObjects = new HashSet<CdmBase>();
113 // } else {
114 // affectedObjects = updateResult.getUpdatedObjects();
115 // }
116 //
117 // if(cdmEntitySessionEnabled != null) {
118 // cdmEntitySessionEnabled.getCdmEntitySession().update(clientObjectAffectedByOperation, affectedObjects);
119 // }
120 // return Status.OK_STATUS;
121 // }
122 //
123 // protected IStatus updateSession(UUID uuid) {
124 //
125 // if(cdmEntitySessionEnabled != null) {
126 // CdmBase cdmBase = cdmEntitySessionEnabled.getCdmEntitySession().remoteLoad(CdmStore.getService(IService.class),uuid);
127 // cdmEntitySessionEnabled.getCdmEntitySession().update(null, cdmBase);
128 // }
129 // return Status.OK_STATUS;
130 // }
131
132 public ICdmEntitySessionEnabled getCdmEntitySessionEnabled() {
133 return cdmEntitySessionEnabled;
134 }
135
136 }