Project

General

Profile

Download (2.44 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
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.
8
*/
9

    
10
package eu.etaxonomy.taxeditor.editor.name.e4.handler;
11

    
12
import javax.inject.Named;
13

    
14
import org.eclipse.e4.core.di.annotations.Execute;
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.jface.viewers.IStructuredSelection;
19
import org.eclipse.swt.widgets.Shell;
20

    
21
import eu.etaxonomy.cdm.model.taxon.Synonym;
22
import eu.etaxonomy.cdm.model.taxon.Taxon;
23
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
24
import eu.etaxonomy.taxeditor.editor.EditorUtil;
25
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
26
import eu.etaxonomy.taxeditor.editor.name.operation.ChangeConceptRelationshipTypeOperation;
27
import eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToMisapplicationOperation;
28
import eu.etaxonomy.taxeditor.model.AbstractUtility;
29
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
30

    
31
/**
32
 *
33
 * @author pplitzner
34
 * @since Aug 28, 2017
35
 *
36
 */
37
public class ChangeToMisapplicationHandlerE4 {
38

    
39
    private TaxonNameEditorE4 editor;
40

    
41
    @Execute
42
    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
43
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
44
            @Named(IServiceConstants.ACTIVE_SHELL)Shell shell,
45
            MHandledMenuItem menuItem) {
46

    
47
        editor = (TaxonNameEditorE4) activePart.getObject();
48

    
49
		if (!EditorUtil.forceUserSaveE4Editor(editor, shell)){
50
            return ;
51
        }
52
		Object selectedElement = selection.getFirstElement();
53

    
54
		AbstractPostOperation operation = null;
55
		if(selectedElement instanceof Taxon){
56
        	operation = new ChangeConceptRelationshipTypeOperation(menuItem.getLocalizedLabel(),
57
        							editor.getUndoContext(), editor.getTaxon(), (Taxon) selectedElement, TaxonRelationshipType.MISAPPLIED_NAME_FOR(), editor);
58
        }
59
        if(selectedElement instanceof Synonym){
60
        	operation = new ChangeSynonymToMisapplicationOperation(menuItem.getLocalizedLabel(),
61
        			editor.getUndoContext(), editor.getTaxon(), (Synonym) selectedElement, editor);
62
        }
63

    
64

    
65
        AbstractUtility.executeOperation(operation);
66
	}
67
}
(2-2/12)