Project

General

Profile

Download (1.95 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.taxeditor.featuretree.e4.IFeatureTreeEditor;
22
import eu.etaxonomy.taxeditor.featuretree.e4.operation.CreateFeatureTreeOperation;
23
import eu.etaxonomy.taxeditor.model.AbstractUtility;
24
import eu.etaxonomy.taxeditor.store.StoreUtil;
25

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

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

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

    
41
        TermTree tree = TermTree.NewInstance(editor.getTermType());
42
        tree.setTitleCache(String.format("New %s tree", editor.getTermType()), true);
43
        CreateFeatureTreeOperation operation = new CreateFeatureTreeOperation(tree, editor, editor);
44
        AbstractUtility.executeOperation(operation, sync);
45
    }
46

    
47
    @CanExecute
48
    public boolean canExecute(
49
            @Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
50
            MHandledMenuItem menuItem) {
51
        boolean canExecute = false;
52
        canExecute = thisPart.getObject() instanceof IFeatureTreeEditor;
53
        menuItem.setVisible(canExecute);
54
        return canExecute;
55
    }
56

    
57
}
(4-4/9)