// $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.core.commands.ExecutionException;
import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
import org.eclipse.ui.handlers.HandlerUtil;
import eu.etaxonomy.cdm.model.description.PolytomousKey;
+import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyEditorInput;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
import eu.etaxonomy.taxeditor.navigation.key.polytomous.PolytomousKeyViewPart;
*/
public class DeleteHandler extends AbstractHandler {
+ protected IWorkbenchPage activePage;
/* (non-Javadoc)
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
-
+ activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
List<PolytomousKey> keys = selection.toList();
-
+
if(keys.isEmpty()){
return null;
}
-
+ for (PolytomousKey key : keys){
+ closeObsoleteEditor(key);
+ }
boolean confirmation = MessagingUtils.confirmDialog("Confirm deletaion", "Do you want to delete the selected key" + (keys.size() == 1 ? "" : "s") + "?");
-
+
if(confirmation){
-
+
for(PolytomousKey key : keys){
try {
AbstractPostOperation operation = new DeleteOperation(
event.getCommand().getName(),
- NavigationUtil.getUndoContext(), key,
+ NavigationUtil.getUndoContext(), key,
(PolytomousKeyViewPart) NavigationUtil.getView(PolytomousKeyViewPart.ID, false),
(PolytomousKeyViewPart) NavigationUtil.getView(PolytomousKeyViewPart.ID, false));
NavigationUtil.executeOperation(operation);
}
}
}
-
+
return null;
}
+
+ protected boolean closeObsoleteEditor(PolytomousKey key){
+ boolean result = true;
+ for (IEditorReference ref : activePage.getEditorReferences()) {
+ try {
+
+ IEditorInput input = ref.getEditorInput();
+ if (input instanceof PolytomousKeyEditorInput) {
+ PolytomousKey pKey = ((PolytomousKeyEditorInput)input).getKey();
+ //if node is a child of taxonNode then close the editor
+ if(key.equals(pKey)){
+ //if (taxonNode.equals(node)) {
+ result &= activePage.closeEditor(ref.getEditor(false), true);
+
+ }
+ }
+ } catch (PartInitException e) {
+ continue;
+ }
+ }
+ return result;
+ }
}