1 package eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.handler
;
3 import java
.util
.ArrayList
;
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
.common
.CdmBase
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
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
.ui
.dialog
.selection
.TaxonNodeSelectionDialog
;
38 public class MoveSynonymToAnotherAcceptedTaxonHandlerE4
implements IPostOperationEnabled
{
39 private static final Logger logger
= Logger
40 .getLogger(MoveSynonymToAnotherAcceptedTaxonHandlerE4
.class);
42 private TaxonNameEditorE4 editor
;
44 private TaxonNode newParentNode
;
46 private EPartService partService
;
49 private EModelService modelService
;
52 private MApplication application
;
55 private MPart activePart
;
58 public void execute(@Named(IServiceConstants
.ACTIVE_PART
)MPart activePart
,
59 @Named(IServiceConstants
.ACTIVE_SELECTION
)IStructuredSelection selection
,
60 @Named(IServiceConstants
.ACTIVE_SHELL
)Shell shell
, EPartService partService
,
63 this.activePart
= activePart
;
64 this.partService
= partService
;
66 editor
= (TaxonNameEditorE4
) activePart
.getObject();
68 TaxonEditorInputE4 input
= editor
.getEditorInput();
70 if (!EditorUtil
.forceUserSaveE4Editor(editor
, shell
)) {
74 if (selection
==null || !(selection
.getFirstElement() instanceof Synonym
)) {
75 MessagingUtils
.warningDialog(Messages
.MoveSynonymToAnotherAcceptedTaxonHandler_NO_SELECTION
, this, Messages
.MoveSynonymToAnotherAcceptedTaxonHandler_NO_SELECTION_MESSAGE
);
76 logger
.error("Selection does not contain a Synonym"); //$NON-NLS-1$
80 Synonym synonym
= (Synonym
) selection
.getFirstElement();
81 Taxon oldParent
= input
.getTaxon();
82 List
<UUID
> excludeTaxa
= new ArrayList
<UUID
>();
83 excludeTaxa
.add(oldParent
.getUuid());
86 newParentNode
= TaxonNodeSelectionDialog
.select(shell
, //editor.getConversationHolder(),
87 Messages
.MoveSynonymToAnotherAcceptedTaxonHandler_SELECT_ACC_TAXON
, excludeTaxa
, input
.getTaxonNode(), input
.getTaxonNode().getClassification());
89 if(newParentNode
!=null){
90 MoveSynonymToAnotherAcceptedTaxonOperationE4 operation
= new MoveSynonymToAnotherAcceptedTaxonOperationE4(Messages
.MoveSynonymToAnotherAcceptedTaxonHandler_CHANGE_ACC_TAXON
, EditorUtil
.getUndoContext(),
91 synonym
.getUuid(), newParentNode
.getTaxon(), this, editor
);
93 AbstractUtility
.executeOperation(operation
, sync
);
98 public boolean canExecute(@Named(IServiceConstants
.ACTIVE_SELECTION
)IStructuredSelection selection
,
99 MHandledMenuItem menuItem
){
100 boolean canExecute
= false;
101 Object selectedElement
= selection
.getFirstElement();
103 NameEditorMenuPropertyTester
.isSynonym(selectedElement
)
104 && NameEditorMenuPropertyTester
.isNotHomotypicSynonymOfAcceptedTaxon(selectedElement
);
106 menuItem
.setVisible(canExecute
);
111 public boolean postOperation(CdmBase objectAffectedByOperation
) {
117 public boolean onComplete() {
118 partService
.hidePart(activePart
);
119 EditorUtil
.openTaxonNodeE4(newParentNode
.getUuid(), modelService
, partService
, application
);