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.core.di.annotations.Optional;
|
18
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
19
|
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
20
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
21
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
22
|
|
23
|
import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
|
24
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
25
|
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditor;
|
26
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
27
|
|
28
|
/**
|
29
|
* @author pplitzner
|
30
|
* @since Jul 12, 2017
|
31
|
*
|
32
|
*/
|
33
|
public class RemoveFeatureTreeHandler {
|
34
|
|
35
|
@Execute
|
36
|
public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
|
37
|
@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection){
|
38
|
for (Object selectedObject : selection.toArray()) {
|
39
|
FeatureTree featureTree = (FeatureTree) selectedObject;
|
40
|
CdmStore.getService(IFeatureTreeService.class).delete(featureTree.getUuid());
|
41
|
}
|
42
|
FeatureTreeEditor editor = (FeatureTreeEditor) thisPart.getObject();
|
43
|
List<FeatureTree> trees = CdmStore.getService(IFeatureTreeService.class).list(FeatureTree.class, null, null, null, null);
|
44
|
editor.getViewer().setInput(trees);
|
45
|
}
|
46
|
|
47
|
@CanExecute
|
48
|
public boolean canExecute(
|
49
|
@Optional@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
|
50
|
@Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
|
51
|
MHandledMenuItem menuItem) {
|
52
|
boolean canExecute = false;
|
53
|
if(selection!=null && !selection.isEmpty()){
|
54
|
for(Object object:selection.toArray()){
|
55
|
canExecute &= object instanceof FeatureTree;
|
56
|
}
|
57
|
}
|
58
|
canExecute &= thisPart.getObject() instanceof FeatureTreeEditor;
|
59
|
menuItem.setVisible(canExecute);
|
60
|
return canExecute;
|
61
|
}
|
62
|
|
63
|
}
|