Project

General

Profile

Download (2.05 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.taxeditor.editor.key.polytomous.handler;
2

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

    
12
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
13
import eu.etaxonomy.taxeditor.editor.EditorUtil;
14
import eu.etaxonomy.taxeditor.editor.key.KeyEditor;
15
import eu.etaxonomy.taxeditor.editor.key.polytomous.IPolytomousKeyEditorPage;
16
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyListEditor;
17
import eu.etaxonomy.taxeditor.editor.key.polytomous.operation.RefreshNodeNumberingOperation;
18
import eu.etaxonomy.taxeditor.model.MessagingUtils;
19
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
20

    
21
public class RefreshNodeNumberingHandler extends AbstractHandler {
22

    
23
	@Override
24
	public Object execute(ExecutionEvent event) throws ExecutionException {
25
		IEditorPart editor = HandlerUtil.getActiveEditor(event);
26

    
27
		if (editor instanceof KeyEditor) {
28
			IPolytomousKeyEditorPage editorPage = (IPolytomousKeyEditorPage) ((KeyEditor) editor)
29
					.getActiveEditor();
30

    
31
			if (editorPage instanceof PolytomousKeyListEditor) {
32

    
33
				IStructuredSelection selection = (IStructuredSelection) HandlerUtil
34
						.getCurrentSelection(event);
35

    
36
				if (selection.getFirstElement() instanceof PolytomousKeyNode) {
37
					try {
38
						String label = event.getCommand().getName();
39
						IUndoContext undoContext = EditorUtil.getUndoContext();
40

    
41
						PolytomousKeyNode keyNode = (PolytomousKeyNode) selection
42
								.getFirstElement();
43

    
44
						AbstractPostOperation operation = new RefreshNodeNumberingOperation(
45
								label, undoContext, keyNode, editorPage);
46
					} catch (NotDefinedException e) {
47
						MessagingUtils.warn(getClass(), "Command name not set."); //$NON-NLS-1$
48
					}
49
				}
50
			}
51
		}
52

    
53
		return null;
54
	}
55

    
56
}
(6-6/8)