Revision 72eff2a6
Added by Patrick Plitzner about 6 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/RemoveFeatureHandler.java | ||
---|---|---|
13 | 13 |
import org.eclipse.e4.core.di.annotations.CanExecute; |
14 | 14 |
import org.eclipse.e4.core.di.annotations.Execute; |
15 | 15 |
import org.eclipse.e4.ui.model.application.ui.basic.MPart; |
16 |
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem; |
|
16 | 17 |
import org.eclipse.e4.ui.services.IServiceConstants; |
17 | 18 |
import org.eclipse.jface.viewers.IStructuredSelection; |
18 | 19 |
|
19 | 20 |
import eu.etaxonomy.cdm.api.service.IFeatureNodeService; |
20 | 21 |
import eu.etaxonomy.cdm.api.service.config.FeatureNodeDeletionConfigurator; |
21 | 22 |
import eu.etaxonomy.cdm.model.description.FeatureNode; |
22 |
import eu.etaxonomy.cdm.model.description.FeatureTree; |
|
23 | 23 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
24 | 24 |
import eu.etaxonomy.taxeditor.workbench.part.IE4ViewerPart; |
25 | 25 |
|
... | ... | |
31 | 31 |
public class RemoveFeatureHandler { |
32 | 32 |
|
33 | 33 |
@Execute |
34 |
public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart thisPart){ |
|
35 |
if(thisPart.getObject() instanceof IE4ViewerPart){ |
|
36 |
IE4ViewerPart editor = (IE4ViewerPart) thisPart.getObject(); |
|
37 |
IStructuredSelection selection = editor.getSelection(); |
|
38 |
for (Object selectedObject : selection.toArray()) { |
|
39 |
FeatureNode featureNode = (FeatureNode) selectedObject; |
|
40 |
CdmStore.getService(IFeatureNodeService.class).deleteFeatureNode(featureNode.getUuid(), new FeatureNodeDeletionConfigurator()); |
|
41 |
} |
|
42 |
editor.refresh(); |
|
34 |
public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart thisPart, |
|
35 |
@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection){ |
|
36 |
for (Object selectedObject : selection.toArray()) { |
|
37 |
FeatureNode featureNode = (FeatureNode) selectedObject; |
|
38 |
CdmStore.getService(IFeatureNodeService.class).deleteFeatureNode(featureNode.getUuid(), new FeatureNodeDeletionConfigurator()); |
|
43 | 39 |
} |
40 |
IE4ViewerPart editor = (IE4ViewerPart) thisPart.getObject(); |
|
41 |
editor.refresh(); |
|
44 | 42 |
} |
45 | 43 |
|
46 | 44 |
@CanExecute |
47 |
public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart thisPart){ |
|
48 |
if(thisPart.getObject() instanceof IE4ViewerPart){ |
|
49 |
IE4ViewerPart viewerPart = (IE4ViewerPart)thisPart.getObject(); |
|
50 |
return viewerPart.getSelection() instanceof FeatureTree; |
|
45 |
public boolean canExecute( |
|
46 |
@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection, |
|
47 |
@Named(IServiceConstants.ACTIVE_PART)MPart thisPart, |
|
48 |
MHandledMenuItem menuItem) { |
|
49 |
boolean canExecute = !selection.isEmpty(); |
|
50 |
for(Object object:selection.toArray()){ |
|
51 |
canExecute &= object instanceof FeatureNode; |
|
51 | 52 |
} |
52 |
return false; |
|
53 |
canExecute &= thisPart.getObject() instanceof IE4ViewerPart; |
|
54 |
menuItem.setVisible(canExecute); |
|
55 |
return canExecute; |
|
53 | 56 |
} |
54 | 57 |
|
55 | 58 |
} |
Also available in: Unified diff
ref #6746 Add/adapt handlers for feature tree editor