Merge branch 'release/5.19.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / featuretree / e4 / operation / MoveFeatureOperation.java
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 * @author pplitzner
31 * @date 21.01.2019
32 */
33 public class MoveFeatureOperation extends AbstractPostOperation<TermNode>{
34
35 private UUID droppedNodeUuid;
36 private UUID targetUuid;
37 private UUID termUuid;
38 private int currentOperation;
39 private int position;
40
41 public MoveFeatureOperation(UUID droppedNodeUuid, UUID termUuid, UUID targetUuid, int position,
42 int currentOperation,
43 IPostOperationEnabled postOperationEnabled, ICdmEntitySessionEnabled<TermNode> cdmEntitySessionEnabled) {
44 super(currentOperation == DND.DROP_MOVE ? "Move Feature" : "Copy Feature",StoreUtil.getUndoContext(),null, postOperationEnabled, cdmEntitySessionEnabled);
45 this.droppedNodeUuid = droppedNodeUuid;
46 this.targetUuid = targetUuid;
47 this.position = position;
48 this.currentOperation = currentOperation;
49 }
50
51 @Override
52 public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
53 UpdateResult updateResult = null;
54 //move operation
55 if(currentOperation==DND.DROP_MOVE){
56 updateResult = CdmStore.getService(ITermNodeService.class).moveNode(droppedNodeUuid, targetUuid, position);
57 }
58 //copy operation
59 else if(currentOperation==DND.DROP_COPY){
60 updateResult = CdmStore.getService(ITermNodeService.class).addChildNode(targetUuid, termUuid);
61 }
62 if(updateResult!=null){
63 return postExecute(updateResult.getCdmEntity());
64 }
65 return Status.CANCEL_STATUS;
66 }
67
68 @Override
69 public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
70 return null;
71 }
72
73 @Override
74 public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
75 return null;
76 }
77
78 /**
79 * This method will try to call the post operation on a possibly registered
80 * IPostOperationEnabled implementor. Objects that were affected by the operation
81 * may be passed to the registered IPostOperationEnabled implementor.
82 *
83 * @param objectAffectedByOperation the affected object. Should be <code>null</code> if not needed
84 * @return a {@link org.eclipse.core.runtime.IStatus} object.
85 */
86 @Override
87 protected IStatus postExecute(Object objectAffectedByOperation) {
88
89 if(postOperationEnabled != null){
90 return postOperationEnabled.postOperation(objectAffectedByOperation) ? Status.OK_STATUS : Status.CANCEL_STATUS;
91 }
92 return Status.OK_STATUS;
93 }
94
95 /**
96 * <p>Getter for the field <code>postOperationEnabled</code>.</p>
97 *
98 * @return a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
99 */
100 @Override
101 public IPostOperationEnabled getPostOperationEnabled() {
102 return postOperationEnabled;
103 }
104 }