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.cdm.persistence.dto.TaxonNodeDto;
|
24
|
import eu.etaxonomy.taxeditor.event.EventUtility;
|
25
|
import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
|
26
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
27
|
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
|
28
|
import eu.etaxonomy.taxeditor.navigation.navigator.e4.TaxonNavigatorE4;
|
29
|
import eu.etaxonomy.taxeditor.navigation.navigator.e4.TreeNodeDropAdapterE4.MovingType;
|
30
|
import eu.etaxonomy.taxeditor.operation.IPostMoniteredOperationEnabled;
|
31
|
import eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation;
|
32
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
33
|
|
34
|
/**
|
35
|
* @author cmathew
|
36
|
* @date 19 Jun 2015
|
37
|
*
|
38
|
*/
|
39
|
public class RemotingMoveTaxonOperation extends RemotingCdmUpdateOperation implements IPostMoniteredOperationEnabled {
|
40
|
|
41
|
private final static String LABEL = Messages.RemotingMoveTaxonOperation_MOVE_OP;
|
42
|
|
43
|
private Set<UUID> taxonNodesToMoveUuid;
|
44
|
private final UUID newParentTreeNodeUuid;
|
45
|
private final MovingType moveToParentNode;
|
46
|
private TaxonNavigatorE4 taxonNavigator;
|
47
|
|
48
|
public RemotingMoveTaxonOperation(Object source,
|
49
|
boolean async,
|
50
|
Set<UUID> taxonNodeToMoveUuid,
|
51
|
UUID newParentTreeNodeUuid,
|
52
|
MovingType moveToParentNode) {
|
53
|
super(LABEL, Action.Update, source,async);
|
54
|
taxonNodesToMoveUuid = taxonNodeToMoveUuid;
|
55
|
this.newParentTreeNodeUuid = newParentTreeNodeUuid;
|
56
|
this.moveToParentNode = moveToParentNode;
|
57
|
|
58
|
}
|
59
|
|
60
|
/* (non-Javadoc)
|
61
|
* @see eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation#doUpdateExecute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
62
|
*/
|
63
|
@Override
|
64
|
protected UpdateResult doUpdateExecute(IProgressMonitor monitor, IAdaptable info) throws Exception {
|
65
|
runMoniteredOperation();
|
66
|
return updateResult;
|
67
|
}
|
68
|
|
69
|
public void runMoniteredOperation() {
|
70
|
ITaxonNodeService nodeService;
|
71
|
final UUID uuid;
|
72
|
int movingTypeInt = -1;
|
73
|
switch (this.moveToParentNode) {
|
74
|
case CHILD:
|
75
|
movingTypeInt = 0;
|
76
|
break;
|
77
|
case BEHIND:
|
78
|
movingTypeInt = 2;
|
79
|
break;
|
80
|
|
81
|
default:
|
82
|
updateResult = new UpdateResult();
|
83
|
updateResult.setAbort();
|
84
|
updateResult.addException(new Exception("The moving type is invalid.")); //$NON-NLS-1$
|
85
|
|
86
|
}
|
87
|
if (movingTypeInt >-1){
|
88
|
uuid = CdmApplicationState.getLongRunningTasksService().monitLongRunningTask(taxonNodesToMoveUuid,
|
89
|
newParentTreeNodeUuid, movingTypeInt);
|
90
|
|
91
|
Display.getDefault().asyncExec(new Runnable() {
|
92
|
@Override
|
93
|
public void run() {
|
94
|
AbstractUtility.executeMoniteredOperation("Move Taxon to new parent: ",
|
95
|
uuid,
|
96
|
500,
|
97
|
false,
|
98
|
RemotingMoveTaxonOperation.this,
|
99
|
null,
|
100
|
true);
|
101
|
}
|
102
|
});
|
103
|
}
|
104
|
|
105
|
|
106
|
}
|
107
|
|
108
|
/**
|
109
|
* {@inheritDoc}
|
110
|
*/
|
111
|
@Override
|
112
|
public void postOperation(IRemotingProgressMonitor monitor) {
|
113
|
monitor.done();
|
114
|
TaxonNodeDto parentDto = CdmStore.getService(ITaxonNodeService.class).dto(newParentTreeNodeUuid);
|
115
|
EventUtility.postEvent(WorkbenchEventConstants.REFRESH_NAVIGATOR, parentDto);
|
116
|
|
117
|
}
|
118
|
|
119
|
}
|