Project

General

Profile

Download (2.91 KB) Statistics
| Branch: | Tag: | Revision:
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 org.eclipse.core.commands.ExecutionException;
12
import org.eclipse.core.runtime.IAdaptable;
13
import org.eclipse.core.runtime.IProgressMonitor;
14
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.core.runtime.Status;
16
import org.eclipse.swt.dnd.DND;
17

    
18
import eu.etaxonomy.cdm.api.service.IFeatureNodeService;
19
import eu.etaxonomy.cdm.api.service.UpdateResult;
20
import eu.etaxonomy.cdm.model.description.Feature;
21
import eu.etaxonomy.cdm.model.term.TermNode;
22
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
23
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
24
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
25
import eu.etaxonomy.taxeditor.store.CdmStore;
26
import eu.etaxonomy.taxeditor.store.StoreUtil;
27

    
28
/**
29
 *
30
 * @author pplitzner
31
 * @date 21.01.2019
32
 *
33
 */
34
public class MoveFeatureOperation extends AbstractPostOperation<TermNode<Feature>> {
35

    
36
    private TermNode<Feature> droppedNode;
37
    private TermNode<Feature> target;
38
    private int currentOperation;
39
    private int position;
40

    
41
    public MoveFeatureOperation(TermNode<Feature> droppedNode, TermNode<Feature> target, int position,
42
            int currentOperation,
43
            IPostOperationEnabled postOperationEnabled, ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
44
        super(currentOperation == DND.DROP_MOVE ? "Move Feature" : "Copy Feature", StoreUtil.getUndoContext(),
45
                droppedNode, postOperationEnabled, cdmEntitySessionEnabled);
46
        this.droppedNode = droppedNode;
47
        this.target = target;
48
        this.position = position;
49
        this.currentOperation = currentOperation;
50
    }
51

    
52
    @Override
53
    public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
54
        UpdateResult updateResult = null;
55
        //move operation
56
        if(currentOperation==DND.DROP_MOVE){
57
            updateResult = CdmStore.getService(IFeatureNodeService.class).moveFeatureNode(droppedNode.getUuid(), target.getUuid(), position);
58
        }
59
        //copy operation
60
        else if(currentOperation==DND.DROP_COPY){
61
            updateResult = CdmStore.getService(IFeatureNodeService.class).addChildFeatureNode(target.getUuid(), droppedNode.getTerm().getUuid());
62
        }
63
        if(updateResult!=null){
64
            return postExecute(updateResult.getCdmEntity());
65
        }
66
        return Status.CANCEL_STATUS;
67
    }
68

    
69
    @Override
70
    public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
71
        return null;
72
    }
73

    
74
    @Override
75
    public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
76
        return null;
77
    }
78

    
79
}
(4-4/6)