Project

General

Profile

Download (3.11 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.CanExecute;
15
import org.eclipse.e4.core.di.annotations.Execute;
16
import org.eclipse.e4.ui.di.UISynchronize;
17
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
18
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
19
import org.eclipse.e4.ui.services.IServiceConstants;
20
import org.eclipse.jface.viewers.IStructuredSelection;
21
import org.eclipse.swt.widgets.Shell;
22

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

    
34
/**
35
 *
36
 * @author pplitzner
37
 * @since Aug 28, 2017
38
 *
39
 */
40
public class ChangeToMisapplicationHandlerE4 {
41

    
42
    private TaxonNameEditorE4 editor;
43

    
44
    @Execute
45
    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
46
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
47
            @Named(IServiceConstants.ACTIVE_SHELL)Shell shell,
48
            MHandledMenuItem menuItem,
49
            UISynchronize sync) {
50

    
51
        editor = (TaxonNameEditorE4) activePart.getObject();
52

    
53
		if (!EditorUtil.forceUserSaveE4Editor(editor, shell)){
54
            return ;
55
        }
56
		Object selectedElement = selection.getFirstElement();
57

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

    
68

    
69
        AbstractUtility.executeOperation(operation, sync);
70
	}
71

    
72
    @CanExecute
73
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
74
            MHandledMenuItem menuItem){
75
        boolean canExecute = false;
76
        Object selectedElement = selection.getFirstElement();
77
        canExecute =
78
                !NameEditorMenuPropertyTester.isAccepted(selectedElement)
79
                && !NameEditorMenuPropertyTester.isMisapplication(selectedElement);
80
        return canExecute;
81
    }
82

    
83
}
(2-2/14)