From: U-BGBM\k.luther Date: Wed, 26 Aug 2015 10:29:16 +0000 (+0200) Subject: close the polytomouskey-editor if the key is deleted X-Git-Tag: 3.8.0^2~41 X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/commitdiff_plain/e82bceda15ffb75dae7f1fd7444fdbdbc2cabfe1?ds=sidebyside close the polytomouskey-editor if the key is deleted --- diff --git a/eu.etaxonomy.taxeditor.editor/META-INF/MANIFEST.MF b/eu.etaxonomy.taxeditor.editor/META-INF/MANIFEST.MF index 6cd6141ef..d4471b24e 100644 --- a/eu.etaxonomy.taxeditor.editor/META-INF/MANIFEST.MF +++ b/eu.etaxonomy.taxeditor.editor/META-INF/MANIFEST.MF @@ -9,6 +9,7 @@ Bundle-Localization: OSGI-INF/l10n/plugin Export-Package: eu.etaxonomy.taxeditor.editor, eu.etaxonomy.taxeditor.editor.handler, eu.etaxonomy.taxeditor.editor.internal, + eu.etaxonomy.taxeditor.editor.key.polytomous, eu.etaxonomy.taxeditor.editor.name, eu.etaxonomy.taxeditor.editor.name.handler, eu.etaxonomy.taxeditor.editor.view.concept, diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/handler/DeleteHandler.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/handler/DeleteHandler.java index faf141c73..a79682049 100644 --- a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/handler/DeleteHandler.java +++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/handler/DeleteHandler.java @@ -1,9 +1,9 @@ // $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. */ @@ -17,9 +17,14 @@ import org.eclipse.core.commands.ExecutionEvent; 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; @@ -33,28 +38,31 @@ import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; */ 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 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); @@ -63,8 +71,30 @@ public class DeleteHandler extends AbstractHandler { } } } - + 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; + } }