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.core.di.annotations.Optional;
|
16
|
import org.eclipse.e4.ui.di.UISynchronize;
|
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
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
21
|
|
22
|
import eu.etaxonomy.cdm.model.description.FeatureNode;
|
23
|
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditor;
|
24
|
import eu.etaxonomy.taxeditor.featuretree.e4.operation.RemoveFeatureOperation;
|
25
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
26
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
27
|
import eu.etaxonomy.taxeditor.workbench.part.IE4ViewerPart;
|
28
|
|
29
|
/**
|
30
|
* @author pplitzner
|
31
|
* @since Jul 12, 2017
|
32
|
*
|
33
|
*/
|
34
|
public class RemoveFeatureHandler {
|
35
|
|
36
|
@Execute
|
37
|
public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
|
38
|
@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection, UISynchronize sync){
|
39
|
FeatureTreeEditor editor = (FeatureTreeEditor) thisPart.getObject();
|
40
|
|
41
|
if (StoreUtil.checkDirty(editor)) {
|
42
|
return;
|
43
|
}
|
44
|
if(!StoreUtil.confirmDelete()){
|
45
|
return;
|
46
|
}
|
47
|
|
48
|
for (Object selectedObject : selection.toArray()) {
|
49
|
FeatureNode featureNode = (FeatureNode) selectedObject;
|
50
|
RemoveFeatureOperation operation = new RemoveFeatureOperation(featureNode, editor, editor);
|
51
|
AbstractUtility.executeOperation(operation, sync);
|
52
|
}
|
53
|
}
|
54
|
|
55
|
@CanExecute
|
56
|
public boolean canExecute(
|
57
|
@Optional@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
|
58
|
@Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
|
59
|
MHandledMenuItem menuItem) {
|
60
|
boolean canExecute = selection!=null && !selection.isEmpty();
|
61
|
if(selection!=null){
|
62
|
for(Object object:selection.toArray()){
|
63
|
canExecute &= object instanceof FeatureNode;
|
64
|
}
|
65
|
}
|
66
|
canExecute &= thisPart.getObject() instanceof IE4ViewerPart;
|
67
|
menuItem.setVisible(canExecute);
|
68
|
return canExecute;
|
69
|
}
|
70
|
|
71
|
}
|