Project

General

Profile

Download (1.64 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.featuretree.e4.handler;
10

    
11
import java.util.List;
12

    
13
import javax.inject.Named;
14

    
15
import org.eclipse.e4.core.di.annotations.CanExecute;
16
import org.eclipse.e4.core.di.annotations.Execute;
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

    
21
import eu.etaxonomy.cdm.model.description.FeatureTree;
22
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditor;
23

    
24
/**
25
 * @author pplitzner
26
 * @since Jul 12, 2017
27
 *
28
 */
29
public class CreateFeatureTreeHandler {
30

    
31
    @Execute
32
    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart thisPart){
33
        FeatureTree tree = FeatureTree.NewInstance();
34
        tree.setTitleCache("New feature tree", true);
35
        FeatureTreeEditor editor = (FeatureTreeEditor) thisPart.getObject();
36
        List<FeatureTree> trees = (List<FeatureTree>) editor.getViewer().getInput();
37
        trees.add(tree);
38
        editor.getViewer().setInput(trees);
39
        editor.setDirty(true);
40
    }
41

    
42
    @CanExecute
43
    public boolean canExecute(
44
            @Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
45
            MHandledMenuItem menuItem) {
46
        boolean canExecute = false;
47
        canExecute = thisPart.getObject() instanceof FeatureTreeEditor;
48
        menuItem.setVisible(canExecute);
49
        return canExecute;
50
    }
51

    
52
}
(3-3/6)