3 * Copyright (C) 2018 EDIT
5 * European Distributed Institute of Taxonomy
7 * http://www.e-taxonomy.eu
11 * The contents of this file are subject to the Mozilla Public License Version 1.1
13 * See LICENSE.TXT at the top of this package for the full license terms.
17 package eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.handler
;
19 import javax
.inject
.Named
;
21 import org
.eclipse
.e4
.core
.di
.annotations
.CanExecute
;
22 import org
.eclipse
.e4
.core
.di
.annotations
.Execute
;
23 import org
.eclipse
.e4
.ui
.di
.UISynchronize
;
24 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
25 import org
.eclipse
.e4
.ui
.model
.application
.ui
.menu
.MHandledMenuItem
;
26 import org
.eclipse
.e4
.ui
.services
.IServiceConstants
;
27 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
28 import org
.eclipse
.swt
.widgets
.Shell
;
30 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
31 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
32 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
33 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
34 import eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.TaxonNameEditorE4
;
35 import eu
.etaxonomy
.taxeditor
.editor
.name
.handler
.NameEditorMenuPropertyTester
;
36 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.ChangeConceptRelationshipTypeOperation
;
37 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.ChangeSynonymToConceptOperation
;
38 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
39 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostTaxonOperation
;
47 public class ChangeToInvalidDesignationHandlerE4
{
48 private TaxonNameEditorE4 editor
;
51 public void execute(@Named(IServiceConstants
.ACTIVE_PART
)MPart activePart
,
52 @Named(IServiceConstants
.ACTIVE_SELECTION
)IStructuredSelection selection
,
53 @Named(IServiceConstants
.ACTIVE_SHELL
)Shell shell
,
54 MHandledMenuItem menuItem
,
57 editor
= (TaxonNameEditorE4
) activePart
.getObject();
58 Object selectedElement
= selection
.getFirstElement();
59 AbstractPostTaxonOperation operation
= null;
61 if(selectedElement
instanceof Taxon
){
62 operation
= new ChangeConceptRelationshipTypeOperation(menuItem
.getLocalizedLabel(),
63 editor
.getUndoContext(), editor
.getTaxon(), (Taxon
) selectedElement
, TaxonRelationshipType
.INVALID_DESIGNATION_FOR(), editor
);
66 if(selectedElement
instanceof Synonym
){
67 operation
= new ChangeSynonymToConceptOperation(menuItem
.getLocalizedLabel(),
68 editor
.getUndoContext(), editor
.getTaxon(), (Synonym
) selectedElement
, TaxonRelationshipType
.INVALID_DESIGNATION_FOR(), editor
);
71 if (!EditorUtil
.forceUserSaveE4Editor(editor
, shell
)){
75 AbstractUtility
.executeOperation(operation
, sync
);
80 public boolean canExecute(@Named(IServiceConstants
.ACTIVE_SELECTION
)IStructuredSelection selection
,
81 MHandledMenuItem menuItem
){
83 boolean canExecute
= false;
84 if(selection
.size()==1){
85 Object selectedElement
= selection
.getFirstElement();
86 canExecute
= NameEditorMenuPropertyTester
.isNotInvalidDesignation(selectedElement
);
88 menuItem
.setVisible(canExecute
);