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
|
import eu.etaxonomy.taxeditor.featuretree.e4.operation.CreateFeatureTreeOperation;
|
24
|
|
25
|
/**
|
26
|
* @author pplitzner
|
27
|
* @since Jul 12, 2017
|
28
|
*
|
29
|
*/
|
30
|
public class CreateFeatureTreeHandler {
|
31
|
|
32
|
@Execute
|
33
|
public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart thisPart){
|
34
|
FeatureTree tree = FeatureTree.NewInstance();
|
35
|
tree.setTitleCache("New feature tree", true);
|
36
|
FeatureTreeEditor editor = (FeatureTreeEditor) thisPart.getObject();
|
37
|
CreateFeatureTreeOperation operation = new CreateFeatureTreeOperation(tree, editor, editor);
|
38
|
editor.addOperation(operation);
|
39
|
List<FeatureTree> trees = (List<FeatureTree>) editor.getViewer().getInput();
|
40
|
trees.add(tree);
|
41
|
editor.getViewer().setInput(trees);
|
42
|
editor.setDirty(true);
|
43
|
}
|
44
|
|
45
|
@CanExecute
|
46
|
public boolean canExecute(
|
47
|
@Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
|
48
|
MHandledMenuItem menuItem) {
|
49
|
boolean canExecute = false;
|
50
|
canExecute = thisPart.getObject() instanceof FeatureTreeEditor;
|
51
|
menuItem.setVisible(canExecute);
|
52
|
return canExecute;
|
53
|
}
|
54
|
|
55
|
}
|