Project

General

Profile

Download (2.22 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.dialogs.MessageDialog;
9
import org.eclipse.jface.viewers.IStructuredSelection;
10
import org.eclipse.ui.IEditorPart;
11
import org.eclipse.ui.handlers.HandlerUtil;
12

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

    
23
public class RefreshNodeNumberingHandler extends AbstractHandler {
24

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

    
29
		if (editor instanceof KeyEditor) {
30
			IPolytomousKeyEditorPage editorPage = (IPolytomousKeyEditorPage) ((KeyEditor) editor)
31
					.getActiveEditor();
32

    
33
			if (editorPage instanceof PolytomousKeyListEditor) {
34
								
35
				IStructuredSelection selection = (IStructuredSelection) HandlerUtil
36
						.getCurrentSelection(event);
37

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

    
43
						PolytomousKeyNode keyNode = (PolytomousKeyNode) selection
44
								.getFirstElement();
45

    
46
						AbstractPostOperation operation = new RefreshNodeNumberingOperation(
47
								label, undoContext, keyNode, editorPage);
48
						EditorUtil.executeOperation(operation);
49
					} catch (NotDefinedException e) {
50
						MessagingUtils.warn(getClass(), "Command name not set.");
51
					}
52
				} 
53
			}
54
		}	    
55

    
56
		return null;
57
	}
58

    
59
}
(4-4/4)