Project

General

Profile

Download (3.66 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2015 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.navigation.navigator.operation;
10

    
11
import java.util.HashSet;
12
import java.util.Set;
13
import java.util.UUID;
14

    
15
import org.eclipse.core.runtime.IAdaptable;
16
import org.eclipse.core.runtime.IProgressMonitor;
17

    
18
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
19
import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
20
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
21
import eu.etaxonomy.cdm.api.service.UpdateResult;
22
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
23
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
24
import eu.etaxonomy.taxeditor.navigation.navigator.e4.TreeNodeDropAdapterE4.MovingType;
25
import eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation;
26

    
27
/**
28
 * @author cmathew
29
 * @date 19 Jun 2015
30
 *
31
 */
32
public class RemotingMoveTaxonOperation extends RemotingCdmUpdateOperation {
33

    
34
    private final static String LABEL = Messages.RemotingMoveTaxonOperation_MOVE_OP;
35

    
36
    private final Set<UUID> taxonNodesToMoveUuid;
37
    private final UUID newParentTreeNodeUuid;
38
    private final MovingType moveToParentNode;
39

    
40
    public RemotingMoveTaxonOperation(Object source,
41
            boolean async,
42
            UUID taxonNodeToMoveUuid,
43
            UUID newParentTreeNodeUuid,
44
            MovingType moveToParentNode) {
45
        super(LABEL, Action.Update, source,async);
46
        taxonNodesToMoveUuid = new HashSet<UUID>();
47
        taxonNodesToMoveUuid.add(taxonNodeToMoveUuid);
48
        this.newParentTreeNodeUuid = newParentTreeNodeUuid;
49
        this.moveToParentNode = moveToParentNode;
50
    }
51

    
52
    public RemotingMoveTaxonOperation(Object source,
53
            boolean async,
54
            TaxonNode taxonNodeToMove,
55
            TaxonNode newParentTreeNode,
56
            MovingType moveToParentNode) {
57
        super(LABEL, Action.Update, source,async);
58
        taxonNodesToMoveUuid = new HashSet<UUID>();
59
        taxonNodesToMoveUuid.add(taxonNodeToMove.getUuid());
60
        this.newParentTreeNodeUuid = newParentTreeNode.getUuid();
61
        this.moveToParentNode = moveToParentNode;
62
    }
63

    
64

    
65
    /**
66
     * @param source
67
     * @param async
68
     * @param uuids
69
     * @param uuid
70
     * @param child
71
     */
72
    public RemotingMoveTaxonOperation(Object source, boolean async, Set<UUID> uuids, UUID uuid,
73
            MovingType child) {
74
        super(LABEL, Action.Update, source,async);
75
        this.taxonNodesToMoveUuid = uuids;
76
        this.newParentTreeNodeUuid = uuid;
77
        this.moveToParentNode = child;
78
    }
79

    
80
    /* (non-Javadoc)
81
     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation#doUpdateExecute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
82
     */
83
    @Override
84
    protected UpdateResult doUpdateExecute(IProgressMonitor monitor, IAdaptable info) throws Exception {
85
        switch (this.moveToParentNode) {
86
            case CHILD:
87
                return CdmApplicationState.getService(ITaxonNodeService.class).moveTaxonNodes(taxonNodesToMoveUuid,
88
                        newParentTreeNodeUuid, 0);
89
            case BEHIND:
90
                return CdmApplicationState.getService(ITaxonNodeService.class).moveTaxonNodes(taxonNodesToMoveUuid,
91
                newParentTreeNodeUuid, 2);
92
             default:
93
                    UpdateResult result = new UpdateResult();
94
                    result.setAbort();
95
                    result.addException(new Exception("The moving type is invalid.")); //$NON-NLS-1$
96
                    return result;
97
        }
98
    }
99

    
100
}
(6-6/9)