1 package eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.handler
;
3 import java
.util
.HashSet
;
7 import javax
.inject
.Inject
;
8 import javax
.inject
.Named
;
10 import org
.apache
.logging
.log4j
.LogManager
;import org
.apache
.logging
.log4j
.Logger
;
11 import org
.eclipse
.e4
.core
.di
.annotations
.CanExecute
;
12 import org
.eclipse
.e4
.core
.di
.annotations
.Execute
;
13 import org
.eclipse
.e4
.ui
.di
.UISynchronize
;
14 import org
.eclipse
.e4
.ui
.model
.application
.MApplication
;
15 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
16 import org
.eclipse
.e4
.ui
.model
.application
.ui
.menu
.MHandledMenuItem
;
17 import org
.eclipse
.e4
.ui
.services
.IServiceConstants
;
18 import org
.eclipse
.e4
.ui
.workbench
.modeling
.EModelService
;
19 import org
.eclipse
.e4
.ui
.workbench
.modeling
.EPartService
;
20 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
21 import org
.eclipse
.swt
.widgets
.Shell
;
23 import eu
.etaxonomy
.cdm
.model
.metadata
.SecReferenceHandlingEnum
;
24 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
27 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
28 import eu
.etaxonomy
.taxeditor
.editor
.e4
.TaxonEditorInputE4
;
29 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
30 import eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.TaxonNameEditorE4
;
31 import eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.operation
.MoveSynonymToAnotherAcceptedTaxonOperationE4
;
32 import eu
.etaxonomy
.taxeditor
.editor
.name
.handler
.NameEditorMenuPropertyTester
;
33 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
34 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
35 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
36 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
37 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.ReferenceSelectionDialog
;
38 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.TaxonNodeSelectionDialog
;
40 public class MoveSynonymToAnotherAcceptedTaxonHandlerE4
implements IPostOperationEnabled
{
42 private static final Logger logger
= Logger
.getLogger(MoveSynonymToAnotherAcceptedTaxonHandlerE4
.class);
44 private TaxonNameEditorE4 editor
;
46 private TaxonNode newParentNode
;
48 private EPartService partService
;
51 private EModelService modelService
;
54 private MApplication application
;
57 private MPart activePart
;
60 public void execute(@Named(IServiceConstants
.ACTIVE_PART
)MPart activePart
,
61 @Named(IServiceConstants
.ACTIVE_SELECTION
)IStructuredSelection selection
,
62 @Named(IServiceConstants
.ACTIVE_SHELL
)Shell shell
, EPartService partService
,
65 this.activePart
= activePart
;
66 this.partService
= partService
;
68 editor
= (TaxonNameEditorE4
) activePart
.getObject();
70 TaxonEditorInputE4 input
= editor
.getEditorInput();
72 if (!EditorUtil
.forceUserSaveE4Editor(editor
, shell
)) {
76 if (selection
==null || !(selection
.getFirstElement() instanceof Synonym
)) {
77 MessagingUtils
.warningDialog(Messages
.MoveSynonymToAnotherAcceptedTaxonHandler_NO_SELECTION
, this, Messages
.MoveSynonymToAnotherAcceptedTaxonHandler_NO_SELECTION_MESSAGE
);
78 logger
.error("Selection does not contain a Synonym"); //$NON-NLS-1$
82 Synonym synonym
= (Synonym
) selection
.getFirstElement();
83 TaxonNode oldParent
= input
.getTaxonNode();
84 Set
<UUID
> excludeTaxa
= new HashSet
<>();
85 excludeTaxa
.add(oldParent
.getUuid());
88 newParentNode
= TaxonNodeSelectionDialog
.select(shell
, Messages
.MoveSynonymToAnotherAcceptedTaxonHandler_SELECT_ACC_TAXON
, excludeTaxa
, input
.getTaxonNode(), input
.getTaxonNode().getClassification().getUuid());
89 if (newParentNode
== null){
92 SecReferenceHandlingEnum secHandling
= PreferencesUtil
.getSecReferenceHandlingPreference();
93 UUID newSecUuid
= null;
95 Reference synSecRef
= synonym
.getSec();
97 Reference parentSecRef
= newParentNode
.getTaxon() != null? newParentNode
.getTaxon().getSec():null;
98 if ((synSecRef
!= parentSecRef
&& secHandling
.equals(SecReferenceHandlingEnum
.KeepOrWarn
) )|| secHandling
.equals(SecReferenceHandlingEnum
.KeepOrSelect
)){
100 if ((parentSecRef
!= synSecRef
&& secHandling
.equals(SecReferenceHandlingEnum
.KeepOrWarn
) )|| secHandling
.equals(SecReferenceHandlingEnum
.KeepOrSelect
)){
101 int result
= MessagingUtils
.confirmDialog(Messages
.ChangeSynonymToAcceptedHandler_Select_Sec_Reference_Handling_title
, Messages
.MoveSynonymToAcceptedHandler_Select_Sec_Reference_Handling_message
,
102 new String
[]{Messages
.ChangeSynonymToAcceptedHandler_Select_Sec_Reference_Keep
, Messages
.ChangeSynonymToAcceptedHandler_Select_Sec_Reference_Parent
, Messages
.ChangeSynonymToAcceptedHandler_Select_Sec_Reference_Select
});
104 Reference sec
= ReferenceSelectionDialog
.select(shell
, null);
105 newSecUuid
= sec
!= null? sec
.getUuid(): null;
106 }else if (result
== 1){
107 newSecUuid
= parentSecRef
!= null? parentSecRef
.getUuid(): null;
108 }else if (result
== 0){
109 newSecUuid
= synSecRef
!= null? synSecRef
.getUuid(): null;
117 boolean homotypicGroupPublish
= true;
118 // for (synonym.getName().getHomotypicalGroup().getTypifiedNames())
119 if (synonym
.isPublish() != newParentNode
.getTaxon().isPublish()){
120 MessagingUtils
.warningDialog("Publish flag", this,Messages
.ChangeSynonymToAcceptedHandler_Different_Publish_Flag
);
122 if(newParentNode
!=null){
123 MoveSynonymToAnotherAcceptedTaxonOperationE4 operation
= new MoveSynonymToAnotherAcceptedTaxonOperationE4(Messages
.MoveSynonymToAnotherAcceptedTaxonHandler_CHANGE_ACC_TAXON
, EditorUtil
.getUndoContext(),
124 synonym
.getUuid(), newParentNode
.getTaxon(),newSecUuid
, this, editor
);
126 AbstractUtility
.executeOperation(operation
, sync
);
131 public boolean canExecute(@Named(IServiceConstants
.ACTIVE_SELECTION
)IStructuredSelection selection
,
132 MHandledMenuItem menuItem
){
133 boolean canExecute
= false;
134 if(selection
.size()==1){
135 Object selectedElement
= selection
.getFirstElement();
137 NameEditorMenuPropertyTester
.isSynonym(selectedElement
)
138 && NameEditorMenuPropertyTester
.isNotHomotypicSynonymOfAcceptedTaxon(selectedElement
);
140 menuItem
.setVisible(canExecute
);
145 public boolean postOperation(Object objectAffectedByOperation
) {
151 public boolean onComplete() {
152 partService
.hidePart(activePart
);
153 EditorUtil
.openTaxonNodeE4(newParentNode
.getUuid(), modelService
, partService
, application
);