Project

General

Profile

Download (3.23 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2

    
3
* Copyright (C) 2018 EDIT
4

    
5
* European Distributed Institute of Taxonomy
6

    
7
* http://www.e-taxonomy.eu
8

    
9
*
10

    
11
* The contents of this file are subject to the Mozilla Public License Version 1.1
12

    
13
* See LICENSE.TXT at the top of this package for the full license terms.
14

    
15
*/
16

    
17
package eu.etaxonomy.taxeditor.editor.name.e4.handler;
18

    
19
import javax.inject.Named;
20

    
21
import org.eclipse.e4.core.di.annotations.CanExecute;
22
import org.eclipse.e4.core.di.annotations.Execute;
23
import org.eclipse.e4.ui.di.UISynchronize;
24
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
25
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
26
import org.eclipse.e4.ui.services.IServiceConstants;
27
import org.eclipse.jface.viewers.IStructuredSelection;
28
import org.eclipse.swt.widgets.Shell;
29

    
30
import eu.etaxonomy.cdm.model.taxon.Synonym;
31
import eu.etaxonomy.cdm.model.taxon.Taxon;
32
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
33
import eu.etaxonomy.taxeditor.editor.EditorUtil;
34
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
35
import eu.etaxonomy.taxeditor.editor.name.handler.NameEditorMenuPropertyTester;
36
import eu.etaxonomy.taxeditor.editor.name.operation.ChangeConceptRelationshipTypeOperation;
37
import eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToConceptOperation;
38
import eu.etaxonomy.taxeditor.model.AbstractUtility;
39
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
40

    
41
/**
42
 * @author k.luther
43
 * @since 14.09.2018
44
 *
45
 */
46

    
47
public class ChangeToInvalidDesignationHandlerE4 {
48
    private TaxonNameEditorE4 editor;
49

    
50
    @Execute
51
    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
52
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
53
            @Named(IServiceConstants.ACTIVE_SHELL)Shell shell,
54
            MHandledMenuItem menuItem,
55
            UISynchronize sync) {
56

    
57
        editor = (TaxonNameEditorE4) activePart.getObject();
58
        Object selectedElement = selection.getFirstElement();
59
        AbstractPostTaxonOperation operation = null;
60

    
61
        if(selectedElement instanceof Taxon){
62
            operation = new ChangeConceptRelationshipTypeOperation(menuItem.getLocalizedLabel(),
63
                                    editor.getUndoContext(), editor.getTaxon(), (Taxon) selectedElement, TaxonRelationshipType.INVALID_DESIGNATION_FOR(), editor);
64
        }
65

    
66
        if(selectedElement instanceof Synonym){
67
            operation = new ChangeSynonymToConceptOperation(menuItem.getLocalizedLabel(),
68
                    editor.getUndoContext(), editor.getTaxon(), (Synonym) selectedElement, TaxonRelationshipType.INVALID_DESIGNATION_FOR(), editor);
69
        }
70

    
71
        if (!EditorUtil.forceUserSaveE4Editor(editor, shell)){
72
            return ;
73
        }
74

    
75
        AbstractUtility.executeOperation(operation, sync);
76

    
77
    }
78

    
79
    @CanExecute
80
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
81
            MHandledMenuItem menuItem){
82

    
83
        boolean canExecute = false;
84
        if(selection.size()==1){
85
            Object selectedElement = selection.getFirstElement();
86
            canExecute = NameEditorMenuPropertyTester.isNotInvalidDesignation(selectedElement);
87
        }
88
        menuItem.setVisible(canExecute);
89
        return canExecute;
90
    }
91

    
92
}
93

    
(2-2/16)