3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.handler
;
12 import org
.eclipse
.core
.commands
.AbstractHandler
;
13 import org
.eclipse
.core
.commands
.ExecutionEvent
;
14 import org
.eclipse
.core
.commands
.ExecutionException
;
15 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
16 import org
.eclipse
.ui
.IEditorInput
;
17 import org
.eclipse
.ui
.IEditorPart
;
18 import org
.eclipse
.ui
.IWorkbenchPart
;
19 import org
.eclipse
.ui
.forms
.editor
.FormEditor
;
20 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
23 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
24 import eu
.etaxonomy
.taxeditor
.editor
.TaxonEditorInput
;
25 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.CreateTaxonDescriptionOperation
;
26 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
27 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
30 * <p>AddDescriptionHandler class.</p>
36 public class CreateDescriptionHandler
extends AbstractHandler
{
39 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
42 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
43 IWorkbenchPart part
= HandlerUtil
.getActivePart(event
);
44 IPostOperationEnabled postOperationEnabled
= (part
instanceof IPostOperationEnabled
) ?
(IPostOperationEnabled
) part
: null;
47 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
48 if (editor
instanceof FormEditor
) {
49 editor
= ((FormEditor
) editor
).getActiveEditor();
51 IEditorInput input
= editor
.getEditorInput();
52 if (input
instanceof TaxonEditorInput
) {
53 Taxon taxon
= ((TaxonEditorInput
) input
).getTaxon();
54 AbstractPostOperation operation
;
57 operation
= createOperationInstance(event
.getCommand().getName(), taxon
, postOperationEnabled
);
58 EditorUtil
.executeOperation(operation
);
59 } catch (NotDefinedException e
) {
60 EditorUtil
.warn(getClass(), "Command name not set.");
66 /**Comments for funtion createOperationInstance
67 * The function is used to make the specific object creation more generic
70 * @param postOperationEnabled
73 protected AbstractPostOperation
createOperationInstance(String eventLabel
, Taxon taxon
, IPostOperationEnabled postOperationEnabled
) {
74 // TODO use undo context specific to editor
75 return new CreateTaxonDescriptionOperation(eventLabel
, EditorUtil
.getUndoContext(), taxon
, postOperationEnabled
);