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
;
12 import javax
.inject
.Named
;
14 import org
.eclipse
.e4
.core
.di
.annotations
.CanExecute
;
15 import org
.eclipse
.e4
.core
.di
.annotations
.Execute
;
16 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
17 import org
.eclipse
.e4
.ui
.model
.application
.ui
.menu
.MHandledMenuItem
;
18 import org
.eclipse
.e4
.ui
.services
.IServiceConstants
;
19 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
20 import org
.eclipse
.swt
.widgets
.Shell
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
25 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
26 import eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.TaxonNameEditorE4
;
27 import eu
.etaxonomy
.taxeditor
.editor
.name
.handler
.NameEditorMenuPropertyTester
;
28 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.ChangeConceptRelationshipTypeOperation
;
29 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.ChangeSynonymToMisapplicationOperation
;
30 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
31 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
39 public class ChangeToMisapplicationHandlerE4
{
41 private TaxonNameEditorE4 editor
;
44 public void execute(@Named(IServiceConstants
.ACTIVE_PART
)MPart activePart
,
45 @Named(IServiceConstants
.ACTIVE_SELECTION
)IStructuredSelection selection
,
46 @Named(IServiceConstants
.ACTIVE_SHELL
)Shell shell
,
47 MHandledMenuItem menuItem
) {
49 editor
= (TaxonNameEditorE4
) activePart
.getObject();
51 if (!EditorUtil
.forceUserSaveE4Editor(editor
, shell
)){
54 Object selectedElement
= selection
.getFirstElement();
56 AbstractPostOperation operation
= null;
57 if(selectedElement
instanceof Taxon
){
58 operation
= new ChangeConceptRelationshipTypeOperation(menuItem
.getLocalizedLabel(),
59 editor
.getUndoContext(), editor
.getTaxon(), (Taxon
) selectedElement
, TaxonRelationshipType
.MISAPPLIED_NAME_FOR(), editor
);
61 if(selectedElement
instanceof Synonym
){
62 operation
= new ChangeSynonymToMisapplicationOperation(menuItem
.getLocalizedLabel(),
63 editor
.getUndoContext(), editor
.getTaxon(), (Synonym
) selectedElement
, editor
);
67 AbstractUtility
.executeOperation(operation
);
71 public boolean canExecute(@Named(IServiceConstants
.ACTIVE_SELECTION
)IStructuredSelection selection
,
72 MHandledMenuItem menuItem
){
73 boolean canExecute
= false;
74 Object selectedElement
= selection
.getFirstElement();
76 !NameEditorMenuPropertyTester
.isAccepted(selectedElement
)
77 && !NameEditorMenuPropertyTester
.isMisapplication(selectedElement
);
78 menuItem
.setVisible(canExecute
);