4 package eu
.etaxonomy
.taxeditor
.navigation
.navigator
.e4
.handler
;
6 import java
.util
.HashSet
;
7 import java
.util
.Iterator
;
11 import javax
.inject
.Named
;
13 import org
.eclipse
.core
.commands
.operations
.AbstractOperation
;
14 import org
.eclipse
.core
.runtime
.IStatus
;
15 import org
.eclipse
.core
.runtime
.Status
;
16 import org
.eclipse
.e4
.core
.di
.annotations
.CanExecute
;
17 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
18 import org
.eclipse
.e4
.ui
.model
.application
.ui
.menu
.MHandledMenuItem
;
19 import org
.eclipse
.e4
.ui
.services
.IServiceConstants
;
20 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
21 import org
.eclipse
.jface
.viewers
.TreeSelection
;
22 import org
.eclipse
.swt
.widgets
.Shell
;
24 import eu
.etaxonomy
.cdm
.api
.service
.IClassificationService
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
27 import eu
.etaxonomy
.cdm
.persistence
.dto
.TaxonNodeDto
;
28 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
29 import eu
.etaxonomy
.taxeditor
.navigation
.l10n
.Messages
;
30 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.TaxonNavigatorLabels
;
31 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.operation
.RemotingChangeAcceptedTaxonToSynonymOperation
;
32 import eu
.etaxonomy
.taxeditor
.operation
.e4
.RemotingCdmHandlerE4
;
33 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
34 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.TaxonNodeSelectionDialog
;
42 public class RemotingChangeAcceptedTaxonToSynonymHandlerE4
extends RemotingCdmHandlerE4
{
45 private Set
<TaxonNodeDto
> oldTaxonNodes
= new HashSet();
46 private Classification classification
;
48 public RemotingChangeAcceptedTaxonToSynonymHandlerE4() {
49 super(TaxonNavigatorLabels
.CHANGE_ACCEPTED_TAXON_TO_SYNONYM_LABEL
);
53 public IStatus
allowOperations(IStructuredSelection selection
,
56 MHandledMenuItem menuItem
) {
57 // check that only a single taxon tree node has been selected
58 // if(selection.size() > 1) {
59 // return new Status(IStatus.ERROR,
60 // "unknown", //$NON-NLS-1$
61 // TaxonNavigatorLabels.SINGLE_TAXON_SELECTION_MESSAGE);
64 // check for no taxon tree node selected
65 if(selection
.size() == 0) {
66 return new Status(IStatus
.ERROR
,
67 "unknown", //$NON-NLS-1$
68 TaxonNavigatorLabels
.NO_TAXON_SELECTION_MESSAGE
);
71 // check that selected object is a taxon node
72 Iterator it
= selection
.iterator();
73 Classification nextClassification
;
74 oldTaxonNodes
= new HashSet
<>();
76 Object obj
= it
.next();
77 if(obj
instanceof TaxonNodeDto
) {
78 oldTaxonNodes
.add((TaxonNodeDto
)obj
);
79 nextClassification
= CdmStore
.getService(IClassificationService
.class).find(((TaxonNodeDto
)obj
).getClassificationUUID());
80 if (classification
== null){
81 classification
= nextClassification
;
82 }else if (!classification
.equals(nextClassification
)){
83 return new Status(IStatus
.ERROR
,
84 "unknown", //$NON-NLS-1$
85 TaxonNavigatorLabels
.ACCEPTED_TAXA_NEED_TO_BE_FROM_SAME_CLASSIFICATION
);
88 if (obj
instanceof TaxonNode
&& !((TaxonNode
)obj
).hasTaxon()){
89 return new Status(IStatus
.ERROR
,
90 "Operation not available for Classifications", //$NON-NLS-1$
91 TaxonNavigatorLabels
.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE
);
93 return new Status(IStatus
.ERROR
,
94 "unknown", //$NON-NLS-1$
95 TaxonNavigatorLabels
.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE
);
97 // check that the source taxon node does not have children
98 if(((TaxonNodeDto
)obj
).getTaxonomicChildrenCount() > 0) {
99 return new Status(IStatus
.ERROR
,
100 "unknown", //$NON-NLS-1$
101 TaxonNavigatorLabels
.SOURCE_TAXON_HAS_CHILDREN_MESSAGE
);
105 // check if corresponding name editor is closed
106 EditorUtil
.closeObsoleteEditor((TaxonNodeDto
)obj
, partService
);
108 return Status
.OK_STATUS
;
112 public AbstractOperation
prepareOperation(IStructuredSelection selection
,
115 MHandledMenuItem menuItem
) {
116 Set
<UUID
> excludeTaxa
= new HashSet
<>();
117 for (TaxonNodeDto oldNode
:oldTaxonNodes
){
118 excludeTaxa
.add(oldNode
.getTaxonUuid());
120 TaxonNode newAcceptedTaxonNode
= TaxonNodeSelectionDialog
.select(shell
,
121 // new ConversationHolderMock(),
122 Messages
.RemotingChangeAcceptedTaxonToSynonymHandler_CHOOSE_TAXON
,
125 classification
.getUuid());
127 if (newAcceptedTaxonNode
== null) {
130 Set
<UUID
> nodeUuids
= new HashSet();
131 for (TaxonNodeDto node
: oldTaxonNodes
){
132 nodeUuids
.add(node
.getUuid());
134 RemotingChangeAcceptedTaxonToSynonymOperation rcattso
=
135 new RemotingChangeAcceptedTaxonToSynonymOperation(getTrigger(),
138 newAcceptedTaxonNode
.getUuid(), partService
, activePart
, application
);
144 private boolean canExecute(@Named(IServiceConstants
.ACTIVE_SELECTION
)TreeSelection selection
, MHandledMenuItem menuItem
){
145 boolean canExecute
= !selection
.isEmpty();
146 Object
[] array
= selection
.toArray();
147 for (Object object
: array
) {
148 canExecute
&= (object
instanceof TaxonNodeDto
) && ((TaxonNodeDto
)selection
.getFirstElement()).getTaxonUuid() != null;
150 menuItem
.setVisible(canExecute
);
155 public void onComplete() {
162 protected Object
getTrigger() {