Project

General

Profile

Download (3.03 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.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;
21

    
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;
32

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

    
41
    private TaxonNameEditorE4 editor;
42

    
43
    @Execute
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) {
48

    
49
        editor = (TaxonNameEditorE4) activePart.getObject();
50

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

    
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);
60
        }
61
        if(selectedElement instanceof Synonym){
62
        	operation = new ChangeSynonymToMisapplicationOperation(menuItem.getLocalizedLabel(),
63
        			editor.getUndoContext(), editor.getTaxon(), (Synonym) selectedElement, editor);
64
        }
65

    
66

    
67
        AbstractUtility.executeOperation(operation);
68
	}
69

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

    
81
}
(2-2/12)