Project

General

Profile

Download (3.35 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.AbstractPostTaxonOperation;
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

    
54
		Object selectedElement = selection.getFirstElement();
55

    
56
		AbstractPostTaxonOperation 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
            if (((Synonym)selectedElement).getId() == 0){
63
                //only create a new Taxon with name of synonym, create a taxonRelationship and remove the synonym
64
            }else{
65
                operation = new ChangeSynonymToMisapplicationOperation(menuItem.getLocalizedLabel(),
66
                        editor.getUndoContext(), editor.getTaxon(), (Synonym) selectedElement, editor);
67
            }
68

    
69
        }
70

    
71

    
72
        if (!EditorUtil.forceUserSaveE4Editor(editor, shell)){
73
            return ;
74
        }
75
        AbstractUtility.executeOperation(operation, sync);
76
	}
77

    
78
    @CanExecute
79
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
80
            MHandledMenuItem menuItem){
81
        boolean canExecute = false;
82
        if(selection.size()==1){
83
            Object selectedElement = selection.getFirstElement();
84
            canExecute = NameEditorMenuPropertyTester.isNotMisapplication(selectedElement);
85
        }
86
        menuItem.setVisible(canExecute);
87
        return canExecute;
88
    }
89

    
90
}
(3-3/16)