Project

General

Profile

Download (2.8 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.ITermNodeService;
19
import eu.etaxonomy.cdm.api.service.UpdateResult;
20
import eu.etaxonomy.cdm.model.term.TermNode;
21
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
22
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
23
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
24
import eu.etaxonomy.taxeditor.store.CdmStore;
25
import eu.etaxonomy.taxeditor.store.StoreUtil;
26

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

    
35
    private TermNode droppedNode;
36
    private TermNode target;
37
    private int currentOperation;
38
    private int position;
39

    
40
    public MoveFeatureOperation(TermNode droppedNode, TermNode target, int position,
41
            int currentOperation,
42
            IPostOperationEnabled postOperationEnabled, ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
43
        super(currentOperation == DND.DROP_MOVE ? "Move Feature" : "Copy Feature", StoreUtil.getUndoContext(),
44
                droppedNode, postOperationEnabled, cdmEntitySessionEnabled);
45
        this.droppedNode = droppedNode;
46
        this.target = target;
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(droppedNode.getUuid(), target.getUuid(), position);
57
        }
58
        //copy operation
59
        else if(currentOperation==DND.DROP_COPY){
60
            updateResult = CdmStore.getService(ITermNodeService.class).addChildNode(target.getUuid(), droppedNode.getTerm().getUuid());
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
}
(4-4/6)