2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.handler
;
14 import javax
.inject
.Named
;
16 import org
.apache
.log4j
.Logger
;
17 import org
.eclipse
.e4
.core
.di
.annotations
.CanExecute
;
18 import org
.eclipse
.e4
.core
.di
.annotations
.Execute
;
19 import org
.eclipse
.e4
.ui
.di
.UISynchronize
;
20 import org
.eclipse
.e4
.ui
.model
.application
.MApplication
;
21 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
22 import org
.eclipse
.e4
.ui
.model
.application
.ui
.menu
.MHandledMenuItem
;
23 import org
.eclipse
.e4
.ui
.services
.IServiceConstants
;
24 import org
.eclipse
.e4
.ui
.workbench
.modeling
.EModelService
;
25 import org
.eclipse
.e4
.ui
.workbench
.modeling
.EPartService
;
26 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
27 import org
.eclipse
.swt
.widgets
.Shell
;
29 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
30 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
31 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
32 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
33 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
34 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
35 import eu
.etaxonomy
.taxeditor
.editor
.e4
.TaxonEditorInputE4
;
36 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
37 import eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.TaxonNameEditorE4
;
38 import eu
.etaxonomy
.taxeditor
.editor
.name
.handler
.NameEditorMenuPropertyTester
;
39 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.ChangeSynonymToAcceptedTaxonOperation
;
40 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
41 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
42 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.TaxonNodeSelectionDialog
;
48 public class ChangeSynonymToAcceptedTaxonHandlerE4
implements IPostOperationEnabled
{
49 private static final Logger logger
= Logger
50 .getLogger(ChangeSynonymToAcceptedTaxonHandlerE4
.class);
52 private TaxonNameEditorE4 editor
;
53 private EPartService partService
;
54 private MApplication application
;
55 private EModelService modelService
;
58 public void execute(@Named(IServiceConstants
.ACTIVE_PART
) MPart activePart
,
59 @Named(IServiceConstants
.ACTIVE_SELECTION
) IStructuredSelection selection
, EPartService partService
,
60 EModelService modelService
, MApplication application
, @Named(IServiceConstants
.ACTIVE_SHELL
) Shell shell
,
63 this.modelService
= modelService
;
64 this.application
= application
;
65 this.partService
= partService
;
67 editor
= (TaxonNameEditorE4
) activePart
.getObject();
69 TaxonEditorInputE4 input
= editor
.getEditorInput();
71 // Get synonym from selection
72 if (!(selection
.getFirstElement() instanceof Synonym
)) {
73 logger
.error("Selection does not contain a Synonym"); //$NON-NLS-1$
77 Synonym synonym
= (Synonym
) selection
.getFirstElement();
79 // Force user to save taxon - not really necessary though, is it?
80 if (!EditorUtil
.forceUserSaveE4Editor(editor
, shell
)) {
85 Taxon taxon
= input
.getTaxon();
87 TaxonNode newParentNode
= TaxonNodeSelectionDialog
.select(shell
,// editor.getConversationHolder(),
88 Messages
.ChangeSynonymToAcceptedTaxonHandler_SELECT_PARENT
, null, null, input
.getTaxonNode().getClassification().getUuid(), true);
91 if(newParentNode
!= null){
93 // TODO get synonyms from homotypical group and add them as homotypic synonyms to new accepted taxon
94 // apply confirmation dialog
95 HomotypicalGroup group
= synonym
.getHomotypicGroup();
96 Set
<TaxonName
> namesInGroup
= group
.getTypifiedNames();
97 // FIXME with this implementation we can not create a taxonNode that is a direct child of the classification node
98 ChangeSynonymToAcceptedTaxonOperation operation
= new ChangeSynonymToAcceptedTaxonOperation(Messages
.ChangeSynonymToAcceptedTaxonHandler_CHANGE_SYN_TO_ACC_TAXON
, EditorUtil
.getUndoContext(),
99 taxon
, newParentNode
, synonym
, namesInGroup
, this, editor
, editor
.getEditorInput()); //$NON-NLS-1$
101 AbstractUtility
.executeOperation(operation
, sync
);
106 public boolean postOperation(Object objectAffectedByOperation
) {
108 // Redraw existing editor
109 ((IPostOperationEnabled
) editor
).postOperation(null);
111 editor
.save(AbstractUtility
.getMonitor());
113 if (objectAffectedByOperation
instanceof TaxonNode
) {
115 // Open new unsaved editor with existing taxon's parent as temporary parent
116 TaxonNode newNode
= (TaxonNode
) objectAffectedByOperation
;
118 EditorUtil
.openTaxonNodeE4(newNode
.getUuid(), modelService
, partService
, application
);
124 public boolean onComplete() {
129 public boolean canExecute(@Named(IServiceConstants
.ACTIVE_SELECTION
)IStructuredSelection selection
,
130 MHandledMenuItem menuItem
){
131 boolean canExecute
= false;
132 if(selection
.size()==1){
133 Object selectedElement
= selection
.getFirstElement();
135 NameEditorMenuPropertyTester
.isNotHomotypicSynonymOfAcceptedTaxon(selectedElement
)
136 && !NameEditorMenuPropertyTester
.isAccepted(selectedElement
)
137 && NameEditorMenuPropertyTester
.isNotMisapplication(selectedElement
)
138 && NameEditorMenuPropertyTester
.isNotProparteSynonym(selectedElement
);
139 menuItem
.setVisible(canExecute
);