Project

General

Profile

Download (3.37 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2018 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
package eu.etaxonomy.taxeditor.editor.name.e4.handler;
10

    
11
import javax.inject.Named;
12

    
13
import org.eclipse.e4.core.di.annotations.CanExecute;
14
import org.eclipse.e4.core.di.annotations.Execute;
15
import org.eclipse.e4.ui.di.UISynchronize;
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.ChangeSynonymToConceptOperation;
30
import eu.etaxonomy.taxeditor.model.AbstractUtility;
31
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
32
/**
33
 * @author k.luther
34
 * @since 14.09.2018
35
 *
36
 */
37
public class ChangeToInvalidDesignationHandlerE4 {
38
    private TaxonNameEditorE4 editor;
39

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

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

    
49
        Object selectedElement = selection.getFirstElement();
50

    
51
        AbstractPostTaxonOperation operation = null;
52
        if(selectedElement instanceof Taxon){
53
            operation = new ChangeConceptRelationshipTypeOperation(menuItem.getLocalizedLabel(),
54
                                    editor.getUndoContext(), editor.getTaxon(), (Taxon) selectedElement, TaxonRelationshipType.INVALID_DESIGNATION_FOR(), editor);
55
        }
56
        if(selectedElement instanceof Synonym){
57
            operation = new ChangeSynonymToConceptOperation(menuItem.getLocalizedLabel(),
58
                    editor.getUndoContext(), editor.getTaxon(), (Synonym) selectedElement, TaxonRelationshipType.INVALID_DESIGNATION_FOR(), editor);
59
        }
60
        if (!EditorUtil.forceUserSaveE4Editor(editor, shell)){
61
            return ;
62
        }
63
        //editor.getEditorInput().addOperation(operation);
64
        AbstractUtility.executeOperation(operation, sync);
65
    }
66

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

    
81
}
(2-2/16)