4 package eu
.etaxonomy
.taxeditor
.navigation
.navigator
.e4
.handler
;
6 import java
.util
.ArrayList
;
10 import org
.eclipse
.core
.commands
.operations
.AbstractOperation
;
11 import org
.eclipse
.core
.runtime
.IStatus
;
12 import org
.eclipse
.core
.runtime
.Status
;
13 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
14 import org
.eclipse
.e4
.ui
.model
.application
.ui
.menu
.MHandledMenuItem
;
15 import org
.eclipse
.jface
.viewers
.TreeSelection
;
16 import org
.eclipse
.swt
.widgets
.Shell
;
18 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolderMock
;
19 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
20 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
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
.e4
.RemotingCdmHandlerE4
;
25 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.TaxonNodeSelectionDialog
;
33 public class RemotingChangeAcceptedTaxonToSynonymHandlerE4
extends RemotingCdmHandlerE4
{
36 private TaxonNode oldTaxonNode
;
38 public RemotingChangeAcceptedTaxonToSynonymHandlerE4() {
39 super(TaxonNavigatorLabels
.CHANGE_ACCEPTED_TAXON_TO_SYNONYM_LABEL
);
43 public IStatus
allowOperations(TreeSelection selection
,
46 MHandledMenuItem menuItem
) {
47 // check that only a single taxon tree node has been selected
48 if(selection
.size() > 1) {
49 return new Status(IStatus
.ERROR
,
50 "unknown", //$NON-NLS-1$
51 TaxonNavigatorLabels
.SINGLE_TAXON_SELECTION_MESSAGE
);
54 // check for no taxon tree node selected
55 if(selection
.size() == 0) {
56 return new Status(IStatus
.ERROR
,
57 "unknown", //$NON-NLS-1$
58 TaxonNavigatorLabels
.NO_TAXON_SELECTION_MESSAGE
);
61 // check that selected object is a taxon node
62 Object obj
= selection
.iterator().next();
63 if(obj
instanceof TaxonNode
&& ((TaxonNode
)obj
).hasTaxon()) {
64 oldTaxonNode
= (TaxonNode
)obj
;
66 if (obj
instanceof TaxonNode
&& !((TaxonNode
)obj
).hasTaxon()){
67 return new Status(IStatus
.ERROR
,
68 "Operation not available for Classifications", //$NON-NLS-1$
69 TaxonNavigatorLabels
.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE
);
71 return new Status(IStatus
.ERROR
,
72 "unknown", //$NON-NLS-1$
73 TaxonNavigatorLabels
.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE
);
75 // check that the source taxon node does not have children
76 if(oldTaxonNode
.getCountChildren() > 0) {
77 return new Status(IStatus
.ERROR
,
78 "unknown", //$NON-NLS-1$
79 TaxonNavigatorLabels
.SOURCE_TAXON_HAS_CHILDREN_MESSAGE
);
83 // check if corresponding name editor is closed
84 EditorUtil
.closeObsoleteEditor(oldTaxonNode
, partService
);
86 return Status
.OK_STATUS
;
90 public AbstractOperation
prepareOperation(TreeSelection selection
,
93 MHandledMenuItem menuItem
) {
94 List
<UUID
> excludeTaxa
= new ArrayList
<UUID
>();
95 excludeTaxa
.add(oldTaxonNode
.getTaxon().getUuid());
96 TaxonNode newAcceptedTaxonNode
= TaxonNodeSelectionDialog
.select(shell
,
97 new ConversationHolderMock(),
98 Messages
.RemotingChangeAcceptedTaxonToSynonymHandler_CHOOSE_TAXON
,
101 oldTaxonNode
.getClassification());
103 if (newAcceptedTaxonNode
== null) {
107 RemotingChangeAcceptedTaxonToSynonymOperation rcattso
=
108 new RemotingChangeAcceptedTaxonToSynonymOperation(getTrigger(),
110 oldTaxonNode
.getUuid(),
111 newAcceptedTaxonNode
.getUuid());
117 public void onComplete() {
124 protected Object
getTrigger() {