Project

General

Profile

Download (2.16 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2017 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.descriptiveDataSet.character.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.core.di.annotations.Optional;
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.jface.viewers.StructuredSelection;
22
import org.eclipse.swt.widgets.Shell;
23

    
24
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.character.CharacterEditor;
25
import eu.etaxonomy.taxeditor.termtree.e4.handler.AddTermHandler;
26

    
27
/**
28
 * @author pplitzner
29
 * @since Jul 12, 2017
30
 *
31
 */
32
public class AddFeatureToCharacterTreeHandler extends AddTermHandler {
33

    
34
    @Execute
35
    @Override
36
    public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell,
37
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
38
            @Named(IServiceConstants.ACTIVE_PART)MPart thisPart, UISynchronize sync) {
39
        CharacterEditor editor = (CharacterEditor) thisPart.getObject();
40
        super.execute(shell, new StructuredSelection(editor.getCharacterTree()), thisPart, sync);
41
    }
42

    
43
    @Override
44
    @CanExecute
45
    public boolean canExecute(
46
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
47
            @Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
48
            MHandledMenuItem menuItem) {
49
        boolean canExecute = false;
50
        canExecute = thisPart.getObject() instanceof CharacterEditor
51
                && ((CharacterEditor) thisPart.getObject()).getCharacterTree()!=null
52
                && (selection==null || selection.isEmpty());
53
        menuItem.setVisible(canExecute);
54
        return canExecute;
55
    }
56
}
    (1-1/1)