Project

General

Profile

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

    
22
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
23
import eu.etaxonomy.cdm.model.name.TaxonName;
24
import eu.etaxonomy.cdm.model.taxon.Synonym;
25
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
26
import eu.etaxonomy.taxeditor.editor.name.handler.NameEditorMenuPropertyTester;
27
import eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation;
28
import eu.etaxonomy.taxeditor.model.AbstractUtility;
29
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
30
import eu.etaxonomy.taxeditor.parser.ParseHandler;
31

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

    
40
    @Execute
41
    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
42
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
43
            MHandledMenuItem menuItem,
44
            UISynchronize sync) {
45

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

    
48
		Object selecteObject = selection.getFirstElement();
49

    
50
		if(! (selecteObject instanceof Synonym)){
51
			return ;
52
		}
53

    
54
		Synonym synonym = (Synonym) selecteObject;
55

    
56
		HomotypicalGroup group = synonym.getHomotypicGroup();
57

    
58
		TaxonName newSynonymName = ParseHandler.createEmptyName();
59

    
60
		AbstractPostOperation<?> operation;
61

    
62
		operation = new CreateSynonymInExistingHomotypicalGroupOperation(menuItem.getLocalizedLabel(), editor.getUndoContext(),
63
        					editor.getTaxon(), group, newSynonymName, editor);
64
        AbstractUtility.executeOperation(operation, sync);
65

    
66
	}
67

    
68

    
69
    @CanExecute
70
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
71
            MHandledMenuItem menuItem){
72
        boolean canExecute = false;
73
        Object selectedElement = selection.getFirstElement();
74
        canExecute = NameEditorMenuPropertyTester.isSynonym(selectedElement);
75
        menuItem.setVisible(canExecute);
76
        return canExecute;
77
    }
78
}
(11-11/16)