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.description.FeatureTree;
|
21
|
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditor;
|
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
|
FeatureTreeEditor editor = (FeatureTreeEditor) thisPart.getObject();
|
36
|
|
37
|
if (StoreUtil.checkDirty(editor)) {
|
38
|
return;
|
39
|
}
|
40
|
|
41
|
|
42
|
FeatureTree tree = FeatureTree.NewInstance();
|
43
|
tree.setTitleCache("New feature tree", true);
|
44
|
CreateFeatureTreeOperation operation = new CreateFeatureTreeOperation(tree, editor, editor);
|
45
|
AbstractUtility.executeOperation(operation, sync);
|
46
|
}
|
47
|
|
48
|
@CanExecute
|
49
|
public boolean canExecute(
|
50
|
@Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
|
51
|
MHandledMenuItem menuItem) {
|
52
|
boolean canExecute = false;
|
53
|
canExecute = thisPart.getObject() instanceof FeatureTreeEditor;
|
54
|
menuItem.setVisible(canExecute);
|
55
|
return canExecute;
|
56
|
}
|
57
|
|
58
|
}
|