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.model.application.ui.basic.MPart;
|
16
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
17
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
18
|
|
19
|
import eu.etaxonomy.cdm.api.service.IFeatureNodeService;
|
20
|
import eu.etaxonomy.cdm.api.service.config.FeatureNodeDeletionConfigurator;
|
21
|
import eu.etaxonomy.cdm.model.description.FeatureNode;
|
22
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
23
|
import eu.etaxonomy.taxeditor.workbench.part.IE4ViewerPart;
|
24
|
|
25
|
/**
|
26
|
* @author pplitzner
|
27
|
* @since Jul 12, 2017
|
28
|
*
|
29
|
*/
|
30
|
public class RemoveFeatureHandler {
|
31
|
|
32
|
@Execute
|
33
|
public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart thisPart){
|
34
|
if(thisPart.getObject() instanceof IE4ViewerPart){
|
35
|
IE4ViewerPart editor = (IE4ViewerPart) thisPart.getObject();
|
36
|
IStructuredSelection selection = editor.getSelection();
|
37
|
for (Object selectedObject : selection.toArray()) {
|
38
|
FeatureNode featureNode = (FeatureNode) selectedObject;
|
39
|
CdmStore.getService(IFeatureNodeService.class).deleteFeatureNode(featureNode.getUuid(), new FeatureNodeDeletionConfigurator());
|
40
|
}
|
41
|
editor.refresh();
|
42
|
}
|
43
|
}
|
44
|
|
45
|
@CanExecute
|
46
|
public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart thisPart){
|
47
|
if(thisPart.getObject() instanceof IE4ViewerPart){
|
48
|
IE4ViewerPart viewerPart = (IE4ViewerPart)thisPart.getObject();
|
49
|
return viewerPart.getSelection()!=null && !viewerPart.getSelection().isEmpty();
|
50
|
}
|
51
|
return false;
|
52
|
}
|
53
|
|
54
|
}
|