Project

General

Profile

Download (2.02 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * 
3
 */
4
package eu.etaxonomy.taxeditor.editor.key.polytomous.handler;
5

    
6
import org.eclipse.core.commands.AbstractHandler;
7
import org.eclipse.core.commands.ExecutionEvent;
8
import org.eclipse.core.commands.ExecutionException;
9
import org.eclipse.core.commands.common.NotDefinedException;
10
import org.eclipse.core.commands.operations.IUndoContext;
11
import org.eclipse.jface.viewers.IStructuredSelection;
12
import org.eclipse.ui.IEditorPart;
13
import org.eclipse.ui.handlers.HandlerUtil;
14

    
15
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
16
import eu.etaxonomy.taxeditor.editor.EditorUtil;
17
import eu.etaxonomy.taxeditor.editor.key.KeyEditor;
18
import eu.etaxonomy.taxeditor.editor.key.polytomous.IPolytomousKeyEditorPage;
19
import eu.etaxonomy.taxeditor.editor.key.polytomous.operation.CreateNodeOperation;
20
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
21

    
22
/**
23
 * @author n.hoffmann
24
 * 
25
 */
26
public class CreateNodeHandler extends AbstractHandler {
27

    
28
	/*
29
	 * (non-Javadoc)
30
	 * 
31
	 * @see
32
	 * org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.
33
	 * ExecutionEvent)
34
	 */
35
	@Override
36
	public Object execute(ExecutionEvent event) throws ExecutionException {
37

    
38
		IEditorPart editor = HandlerUtil.getActiveEditor(event);
39

    
40
		if (editor instanceof KeyEditor) {
41
			IPolytomousKeyEditorPage editorPage = (IPolytomousKeyEditorPage) ((KeyEditor) editor)
42
					.getActiveEditor();
43

    
44
			IStructuredSelection selection = (IStructuredSelection) HandlerUtil
45
					.getCurrentSelection(event);
46

    
47
			if (selection.getFirstElement() instanceof PolytomousKeyNode) {
48
				try {
49
					String label = event.getCommand().getName();
50
					IUndoContext undoContext = EditorUtil.getUndoContext();
51

    
52
					PolytomousKeyNode keyNode = (PolytomousKeyNode) selection
53
							.getFirstElement();
54

    
55
					AbstractPostOperation operation = new CreateNodeOperation(
56
							label, undoContext, keyNode, editorPage);
57
					EditorUtil.executeOperation(operation);
58
				} catch (NotDefinedException e) {
59
					EditorUtil.warn(getClass(), "Command name not set.");
60
				}
61

    
62
			}
63
		}
64

    
65
		return null;
66
	}
67

    
68
}
(1-1/2)