Revision e82bceda
Added by U-BGBM\k.luther over 8 years ago
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/handler/DeleteHandler.java | ||
---|---|---|
1 | 1 |
// $Id$ |
2 | 2 |
/** |
3 | 3 |
* Copyright (C) 2007 EDIT |
4 |
* European Distributed Institute of Taxonomy
|
|
4 |
* European Distributed Institute of Taxonomy |
|
5 | 5 |
* http://www.e-taxonomy.eu |
6 |
*
|
|
6 |
* |
|
7 | 7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
8 | 8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
9 | 9 |
*/ |
... | ... | |
17 | 17 |
import org.eclipse.core.commands.ExecutionException; |
18 | 18 |
import org.eclipse.core.commands.common.NotDefinedException; |
19 | 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; |
|
20 | 24 |
import org.eclipse.ui.handlers.HandlerUtil; |
21 | 25 |
|
22 | 26 |
import eu.etaxonomy.cdm.model.description.PolytomousKey; |
27 |
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyEditorInput; |
|
23 | 28 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
24 | 29 |
import eu.etaxonomy.taxeditor.navigation.NavigationUtil; |
25 | 30 |
import eu.etaxonomy.taxeditor.navigation.key.polytomous.PolytomousKeyViewPart; |
... | ... | |
33 | 38 |
*/ |
34 | 39 |
public class DeleteHandler extends AbstractHandler { |
35 | 40 |
|
41 |
protected IWorkbenchPage activePage; |
|
36 | 42 |
/* (non-Javadoc) |
37 | 43 |
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) |
38 | 44 |
*/ |
39 | 45 |
@Override |
40 | 46 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
41 | 47 |
IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event); |
42 |
|
|
48 |
activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage(); |
|
43 | 49 |
List<PolytomousKey> keys = selection.toList(); |
44 |
|
|
50 |
|
|
45 | 51 |
if(keys.isEmpty()){ |
46 | 52 |
return null; |
47 | 53 |
} |
48 |
|
|
54 |
for (PolytomousKey key : keys){ |
|
55 |
closeObsoleteEditor(key); |
|
56 |
} |
|
49 | 57 |
boolean confirmation = MessagingUtils.confirmDialog("Confirm deletaion", "Do you want to delete the selected key" + (keys.size() == 1 ? "" : "s") + "?"); |
50 |
|
|
58 |
|
|
51 | 59 |
if(confirmation){ |
52 |
|
|
60 |
|
|
53 | 61 |
for(PolytomousKey key : keys){ |
54 | 62 |
try { |
55 | 63 |
AbstractPostOperation operation = new DeleteOperation( |
56 | 64 |
event.getCommand().getName(), |
57 |
NavigationUtil.getUndoContext(), key,
|
|
65 |
NavigationUtil.getUndoContext(), key, |
|
58 | 66 |
(PolytomousKeyViewPart) NavigationUtil.getView(PolytomousKeyViewPart.ID, false), |
59 | 67 |
(PolytomousKeyViewPart) NavigationUtil.getView(PolytomousKeyViewPart.ID, false)); |
60 | 68 |
NavigationUtil.executeOperation(operation); |
... | ... | |
63 | 71 |
} |
64 | 72 |
} |
65 | 73 |
} |
66 |
|
|
74 |
|
|
67 | 75 |
return null; |
68 | 76 |
} |
69 | 77 |
|
78 |
|
|
79 |
protected boolean closeObsoleteEditor(PolytomousKey key){ |
|
80 |
boolean result = true; |
|
81 |
for (IEditorReference ref : activePage.getEditorReferences()) { |
|
82 |
try { |
|
83 |
|
|
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 |
|
88 |
if(key.equals(pKey)){ |
|
89 |
//if (taxonNode.equals(node)) { |
|
90 |
result &= activePage.closeEditor(ref.getEditor(false), true); |
|
91 |
|
|
92 |
} |
|
93 |
} |
|
94 |
} catch (PartInitException e) { |
|
95 |
continue; |
|
96 |
} |
|
97 |
} |
|
98 |
return result; |
|
99 |
} |
|
70 | 100 |
} |
Also available in: Unified diff
close the polytomouskey-editor if the key is deleted