1
|
/**
|
2
|
* Copyright (C) 2018 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.featuretree.e4.operation;
|
10
|
|
11
|
import java.util.UUID;
|
12
|
|
13
|
import org.eclipse.core.commands.ExecutionException;
|
14
|
import org.eclipse.core.runtime.IAdaptable;
|
15
|
import org.eclipse.core.runtime.IProgressMonitor;
|
16
|
import org.eclipse.core.runtime.IStatus;
|
17
|
import org.eclipse.core.runtime.Status;
|
18
|
import org.eclipse.swt.dnd.DND;
|
19
|
|
20
|
import eu.etaxonomy.cdm.api.service.ITermNodeService;
|
21
|
import eu.etaxonomy.cdm.api.service.UpdateResult;
|
22
|
import eu.etaxonomy.cdm.model.term.TermNode;
|
23
|
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
|
24
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
25
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
|
26
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
27
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
28
|
|
29
|
/**
|
30
|
*
|
31
|
* @author pplitzner
|
32
|
* @date 21.01.2019
|
33
|
*
|
34
|
*/
|
35
|
public class MoveFeatureOperation extends AbstractPostOperation<TermNode>{
|
36
|
|
37
|
private UUID droppedNodeUuid;
|
38
|
private UUID targetUuid;
|
39
|
private UUID termUuid;
|
40
|
private int currentOperation;
|
41
|
private int position;
|
42
|
|
43
|
// protected IPostOperationEnabled postOperationEnabled;
|
44
|
|
45
|
private ICdmEntitySessionEnabled cdmEntitySessionEnabled;
|
46
|
|
47
|
|
48
|
public MoveFeatureOperation(UUID droppedNodeUuid, UUID termUuid, UUID targetUuid, int position,
|
49
|
int currentOperation,
|
50
|
IPostOperationEnabled postOperationEnabled, ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
|
51
|
super(currentOperation == DND.DROP_MOVE ? "Move Feature" : "Copy Feature",StoreUtil.getUndoContext(),null, postOperationEnabled, cdmEntitySessionEnabled);
|
52
|
this.droppedNodeUuid = droppedNodeUuid;
|
53
|
this.targetUuid = targetUuid;
|
54
|
this.position = position;
|
55
|
this.currentOperation = currentOperation;
|
56
|
}
|
57
|
|
58
|
@Override
|
59
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
|
60
|
UpdateResult updateResult = null;
|
61
|
//move operation
|
62
|
if(currentOperation==DND.DROP_MOVE){
|
63
|
updateResult = CdmStore.getService(ITermNodeService.class).moveNode(droppedNodeUuid, targetUuid, position);
|
64
|
}
|
65
|
//copy operation
|
66
|
else if(currentOperation==DND.DROP_COPY){
|
67
|
updateResult = CdmStore.getService(ITermNodeService.class).addChildNode(targetUuid, termUuid);
|
68
|
}
|
69
|
if(updateResult!=null){
|
70
|
return postExecute(updateResult.getCdmEntity());
|
71
|
}
|
72
|
return Status.CANCEL_STATUS;
|
73
|
}
|
74
|
|
75
|
@Override
|
76
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
|
77
|
return null;
|
78
|
}
|
79
|
|
80
|
@Override
|
81
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
|
82
|
return null;
|
83
|
}
|
84
|
|
85
|
/**
|
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.
|
89
|
*
|
90
|
* @param objectAffectedByOperation the affected object. Should be <code>null</code> if not needed
|
91
|
* @return a {@link org.eclipse.core.runtime.IStatus} object.
|
92
|
*/
|
93
|
@Override
|
94
|
protected IStatus postExecute(Object objectAffectedByOperation) {
|
95
|
|
96
|
if(postOperationEnabled != null){
|
97
|
return postOperationEnabled.postOperation(objectAffectedByOperation) ? Status.OK_STATUS : Status.CANCEL_STATUS;
|
98
|
}
|
99
|
return Status.OK_STATUS;
|
100
|
}
|
101
|
|
102
|
/**
|
103
|
* <p>Getter for the field <code>postOperationEnabled</code>.</p>
|
104
|
*
|
105
|
* @return a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
|
106
|
*/
|
107
|
@Override
|
108
|
public IPostOperationEnabled getPostOperationEnabled() {
|
109
|
return postOperationEnabled;
|
110
|
}
|
111
|
}
|