*/
package eu.etaxonomy.taxeditor.featuretree.e4.handler;
-import java.util.List;
-
import javax.inject.Named;
import org.eclipse.e4.core.di.annotations.CanExecute;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.core.di.annotations.Optional;
+import org.eclipse.e4.ui.di.UISynchronize;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.jface.viewers.IStructuredSelection;
-import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
import eu.etaxonomy.cdm.model.description.FeatureTree;
-import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditor;
-import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.featuretree.e4.IFeatureTreeEditor;
+import eu.etaxonomy.taxeditor.featuretree.e4.operation.RemoveFeatureTreeOperation;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
+import eu.etaxonomy.taxeditor.store.StoreUtil;
/**
* @author pplitzner
@Execute
public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
- @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection){
- FeatureTreeEditor editor = (FeatureTreeEditor) thisPart.getObject();
- List<FeatureTree> trees = (List<FeatureTree>) editor.getViewer().getInput();
+ @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection, UISynchronize sync){
+ IFeatureTreeEditor editor = (IFeatureTreeEditor) thisPart.getObject();
+
+ if (StoreUtil.promptCheckIsDirty(editor)) {
+ return;
+ }
+ if(!StoreUtil.confirmDelete()){
+ return;
+ }
+
for (Object selectedObject : selection.toArray()) {
FeatureTree featureTree = (FeatureTree) selectedObject;
- CdmStore.getService(IFeatureTreeService.class).delete(featureTree.getUuid());
- trees.remove(featureTree);
+ RemoveFeatureTreeOperation operation = new RemoveFeatureTreeOperation(featureTree, editor, editor);
+ AbstractUtility.executeOperation(operation, sync);
}
- editor.getViewer().setInput(trees);
}
@CanExecute
canExecute &= object instanceof FeatureTree;
}
}
- canExecute &= thisPart.getObject() instanceof FeatureTreeEditor;
+ canExecute &= thisPart.getObject() instanceof IFeatureTreeEditor;
menuItem.setVisible(canExecute);
return canExecute;
}