AT: commiting Palm Use Data extension
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / uses / handler / CreateUseHandler.java
1 package eu.etaxonomy.taxeditor.editor.view.uses.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.ui.IEditorInput;
8 import org.eclipse.ui.IEditorPart;
9 import org.eclipse.ui.IWorkbenchPart;
10 import org.eclipse.ui.forms.editor.FormEditor;
11 import org.eclipse.ui.handlers.HandlerUtil;
12
13 import eu.etaxonomy.cdm.model.taxon.Taxon;
14 import eu.etaxonomy.taxeditor.editor.EditorUtil;
15 import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
16 import eu.etaxonomy.taxeditor.editor.view.uses.operation.CreateTaxonUseOperation;
17 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
18 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
19
20 public class CreateUseHandler extends AbstractHandler {
21 /* (non-Javadoc)
22 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
23 */
24 /** {@inheritDoc} */
25 public Object execute(ExecutionEvent event) throws ExecutionException {
26 IWorkbenchPart part = HandlerUtil.getActivePart(event);
27 IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null;
28
29
30 IEditorPart editor = HandlerUtil.getActiveEditor(event);
31 if (editor instanceof FormEditor) {
32 editor = ((FormEditor) editor).getActiveEditor();
33 }
34 IEditorInput input = editor.getEditorInput();
35 if (input instanceof TaxonEditorInput) {
36 Taxon taxon = ((TaxonEditorInput) input).getTaxon();
37 AbstractPostOperation operation;
38 try {
39 // TODO use undo context specific to editor
40 operation = new CreateTaxonUseOperation(event.getCommand().getName(),
41 EditorUtil.getUndoContext(), taxon, postOperationEnabled);
42 EditorUtil.executeOperation(operation);
43 } catch (NotDefinedException e) {
44 EditorUtil.warn(getClass(), "Command name not set.");
45 }
46 }
47 return null;
48 }
49 }