Project

General

Profile

Download (2.04 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 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

    
20
import eu.etaxonomy.cdm.model.term.TermTree;
21
import eu.etaxonomy.cdm.model.term.TermType;
22
import eu.etaxonomy.taxeditor.featuretree.e4.IFeatureTreeEditor;
23
import eu.etaxonomy.taxeditor.featuretree.e4.operation.CreateFeatureTreeOperation;
24
import eu.etaxonomy.taxeditor.model.AbstractUtility;
25
import eu.etaxonomy.taxeditor.store.StoreUtil;
26

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

    
34
    @Execute
35
    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart thisPart, UISynchronize sync){
36
        IFeatureTreeEditor editor = (IFeatureTreeEditor) thisPart.getObject();
37

    
38
        if (StoreUtil.promptCheckIsDirty(editor)) {
39
            return;
40
        }
41

    
42
        TermTree tree = TermTree.NewInstance(getTermType());
43
        tree.setTitleCache("New feature tree", true);
44
        CreateFeatureTreeOperation operation = new CreateFeatureTreeOperation(tree, editor, editor);
45
        AbstractUtility.executeOperation(operation, sync);
46
    }
47

    
48
    protected TermType getTermType(){
49
        return TermType.Feature;
50
    }
51

    
52
    @CanExecute
53
    public boolean canExecute(
54
            @Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
55
            MHandledMenuItem menuItem) {
56
        boolean canExecute = false;
57
        canExecute = thisPart.getObject() instanceof IFeatureTreeEditor;
58
        menuItem.setVisible(canExecute);
59
        return canExecute;
60
    }
61

    
62
}
(4-4/11)