3 * Copyright (C) 2011 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
.checklist
.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
.occurrence
.SpecimenOrObservationBase
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
24 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
25 import eu
.etaxonomy
.taxeditor
.editor
.TaxonEditorInput
;
26 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.DescriptiveViewPart
;
27 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.CreateSpecimenDescriptionOperation
;
28 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.CreateTaxonDescriptionOperation
;
29 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
30 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
31 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
32 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
35 * <p>AddDescriptionHandler class.</p>
41 public class CreateDescriptionHandler
extends AbstractHandler
{
44 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
48 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
49 IWorkbenchPart part
= HandlerUtil
.getActivePart(event
);
50 IPostOperationEnabled postOperationEnabled
= (part
instanceof IPostOperationEnabled
) ?
(IPostOperationEnabled
) part
: null;
52 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
53 if (editor
instanceof FormEditor
) {
54 editor
= ((FormEditor
) editor
).getActiveEditor();
56 IEditorInput input
= editor
.getEditorInput();
57 AbstractPostOperation
<?
> operation
;
60 if (input
instanceof TaxonEditorInput
) {
61 Taxon taxon
= ((TaxonEditorInput
) input
).getTaxon();
63 operation
= createTaxonOperation(event
.getCommand().getName(), taxon
, postOperationEnabled
);
64 AbstractUtility
.executeOperation(operation
);
65 } catch (NotDefinedException e
) {
66 MessagingUtils
.warn(getClass(), "Command name not set.");
69 // specimen description
70 else if(part
instanceof DescriptiveViewPart
){
71 Object viewerInput
= ((DescriptiveViewPart
)part
).getViewer().getInput();
72 if(viewerInput
instanceof SpecimenOrObservationBase
<?
>){
74 operation
= new CreateSpecimenDescriptionOperation(event
.getCommand().getName(), EditorUtil
.getUndoContext(), (SpecimenOrObservationBase
<?
>) viewerInput
, postOperationEnabled
);
75 AbstractUtility
.executeOperation(operation
);
76 } catch (NotDefinedException e
) {
77 MessagingUtils
.warn(getClass(), "Command name not set.");
85 protected CreateTaxonDescriptionOperation
createTaxonOperation(String eventLabel
, Taxon taxon
, IPostOperationEnabled postOperationEnabled
) {
86 return new CreateTaxonDescriptionOperation(eventLabel
, EditorUtil
.getUndoContext(), taxon
, postOperationEnabled
);