2 * Copyright (C) 2011 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.handler
;
11 import org
.eclipse
.core
.commands
.AbstractHandler
;
12 import org
.eclipse
.core
.commands
.ExecutionEvent
;
13 import org
.eclipse
.core
.commands
.ExecutionException
;
14 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
15 import org
.eclipse
.core
.expressions
.EvaluationContext
;
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
.cdm
.model
.taxon
.TaxonBase
;
25 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
26 import eu
.etaxonomy
.taxeditor
.editor
.TaxonEditorInput
;
27 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.DescriptiveViewPart
;
28 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.CreateSpecimenDescriptionOperation
;
29 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.CreateTaxonDescriptionOperation
;
30 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
31 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
32 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
33 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
36 * <p>AddDescriptionHandler class.</p>
42 public class CreateDescriptionHandler
extends AbstractHandler
{
45 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
49 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
50 IWorkbenchPart part
= HandlerUtil
.getActivePart(event
);
51 IPostOperationEnabled postOperationEnabled
= (part
instanceof IPostOperationEnabled
) ?
(IPostOperationEnabled
) part
: null;
53 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
54 if (editor
instanceof FormEditor
) {
55 editor
= ((FormEditor
) editor
).getActiveEditor();
57 IEditorInput input
= editor
.getEditorInput();
58 AbstractPostOperation
<?
> operation
;
61 if (input
instanceof TaxonEditorInput
) {
62 Taxon taxon
= ((TaxonEditorInput
) input
).getTaxon();
64 operation
= createTaxonOperation(event
.getCommand().getName(), taxon
, postOperationEnabled
);
65 AbstractUtility
.executeOperation(operation
);
66 } catch (NotDefinedException e
) {
67 MessagingUtils
.warn(getClass(), "Command name not set."); //$NON-NLS-1$
70 // specimen description
71 else if(part
instanceof DescriptiveViewPart
){
72 Object viewerInput
= ((DescriptiveViewPart
)part
).getViewer().getInput();
73 if(viewerInput
instanceof SpecimenOrObservationBase
<?
>){
75 operation
= new CreateSpecimenDescriptionOperation(event
.getCommand().getName(), EditorUtil
.getUndoContext(), (SpecimenOrObservationBase
<?
>) viewerInput
, postOperationEnabled
);
76 AbstractUtility
.executeOperation(operation
);
77 } catch (NotDefinedException e
) {
78 MessagingUtils
.warn(getClass(), "Command name not set."); //$NON-NLS-1$
81 if(viewerInput
instanceof TaxonBase
){
83 operation
= createTaxonOperation(event
.getCommand().getName(), (Taxon
) viewerInput
, postOperationEnabled
);
84 AbstractUtility
.executeOperation(operation
);
85 } catch (NotDefinedException e
) {
86 MessagingUtils
.warn(getClass(), "Command name not set."); //$NON-NLS-1$
95 protected CreateTaxonDescriptionOperation
createTaxonOperation(String eventLabel
, Taxon taxon
, IPostOperationEnabled postOperationEnabled
) {
96 return new CreateTaxonDescriptionOperation(eventLabel
, EditorUtil
.getUndoContext(), taxon
, postOperationEnabled
);