1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
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.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.editor.key.polytomous.handler;
|
12
|
|
13
|
import org.eclipse.core.commands.AbstractHandler;
|
14
|
import org.eclipse.core.commands.ExecutionEvent;
|
15
|
import org.eclipse.core.commands.ExecutionException;
|
16
|
import org.eclipse.core.commands.common.NotDefinedException;
|
17
|
import org.eclipse.core.commands.operations.IUndoContext;
|
18
|
import org.eclipse.jface.dialogs.MessageDialog;
|
19
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
20
|
import org.eclipse.ui.IEditorPart;
|
21
|
import org.eclipse.ui.handlers.HandlerUtil;
|
22
|
|
23
|
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
|
24
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
25
|
import eu.etaxonomy.taxeditor.editor.key.KeyEditor;
|
26
|
import eu.etaxonomy.taxeditor.editor.key.polytomous.IPolytomousKeyEditorPage;
|
27
|
import eu.etaxonomy.taxeditor.editor.key.polytomous.operation.DeleteNodeOperation;
|
28
|
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
|
29
|
|
30
|
/**
|
31
|
* @author n.hoffmann
|
32
|
* @created Dec 6, 2010
|
33
|
* @version 1.0
|
34
|
*/
|
35
|
public class DeleteNodeHandler extends AbstractHandler {
|
36
|
|
37
|
/*
|
38
|
* (non-Javadoc)
|
39
|
*
|
40
|
* @see
|
41
|
* org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.
|
42
|
* ExecutionEvent)
|
43
|
*/
|
44
|
@Override
|
45
|
public Object execute(ExecutionEvent event) throws ExecutionException {
|
46
|
IEditorPart editor = HandlerUtil.getActiveEditor(event);
|
47
|
|
48
|
if (editor instanceof KeyEditor) {
|
49
|
IPolytomousKeyEditorPage editorPage = (IPolytomousKeyEditorPage) ((KeyEditor) editor)
|
50
|
.getActiveEditor();
|
51
|
|
52
|
IStructuredSelection selection = (IStructuredSelection) HandlerUtil
|
53
|
.getCurrentSelection(event);
|
54
|
|
55
|
if (selection.getFirstElement() instanceof PolytomousKeyNode) {
|
56
|
try {
|
57
|
String label = event.getCommand().getName();
|
58
|
IUndoContext undoContext = EditorUtil.getUndoContext();
|
59
|
|
60
|
for (Object element : selection.toArray()) {
|
61
|
PolytomousKeyNode keyNode = (PolytomousKeyNode) element;
|
62
|
|
63
|
AbstractPostOperation operation = new DeleteNodeOperation(
|
64
|
label, undoContext, keyNode, editorPage);
|
65
|
EditorUtil.executeOperation(operation);
|
66
|
}
|
67
|
|
68
|
} catch (NotDefinedException e) {
|
69
|
EditorUtil.warn(getClass(), "Command name not set.");
|
70
|
}
|
71
|
} else {
|
72
|
MessageDialog.openInformation(
|
73
|
EditorUtil.getShell(),
|
74
|
"No Key Node Selected",
|
75
|
"Please right-click on a specific key node to delete a key node.");
|
76
|
}
|
77
|
}
|
78
|
|
79
|
return null;
|
80
|
}
|
81
|
|
82
|
}
|