Project

General

Profile

Download (2.24 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

    
21
import eu.etaxonomy.cdm.model.taxon.Taxon;
22
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
23
import eu.etaxonomy.taxeditor.editor.name.handler.NameEditorMenuPropertyTester;
24
import eu.etaxonomy.taxeditor.editor.name.operation.ChangeConceptToSynonymOperation;
25
import eu.etaxonomy.taxeditor.model.AbstractUtility;
26
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
27

    
28
/**
29
 *
30
 * @author pplitzner
31
 * @since Aug 28, 2017
32
 *
33
 */
34
public class ChangeToSynonymHandlerE4 {
35

    
36
    @Execute
37
    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
38
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
39
            MHandledMenuItem menuItem) {
40

    
41
        TaxonNameEditorE4 editor = (TaxonNameEditorE4) activePart.getObject();
42

    
43

    
44
		Taxon concept  = (Taxon) selection.getFirstElement();
45

    
46
		AbstractPostOperation operation;
47
		operation = new ChangeConceptToSynonymOperation(menuItem.getLocalizedLabel(),
48
        		editor.getUndoContext(), editor.getTaxon(), concept, null, editor);
49

    
50
        AbstractUtility.executeOperation(operation);
51

    
52
	}
53

    
54
    @CanExecute
55
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
56
            MHandledMenuItem menuItem){
57
        boolean canExecute = false;
58
        Object selectedElement = selection.getFirstElement();
59
        canExecute =
60
                !NameEditorMenuPropertyTester.isAccepted(selectedElement)
61
                && !NameEditorMenuPropertyTester.isSynonym(selectedElement);
62
        menuItem.setVisible(canExecute);
63
        return canExecute;
64
    }
65

    
66
}
(3-3/12)