3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.navigation
.key
.polytomous
.handler
;
13 import java
.util
.List
;
15 import org
.eclipse
.core
.commands
.AbstractHandler
;
16 import org
.eclipse
.core
.commands
.ExecutionEvent
;
17 import org
.eclipse
.core
.commands
.ExecutionException
;
18 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
19 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
20 import org
.eclipse
.ui
.IEditorInput
;
21 import org
.eclipse
.ui
.IEditorReference
;
22 import org
.eclipse
.ui
.IWorkbenchPage
;
23 import org
.eclipse
.ui
.PartInitException
;
24 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
26 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKey
;
27 import eu
.etaxonomy
.taxeditor
.editor
.key
.polytomous
.PolytomousKeyEditorInput
;
28 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
29 import eu
.etaxonomy
.taxeditor
.navigation
.NavigationUtil
;
30 import eu
.etaxonomy
.taxeditor
.navigation
.key
.polytomous
.PolytomousKeyViewPart
;
31 import eu
.etaxonomy
.taxeditor
.navigation
.key
.polytomous
.operation
.DeleteOperation
;
32 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
36 * @created Dec 3, 2010
39 public class DeleteHandler
extends AbstractHandler
{
41 protected IWorkbenchPage activePage
;
43 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
46 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
47 IStructuredSelection selection
= (IStructuredSelection
) HandlerUtil
.getCurrentSelection(event
);
48 activePage
= HandlerUtil
.getActiveWorkbenchWindow(event
).getActivePage();
49 List
<PolytomousKey
> keys
= selection
.toList();
54 for (PolytomousKey key
: keys
){
55 closeObsoleteEditor(key
);
57 boolean confirmation
= MessagingUtils
.confirmDialog("Confirm deletaion", "Do you want to delete the selected key" + (keys
.size() == 1 ?
"" : "s") + "?");
61 for(PolytomousKey key
: keys
){
63 AbstractPostOperation operation
= new DeleteOperation(
64 event
.getCommand().getName(),
65 NavigationUtil
.getUndoContext(), key
,
66 (PolytomousKeyViewPart
) NavigationUtil
.getView(PolytomousKeyViewPart
.ID
, false),
67 (PolytomousKeyViewPart
) NavigationUtil
.getView(PolytomousKeyViewPart
.ID
, false));
68 NavigationUtil
.executeOperation(operation
);
69 } catch (NotDefinedException e
) {
70 MessagingUtils
.error(getClass(), e
);
79 protected boolean closeObsoleteEditor(PolytomousKey key
){
80 boolean result
= true;
81 for (IEditorReference ref
: activePage
.getEditorReferences()) {
84 IEditorInput input
= ref
.getEditorInput();
85 if (input
instanceof PolytomousKeyEditorInput
) {
86 PolytomousKey pKey
= ((PolytomousKeyEditorInput
)input
).getKey();
87 //if node is a child of taxonNode then close the editor
89 //if (taxonNode.equals(node)) {
90 result
&= activePage
.closeEditor(ref
.getEditor(false), true);
94 } catch (PartInitException e
) {