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 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;
|
15
|
|
16
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
17
|
import eu.etaxonomy.cdm.model.common.ICdmBase;
|
18
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
|
19
|
|
20
|
/**
|
21
|
* @author pplitzner
|
22
|
* @date 03.12.2013
|
23
|
*
|
24
|
*/
|
25
|
public abstract class AbstractPostOperation<T extends ICdmBase> extends AbstractOperation {
|
26
|
|
27
|
|
28
|
/**
|
29
|
* A reference to the {@link ICdmBase} element the concrete operation is working on
|
30
|
*/
|
31
|
protected T element;
|
32
|
|
33
|
/**
|
34
|
*
|
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
|
this.postOperationEnabled = postOperationEnabled;
|
58
|
this.cdmEntitySessionEnabled = cdmEntitySessionEnabled;
|
59
|
}
|
60
|
|
61
|
/**
|
62
|
* This method will try to call the post operation on a possibly registered
|
63
|
* IPostOperationEnabled implementor. Objects that were affected by the operation
|
64
|
* may be passed to the registered IPostOperationEnabled implementor.
|
65
|
*
|
66
|
* @param objectAffectedByOperation the affected object. Should be <code>null</code> if not needed
|
67
|
* @return a {@link org.eclipse.core.runtime.IStatus} object.
|
68
|
*/
|
69
|
protected IStatus postExecute(CdmBase objectAffectedByOperation) {
|
70
|
|
71
|
if(postOperationEnabled != null){
|
72
|
return postOperationEnabled.postOperation(objectAffectedByOperation) ? Status.OK_STATUS : Status.CANCEL_STATUS;
|
73
|
}
|
74
|
return Status.OK_STATUS;
|
75
|
}
|
76
|
|
77
|
/**
|
78
|
* <p>Getter for the field <code>postOperationEnabled</code>.</p>
|
79
|
*
|
80
|
* @return a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
|
81
|
*/
|
82
|
public IPostOperationEnabled getPostOperationEnabled() {
|
83
|
return postOperationEnabled;
|
84
|
}
|
85
|
|
86
|
// protected IStatus updateSession(CdmBase clientObjectAffectedByOperation, UpdateResult updateResult) {
|
87
|
// Set<CdmBase> affectedObjects;
|
88
|
// if(updateResult == null) {
|
89
|
// affectedObjects = new HashSet<CdmBase>();
|
90
|
// } else {
|
91
|
// affectedObjects = updateResult.getUpdatedObjects();
|
92
|
// }
|
93
|
//
|
94
|
// if(cdmEntitySessionEnabled != null) {
|
95
|
// cdmEntitySessionEnabled.getCdmEntitySession().update(clientObjectAffectedByOperation, affectedObjects);
|
96
|
// }
|
97
|
// return Status.OK_STATUS;
|
98
|
// }
|
99
|
//
|
100
|
// protected IStatus updateSession(UUID uuid) {
|
101
|
//
|
102
|
// if(cdmEntitySessionEnabled != null) {
|
103
|
// CdmBase cdmBase = cdmEntitySessionEnabled.getCdmEntitySession().remoteLoad(CdmStore.getService(IService.class),uuid);
|
104
|
// cdmEntitySessionEnabled.getCdmEntitySession().update(null, cdmBase);
|
105
|
// }
|
106
|
// return Status.OK_STATUS;
|
107
|
// }
|
108
|
|
109
|
public ICdmEntitySessionEnabled getCdmEntitySessionEnabled() {
|
110
|
return cdmEntitySessionEnabled;
|
111
|
}
|
112
|
|
113
|
}
|