Project

General

Profile

Download (5.53 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.Set;
12
import java.util.UUID;
13

    
14
import org.eclipse.core.runtime.IAdaptable;
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.swt.widgets.Display;
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.common.monitor.IRemotingProgressMonitor;
23
import eu.etaxonomy.taxeditor.event.EventUtility;
24
import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
25
import eu.etaxonomy.taxeditor.model.AbstractUtility;
26
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
27
import eu.etaxonomy.taxeditor.navigation.navigator.e4.TaxonNavigatorE4;
28
import eu.etaxonomy.taxeditor.navigation.navigator.e4.TreeNodeDropAdapterE4.MovingType;
29
import eu.etaxonomy.taxeditor.operation.IPostMoniteredOperationEnabled;
30
import eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation;
31

    
32
/**
33
 * @author cmathew
34
 * @date 19 Jun 2015
35
 *
36
 */
37
public class RemotingMoveTaxonOperation extends RemotingCdmUpdateOperation implements IPostMoniteredOperationEnabled {
38

    
39
    private final static String LABEL = Messages.RemotingMoveTaxonOperation_MOVE_OP;
40

    
41
    private Set<UUID> taxonNodesToMoveUuid;
42
    private final UUID newParentTreeNodeUuid;
43
    private final MovingType moveToParentNode;
44
    private TaxonNavigatorE4 taxonNavigator;
45

    
46
    public RemotingMoveTaxonOperation(Object source,
47
            boolean async,
48
            Set<UUID> taxonNodeToMoveUuid,
49
            UUID newParentTreeNodeUuid,
50
            MovingType moveToParentNode) {
51
        super(LABEL, Action.Update, source,async);
52
        taxonNodesToMoveUuid = taxonNodeToMoveUuid;
53
        this.newParentTreeNodeUuid = newParentTreeNodeUuid;
54
        this.moveToParentNode = moveToParentNode;
55

    
56
    }
57

    
58
//    public RemotingMoveTaxonOperation(Object source,
59
//            boolean async,
60
//            List<TaxonNode> taxonNodeToMove,
61
//            TaxonNode newParentTreeNode,
62
//            MovingType moveToParentNode) {
63
//        super(LABEL, Action.Update, source,async);
64
//
65
//        taxonNodesToMoveUuid=taxonNodeToMove;
66
//        this.newParentTreeNodeUuid = newParentTreeNode.getUuid();
67
//        this.moveToParentNode = moveToParentNode;
68
//    }
69

    
70

    
71
//    /**
72
//     * @param source
73
//     * @param async
74
//     * @param uuids
75
//     * @param uuid
76
//     * @param child
77
//     */
78
//    public RemotingMoveTaxonOperation(Object source, boolean async, Set<UUID> uuids, UUID uuid,
79
//            MovingType child) {
80
//        super(LABEL, Action.Update, source,async);
81
//        this.taxonNodesToMoveUuid = uuids;
82
//        this.newParentTreeNodeUuid = uuid;
83
//        this.moveToParentNode = child;
84
//    }
85

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

    
109
    public void runMoniteredOperation() {
110
        ITaxonNodeService nodeService;
111
        final UUID uuid;
112
        int movingTypeInt = -1;
113
        switch (this.moveToParentNode) {
114
        case CHILD:
115
            movingTypeInt = 0;
116
            break;
117
        case BEHIND:
118
            movingTypeInt = 2;
119
            break;
120

    
121
         default:
122
                updateResult = new UpdateResult();
123
                updateResult.setAbort();
124
                updateResult.addException(new Exception("The moving type is invalid.")); //$NON-NLS-1$
125

    
126
         }
127
        if (movingTypeInt >-1){
128
            uuid = CdmApplicationState.getLongRunningTasksService().monitLongRunningTask(taxonNodesToMoveUuid,
129
                newParentTreeNodeUuid, movingTypeInt);
130

    
131
                Display.getDefault().asyncExec(new Runnable() {
132
                    @Override
133
                    public void run() {
134
                        AbstractUtility.executeMoniteredOperation("Move Taxon to new parent: ",
135
                                uuid,
136
                                1000,
137
                                false,
138
                                RemotingMoveTaxonOperation.this,
139
                                null);
140
                    }
141
                });
142
        }
143
//        monitor.done();
144

    
145
    }
146

    
147
    /**
148
     * {@inheritDoc}
149
     */
150
    @Override
151
    public void postOperation(IRemotingProgressMonitor monitor) {
152
        monitor.done();
153
        EventUtility.postEvent(WorkbenchEventConstants.REFRESH_NAVIGATOR, true);
154

    
155
    }
156

    
157
}
(6-6/9)