2 * Copyright (C) 2018 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
.featuretree
.e4
.operation
;
11 import java
.util
.UUID
;
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
;
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
;
33 public class MoveFeatureOperation
extends AbstractPostOperation
<TermNode
>{
35 private UUID droppedNodeUuid
;
36 private UUID targetUuid
;
37 private UUID termUuid
;
38 private int currentOperation
;
41 public MoveFeatureOperation(UUID droppedNodeUuid
, UUID termUuid
, UUID targetUuid
, int position
,
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
;
52 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
) throws ExecutionException
{
53 UpdateResult updateResult
= null;
55 if(currentOperation
==DND
.DROP_MOVE
){
56 updateResult
= CdmStore
.getService(ITermNodeService
.class).moveNode(droppedNodeUuid
, targetUuid
, position
);
59 else if(currentOperation
==DND
.DROP_COPY
){
60 updateResult
= CdmStore
.getService(ITermNodeService
.class).addChildNode(targetUuid
, termUuid
);
62 if(updateResult
!=null){
63 return postExecute(updateResult
.getCdmEntity());
65 return Status
.CANCEL_STATUS
;
69 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
) throws ExecutionException
{
74 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
) throws ExecutionException
{
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.
83 * @param objectAffectedByOperation the affected object. Should be <code>null</code> if not needed
84 * @return a {@link org.eclipse.core.runtime.IStatus} object.
87 protected IStatus
postExecute(Object objectAffectedByOperation
) {
89 if(postOperationEnabled
!= null){
90 return postOperationEnabled
.postOperation(objectAffectedByOperation
) ? Status
.OK_STATUS
: Status
.CANCEL_STATUS
;
92 return Status
.OK_STATUS
;
96 * <p>Getter for the field <code>postOperationEnabled</code>.</p>
98 * @return a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
101 public IPostOperationEnabled
getPostOperationEnabled() {
102 return postOperationEnabled
;