1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2015 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package eu.etaxonomy.taxeditor.navigation.navigator.handler;
|
11
|
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.List;
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import org.eclipse.core.commands.ExecutionEvent;
|
17
|
import org.eclipse.core.commands.operations.AbstractOperation;
|
18
|
import org.eclipse.core.runtime.IStatus;
|
19
|
import org.eclipse.core.runtime.Status;
|
20
|
import org.eclipse.jface.dialogs.MessageDialog;
|
21
|
import org.eclipse.jface.viewers.TreeSelection;
|
22
|
import org.eclipse.ui.handlers.HandlerUtil;
|
23
|
|
24
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolderMock;
|
25
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
26
|
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
|
27
|
import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigatorLabels;
|
28
|
import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingMoveTaxonOperation;
|
29
|
import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
|
30
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
31
|
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
|
32
|
|
33
|
/**
|
34
|
* @author cmathew
|
35
|
* @date 19 Jun 2015
|
36
|
*
|
37
|
*/
|
38
|
public class RemotingMoveTaxonHandler extends RemotingCdmHandler {
|
39
|
|
40
|
private TaxonNode oldTaxonNode;
|
41
|
|
42
|
public RemotingMoveTaxonHandler() {
|
43
|
super(TaxonNavigatorLabels.MOVE_TAXON_LABEL);
|
44
|
}
|
45
|
|
46
|
/* (non-Javadoc)
|
47
|
* @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent)
|
48
|
*/
|
49
|
@Override
|
50
|
public IStatus allowOperations(ExecutionEvent event) {
|
51
|
TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event);
|
52
|
// check that only a single taxon tree node has been selected
|
53
|
if(selection.size() > 1) {
|
54
|
return new Status(IStatus.ERROR,
|
55
|
"unknown",
|
56
|
TaxonNavigatorLabels.SINGLE_TAXON_SELECTION_MESSAGE);
|
57
|
}
|
58
|
|
59
|
// check for no taxon tree node selected
|
60
|
if(selection.size() == 0) {
|
61
|
return new Status(IStatus.ERROR,
|
62
|
"unknown",
|
63
|
TaxonNavigatorLabels.NO_TAXON_SELECTION_MESSAGE);
|
64
|
}
|
65
|
// check that selected object is a taxon node
|
66
|
Object obj = selection.iterator().next();
|
67
|
if(obj instanceof TaxonNode) {
|
68
|
oldTaxonNode = (TaxonNode)obj;
|
69
|
} else {
|
70
|
return new Status(IStatus.ERROR,
|
71
|
"unknown",
|
72
|
TaxonNavigatorLabels.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE);
|
73
|
}
|
74
|
return Status.OK_STATUS;
|
75
|
}
|
76
|
|
77
|
/* (non-Javadoc)
|
78
|
* @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#prepareOperation(org.eclipse.core.commands.ExecutionEvent)
|
79
|
*/
|
80
|
@Override
|
81
|
public AbstractOperation prepareOperation(ExecutionEvent event) {
|
82
|
TaxonNode parentTaxonNode;
|
83
|
|
84
|
List<UUID> excludeTaxa = new ArrayList<UUID>();
|
85
|
excludeTaxa.add(oldTaxonNode.getUuid());
|
86
|
|
87
|
boolean moveToNewParent = true;
|
88
|
|
89
|
if (PreferencesUtil.getSortNodesNaturally()){
|
90
|
if(!MessageDialog.openQuestion(null, "Target node", "The choosen target node should be the parent?")){
|
91
|
moveToNewParent = false;
|
92
|
}
|
93
|
parentTaxonNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event),
|
94
|
new ConversationHolderMock(),
|
95
|
"Choose the taxon above the moved taxon.",
|
96
|
excludeTaxa,
|
97
|
null,
|
98
|
null);
|
99
|
} else {
|
100
|
parentTaxonNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event),
|
101
|
new ConversationHolderMock(),
|
102
|
"Choose new parent",
|
103
|
excludeTaxa,
|
104
|
null,
|
105
|
null);
|
106
|
}
|
107
|
if(parentTaxonNode != null){
|
108
|
if(NavigationUtil.isDirty(parentTaxonNode)){
|
109
|
MessageDialog.openWarning(HandlerUtil.getActiveShell(event),
|
110
|
"Unsaved Parent Taxon",
|
111
|
"There are unsaved changes in the parent taxon. Please save first.");
|
112
|
return null;
|
113
|
}
|
114
|
|
115
|
return new RemotingMoveTaxonOperation(event.getTrigger(),
|
116
|
false,
|
117
|
oldTaxonNode.getUuid(),
|
118
|
parentTaxonNode.getUuid(),
|
119
|
moveToNewParent);
|
120
|
}
|
121
|
|
122
|
return null;
|
123
|
}
|
124
|
|
125
|
/* (non-Javadoc)
|
126
|
* @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete()
|
127
|
*/
|
128
|
@Override
|
129
|
public void onComplete() {
|
130
|
// TODO Auto-generated method stub
|
131
|
|
132
|
}
|
133
|
|
134
|
}
|