4 package eu
.etaxonomy
.taxeditor
.navigation
.navigator
.e4
.handler
;
6 import java
.util
.ArrayList
;
10 import javax
.inject
.Named
;
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
.e4
.core
.di
.annotations
.CanExecute
;
16 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
17 import org
.eclipse
.e4
.ui
.model
.application
.ui
.menu
.MHandledMenuItem
;
18 import org
.eclipse
.e4
.ui
.services
.IServiceConstants
;
19 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
20 import org
.eclipse
.jface
.viewers
.TreeSelection
;
21 import org
.eclipse
.swt
.widgets
.Shell
;
23 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolderMock
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
25 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
26 import eu
.etaxonomy
.taxeditor
.navigation
.l10n
.Messages
;
27 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.TaxonNavigatorLabels
;
28 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.operation
.RemotingChangeAcceptedTaxonToSynonymOperation
;
29 import eu
.etaxonomy
.taxeditor
.operation
.e4
.RemotingCdmHandlerE4
;
30 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.TaxonNodeSelectionDialog
;
38 public class RemotingChangeAcceptedTaxonToSynonymHandlerE4
extends RemotingCdmHandlerE4
{
41 private TaxonNode oldTaxonNode
;
43 public RemotingChangeAcceptedTaxonToSynonymHandlerE4() {
44 super(TaxonNavigatorLabels
.CHANGE_ACCEPTED_TAXON_TO_SYNONYM_LABEL
);
48 public IStatus
allowOperations(IStructuredSelection selection
,
51 MHandledMenuItem menuItem
) {
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", //$NON-NLS-1$
56 TaxonNavigatorLabels
.SINGLE_TAXON_SELECTION_MESSAGE
);
59 // check for no taxon tree node selected
60 if(selection
.size() == 0) {
61 return new Status(IStatus
.ERROR
,
62 "unknown", //$NON-NLS-1$
63 TaxonNavigatorLabels
.NO_TAXON_SELECTION_MESSAGE
);
66 // check that selected object is a taxon node
67 Object obj
= selection
.iterator().next();
68 if(obj
instanceof TaxonNode
&& ((TaxonNode
)obj
).hasTaxon()) {
69 oldTaxonNode
= (TaxonNode
)obj
;
71 if (obj
instanceof TaxonNode
&& !((TaxonNode
)obj
).hasTaxon()){
72 return new Status(IStatus
.ERROR
,
73 "Operation not available for Classifications", //$NON-NLS-1$
74 TaxonNavigatorLabels
.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE
);
76 return new Status(IStatus
.ERROR
,
77 "unknown", //$NON-NLS-1$
78 TaxonNavigatorLabels
.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE
);
80 // check that the source taxon node does not have children
81 if(oldTaxonNode
.getCountChildren() > 0) {
82 return new Status(IStatus
.ERROR
,
83 "unknown", //$NON-NLS-1$
84 TaxonNavigatorLabels
.SOURCE_TAXON_HAS_CHILDREN_MESSAGE
);
88 // check if corresponding name editor is closed
89 EditorUtil
.closeObsoleteEditor(oldTaxonNode
, partService
);
91 return Status
.OK_STATUS
;
95 public AbstractOperation
prepareOperation(IStructuredSelection selection
,
98 MHandledMenuItem menuItem
) {
99 List
<UUID
> excludeTaxa
= new ArrayList
<UUID
>();
100 excludeTaxa
.add(oldTaxonNode
.getTaxon().getUuid());
101 TaxonNode newAcceptedTaxonNode
= TaxonNodeSelectionDialog
.select(shell
,
102 new ConversationHolderMock(),
103 Messages
.RemotingChangeAcceptedTaxonToSynonymHandler_CHOOSE_TAXON
,
106 oldTaxonNode
.getClassification());
108 if (newAcceptedTaxonNode
== null) {
112 RemotingChangeAcceptedTaxonToSynonymOperation rcattso
=
113 new RemotingChangeAcceptedTaxonToSynonymOperation(getTrigger(),
115 oldTaxonNode
.getUuid(),
116 newAcceptedTaxonNode
.getUuid());
122 private boolean canExecute(@Named(IServiceConstants
.ACTIVE_SELECTION
)TreeSelection selection
, MHandledMenuItem menuItem
){
123 boolean canExecute
= false;
124 canExecute
= selection
.getFirstElement() instanceof TaxonNode
125 && ((TaxonNode
) selection
.getFirstElement()).getTaxon()!=null;
126 menuItem
.setVisible(canExecute
);
131 public void onComplete() {
138 protected Object
getTrigger() {