1 package eu
.etaxonomy
.taxeditor
.editor
.view
.uses
.handler
;
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
;
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
;
20 public class CreateUseHandler
extends AbstractHandler
{
22 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
25 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
26 IWorkbenchPart part
= HandlerUtil
.getActivePart(event
);
27 IPostOperationEnabled postOperationEnabled
= (part
instanceof IPostOperationEnabled
) ?
(IPostOperationEnabled
) part
: null;
30 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
31 if (editor
instanceof FormEditor
) {
32 editor
= ((FormEditor
) editor
).getActiveEditor();
34 IEditorInput input
= editor
.getEditorInput();
35 if (input
instanceof TaxonEditorInput
) {
36 Taxon taxon
= ((TaxonEditorInput
) input
).getTaxon();
37 AbstractPostOperation operation
;
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.");