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
.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
.taxon
.Synonym
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
25 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
26 import eu
.etaxonomy
.taxeditor
.editor
.e4
.TaxonEditorInputE4
;
27 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
28 import eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.TaxonNameEditorE4
;
29 import eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.operation
.MoveSynonymToAnotherAcceptedTaxonOperationE4
;
30 import eu
.etaxonomy
.taxeditor
.editor
.name
.handler
.NameEditorMenuPropertyTester
;
31 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
32 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
33 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
34 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.TaxonNodeSelectionDialog
;
36 public class MoveSynonymToAnotherAcceptedTaxonHandlerE4
implements IPostOperationEnabled
{
37 private static final Logger logger
= Logger
38 .getLogger(MoveSynonymToAnotherAcceptedTaxonHandlerE4
.class);
40 private TaxonNameEditorE4 editor
;
42 private TaxonNode newParentNode
;
44 private EPartService partService
;
47 private EModelService modelService
;
50 private MApplication application
;
53 private MPart activePart
;
56 public void execute(@Named(IServiceConstants
.ACTIVE_PART
)MPart activePart
,
57 @Named(IServiceConstants
.ACTIVE_SELECTION
)IStructuredSelection selection
,
58 @Named(IServiceConstants
.ACTIVE_SHELL
)Shell shell
, EPartService partService
,
61 this.activePart
= activePart
;
62 this.partService
= partService
;
64 editor
= (TaxonNameEditorE4
) activePart
.getObject();
66 TaxonEditorInputE4 input
= editor
.getEditorInput();
68 if (!EditorUtil
.forceUserSaveE4Editor(editor
, shell
)) {
72 if (selection
==null || !(selection
.getFirstElement() instanceof Synonym
)) {
73 MessagingUtils
.warningDialog(Messages
.MoveSynonymToAnotherAcceptedTaxonHandler_NO_SELECTION
, this, Messages
.MoveSynonymToAnotherAcceptedTaxonHandler_NO_SELECTION_MESSAGE
);
74 logger
.error("Selection does not contain a Synonym"); //$NON-NLS-1$
78 Synonym synonym
= (Synonym
) selection
.getFirstElement();
79 TaxonNode oldParent
= input
.getTaxonNode();
80 Set
<UUID
> excludeTaxa
= new HashSet
<>();
81 excludeTaxa
.add(oldParent
.getUuid());
84 newParentNode
= TaxonNodeSelectionDialog
.select(shell
, //editor.getConversationHolder(),
85 Messages
.MoveSynonymToAnotherAcceptedTaxonHandler_SELECT_ACC_TAXON
, excludeTaxa
, input
.getTaxonNode(), input
.getTaxonNode().getClassification().getUuid());
87 if (synonym
.isPublish() != newParentNode
.getTaxon().isPublish()){
88 MessagingUtils
.informationDialog("Publish flag", Messages
.ChangeSynonymToAcceptedHandler_Different_Publish_Flag
);
90 if(newParentNode
!=null){
91 MoveSynonymToAnotherAcceptedTaxonOperationE4 operation
= new MoveSynonymToAnotherAcceptedTaxonOperationE4(Messages
.MoveSynonymToAnotherAcceptedTaxonHandler_CHANGE_ACC_TAXON
, EditorUtil
.getUndoContext(),
92 synonym
.getUuid(), newParentNode
.getTaxon(), this, editor
);
94 AbstractUtility
.executeOperation(operation
, sync
);
99 public boolean canExecute(@Named(IServiceConstants
.ACTIVE_SELECTION
)IStructuredSelection selection
,
100 MHandledMenuItem menuItem
){
101 boolean canExecute
= false;
102 if(selection
.size()==1){
103 Object selectedElement
= selection
.getFirstElement();
105 NameEditorMenuPropertyTester
.isSynonym(selectedElement
)
106 && NameEditorMenuPropertyTester
.isNotHomotypicSynonymOfAcceptedTaxon(selectedElement
);
108 menuItem
.setVisible(canExecute
);
113 public boolean postOperation(Object objectAffectedByOperation
) {
119 public boolean onComplete() {
120 partService
.hidePart(activePart
);
121 EditorUtil
.openTaxonNodeE4(newParentNode
.getUuid(), modelService
, partService
, application
);