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
.TreeSelection
;
20 import org
.eclipse
.swt
.widgets
.Shell
;
22 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolderMock
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
24 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
25 import eu
.etaxonomy
.taxeditor
.navigation
.l10n
.Messages
;
26 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.TaxonNavigatorLabels
;
27 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.operation
.RemotingChangeAcceptedTaxonToSynonymOperation
;
28 import eu
.etaxonomy
.taxeditor
.operation
.e4
.RemotingCdmHandlerE4
;
29 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.TaxonNodeSelectionDialog
;
37 public class RemotingChangeAcceptedTaxonToSynonymHandlerE4
extends RemotingCdmHandlerE4
{
40 private TaxonNode oldTaxonNode
;
42 public RemotingChangeAcceptedTaxonToSynonymHandlerE4() {
43 super(TaxonNavigatorLabels
.CHANGE_ACCEPTED_TAXON_TO_SYNONYM_LABEL
);
47 public IStatus
allowOperations(TreeSelection selection
,
50 MHandledMenuItem menuItem
) {
51 // check that only a single taxon tree node has been selected
52 if(selection
.size() > 1) {
53 return new Status(IStatus
.ERROR
,
54 "unknown", //$NON-NLS-1$
55 TaxonNavigatorLabels
.SINGLE_TAXON_SELECTION_MESSAGE
);
58 // check for no taxon tree node selected
59 if(selection
.size() == 0) {
60 return new Status(IStatus
.ERROR
,
61 "unknown", //$NON-NLS-1$
62 TaxonNavigatorLabels
.NO_TAXON_SELECTION_MESSAGE
);
65 // check that selected object is a taxon node
66 Object obj
= selection
.iterator().next();
67 if(obj
instanceof TaxonNode
&& ((TaxonNode
)obj
).hasTaxon()) {
68 oldTaxonNode
= (TaxonNode
)obj
;
70 if (obj
instanceof TaxonNode
&& !((TaxonNode
)obj
).hasTaxon()){
71 return new Status(IStatus
.ERROR
,
72 "Operation not available for Classifications", //$NON-NLS-1$
73 TaxonNavigatorLabels
.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE
);
75 return new Status(IStatus
.ERROR
,
76 "unknown", //$NON-NLS-1$
77 TaxonNavigatorLabels
.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE
);
79 // check that the source taxon node does not have children
80 if(oldTaxonNode
.getCountChildren() > 0) {
81 return new Status(IStatus
.ERROR
,
82 "unknown", //$NON-NLS-1$
83 TaxonNavigatorLabels
.SOURCE_TAXON_HAS_CHILDREN_MESSAGE
);
87 // check if corresponding name editor is closed
88 EditorUtil
.closeObsoleteEditor(oldTaxonNode
, partService
);
90 return Status
.OK_STATUS
;
94 public AbstractOperation
prepareOperation(TreeSelection selection
,
97 MHandledMenuItem menuItem
) {
98 List
<UUID
> excludeTaxa
= new ArrayList
<UUID
>();
99 excludeTaxa
.add(oldTaxonNode
.getTaxon().getUuid());
100 TaxonNode newAcceptedTaxonNode
= TaxonNodeSelectionDialog
.select(shell
,
101 new ConversationHolderMock(),
102 Messages
.RemotingChangeAcceptedTaxonToSynonymHandler_CHOOSE_TAXON
,
105 oldTaxonNode
.getClassification());
107 if (newAcceptedTaxonNode
== null) {
111 RemotingChangeAcceptedTaxonToSynonymOperation rcattso
=
112 new RemotingChangeAcceptedTaxonToSynonymOperation(getTrigger(),
114 oldTaxonNode
.getUuid(),
115 newAcceptedTaxonNode
.getUuid());
121 private boolean canExecute(@Named(IServiceConstants
.ACTIVE_SELECTION
)TreeSelection selection
, MHandledMenuItem menuItem
){
122 boolean canExecute
= false;
123 menuItem
.setVisible(canExecute
);
124 canExecute
= selection
.getFirstElement() instanceof TaxonNode
;
125 System
.out
.println(canExecute
);
130 public void onComplete() {
137 protected Object
getTrigger() {