1
|
/**
|
2
|
*
|
3
|
*/
|
4
|
package eu.etaxonomy.taxeditor.navigation.navigator.handler;
|
5
|
|
6
|
import java.util.ArrayList;
|
7
|
import java.util.List;
|
8
|
import java.util.UUID;
|
9
|
|
10
|
import org.apache.log4j.Logger;
|
11
|
import org.eclipse.core.commands.ExecutionEvent;
|
12
|
import org.eclipse.core.commands.operations.AbstractOperation;
|
13
|
import org.eclipse.core.runtime.IStatus;
|
14
|
import org.eclipse.core.runtime.Status;
|
15
|
import org.eclipse.jface.viewers.TreeSelection;
|
16
|
import org.eclipse.ui.handlers.HandlerUtil;
|
17
|
|
18
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolderMock;
|
19
|
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
|
20
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
21
|
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
|
22
|
import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigatorLabels;
|
23
|
import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingChangeAcceptedTaxonToSynonymOperation;
|
24
|
import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
|
25
|
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
|
26
|
|
27
|
/**
|
28
|
* <p>ChangeAcceptedTaxonToSynonymHandler class.</p>
|
29
|
*
|
30
|
* @author n.hoffmann
|
31
|
* @created Jan 4, 2010
|
32
|
* @version 1.0
|
33
|
*/
|
34
|
public class RemotingChangeAcceptedTaxonToSynonymHandler extends RemotingCdmHandler {
|
35
|
|
36
|
private static final Logger logger = Logger
|
37
|
.getLogger(RemotingChangeAcceptedTaxonToSynonymHandler.class);
|
38
|
|
39
|
|
40
|
private ITaxonTreeNode oldTaxonNode;
|
41
|
|
42
|
/**
|
43
|
* @param label
|
44
|
*/
|
45
|
public RemotingChangeAcceptedTaxonToSynonymHandler() {
|
46
|
super(TaxonNavigatorLabels.CHANGE_ACCEPTED_TAXON_TO_SYNONYM_LABEL);
|
47
|
}
|
48
|
/* (non-Javadoc)
|
49
|
* @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent)
|
50
|
*/
|
51
|
@Override
|
52
|
public IStatus allowOperations(ExecutionEvent event) {
|
53
|
TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event);
|
54
|
// check that only a single taxon tree node has been selected
|
55
|
if(selection.size() > 1) {
|
56
|
return new Status(IStatus.ERROR,
|
57
|
"unknown", //$NON-NLS-1$
|
58
|
TaxonNavigatorLabels.SINGLE_TAXON_SELECTION_MESSAGE);
|
59
|
}
|
60
|
|
61
|
// check for no taxon tree node selected
|
62
|
if(selection.size() == 0) {
|
63
|
return new Status(IStatus.ERROR,
|
64
|
"unknown", //$NON-NLS-1$
|
65
|
TaxonNavigatorLabels.NO_TAXON_SELECTION_MESSAGE);
|
66
|
}
|
67
|
|
68
|
// check that selected object is a taxon node
|
69
|
Object obj = selection.iterator().next();
|
70
|
if(obj instanceof ITaxonTreeNode) {
|
71
|
oldTaxonNode = (ITaxonTreeNode)obj;
|
72
|
} else {
|
73
|
return new Status(IStatus.ERROR,
|
74
|
"unknown", //$NON-NLS-1$
|
75
|
TaxonNavigatorLabels.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE);
|
76
|
}
|
77
|
// check that the source taxon node does not have children
|
78
|
if(((TaxonNode)oldTaxonNode).getCountChildren() > 0) {
|
79
|
return new Status(IStatus.ERROR,
|
80
|
"unknown", //$NON-NLS-1$
|
81
|
TaxonNavigatorLabels.SOURCE_TAXON_HAS_CHILDREN_MESSAGE);
|
82
|
|
83
|
}
|
84
|
|
85
|
// check if corresponding name editor is closed
|
86
|
boolean editorClosed = NavigatorHandlerUtils.closeObsoleteEditor(event, (TaxonNode) oldTaxonNode);
|
87
|
if(editorClosed != true) {
|
88
|
return new Status(IStatus.ERROR,
|
89
|
"unknown", //$NON-NLS-1$
|
90
|
TaxonNavigatorLabels.RELATED_EDITOR_NOT_CLOSED_MESSAGE);
|
91
|
}
|
92
|
|
93
|
return Status.OK_STATUS;
|
94
|
}
|
95
|
/* (non-Javadoc)
|
96
|
* @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#doOperations(org.eclipse.core.commands.ExecutionEvent)
|
97
|
*/
|
98
|
@Override
|
99
|
public AbstractOperation prepareOperation(ExecutionEvent event) {
|
100
|
List<UUID> excludeTaxa = new ArrayList<UUID>();
|
101
|
excludeTaxa.add(((TaxonNode)oldTaxonNode).getTaxon().getUuid());
|
102
|
TaxonNode newAcceptedTaxonNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event),
|
103
|
new ConversationHolderMock(),
|
104
|
Messages.RemotingChangeAcceptedTaxonToSynonymHandler_CHOOSE_TAXON,
|
105
|
excludeTaxa,
|
106
|
null,
|
107
|
((TaxonNode)oldTaxonNode).getClassification());
|
108
|
|
109
|
if (newAcceptedTaxonNode == null) {
|
110
|
return null;
|
111
|
}
|
112
|
|
113
|
RemotingChangeAcceptedTaxonToSynonymOperation rcattso =
|
114
|
new RemotingChangeAcceptedTaxonToSynonymOperation(event.getTrigger(),
|
115
|
false,
|
116
|
oldTaxonNode.getUuid(),
|
117
|
newAcceptedTaxonNode.getUuid());
|
118
|
|
119
|
return rcattso;
|
120
|
}
|
121
|
|
122
|
/* (non-Javadoc)
|
123
|
* @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete(org.eclipse.core.commands.ExecutionEvent)
|
124
|
*/
|
125
|
@Override
|
126
|
public void onComplete() {
|
127
|
// TODO Auto-generated method stub
|
128
|
|
129
|
}
|
130
|
|
131
|
|
132
|
|
133
|
|
134
|
}
|