// $Id$
/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* European Distributed Institute of Taxonomy
* http://www.e-taxonomy.eu
-*
+*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.handlers.HandlerUtil;
-import eu.etaxonomy.cdm.model.taxon.ITreeNode;
+import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
private TaxonNavigator taxonNavigator;
/** {@inheritDoc} */
- public Object execute(ExecutionEvent event) throws ExecutionException {
-
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+
activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
-
+
taxonNavigator = NavigationUtil.showNavigator();
-
+
TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event);
-
+
String plural = selection.size() > 1 ? "s" : "";
// Prompt user for confirmation
if(! MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Confirm Deletion", "Are you sure you want to delete the selected node" + plural +"?")){
return null;
}
-
+
Iterator selectionIterator = selection.iterator();
- Set<ITreeNode> treeNodes = new HashSet<ITreeNode>();
-
+ Set<ITaxonTreeNode> treeNodes = new HashSet<ITaxonTreeNode>();
+
while (selectionIterator.hasNext()){
Object object = selectionIterator.next();
- if(object instanceof ITreeNode)
- treeNodes.add((ITreeNode) object);
+ if(object instanceof ITaxonTreeNode) {
+ treeNodes.add((ITaxonTreeNode) object);
+ }
}
-
+
AbstractPostOperation operation = null;
try {
operation = new DeleteOperation(
- event.getCommand().getName(), NavigationUtil.getUndoContext(),
+ event.getCommand().getName(), NavigationUtil.getUndoContext(),
treeNodes, taxonNavigator, taxonNavigator);
-
+
IStatus status = NavigationUtil.executeOperation(operation);
-
-
+
+
// FIXME is there a better place for this code?
if (status == Status.OK_STATUS){
- for (ITreeNode treeNode : treeNodes){
+ for (ITaxonTreeNode treeNode : treeNodes){
if(treeNode instanceof TaxonNode) {
closeObsoleteEditor((TaxonNode) treeNode);
}
}
}
-
+
} catch (NotDefinedException e) {
NavigationUtil.warn(getClass(), "Command name not set");
}
return null;
}
-
+
private void closeObsoleteEditor(TaxonNode taxonNode){
for (IEditorReference ref : activePage.getEditorReferences()) {
try {
- IEditorInput input = ref.getEditorInput();
+ IEditorInput input = ref.getEditorInput();
if (input instanceof TaxonEditorInput) {
TaxonNode node = ((TaxonEditorInput) input).getTaxonNode();
if (taxonNode.equals(node)) {