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 java
.util
.Collection
;
13 import org
.eclipse
.core
.commands
.AbstractHandler
;
14 import org
.eclipse
.core
.commands
.ExecutionEvent
;
15 import org
.eclipse
.core
.commands
.ExecutionException
;
16 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
17 import org
.eclipse
.core
.expressions
.EvaluationContext
;
18 import org
.eclipse
.ui
.IEditorInput
;
19 import org
.eclipse
.ui
.IEditorPart
;
20 import org
.eclipse
.ui
.IWorkbenchPart
;
21 import org
.eclipse
.ui
.forms
.editor
.FormEditor
;
22 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
24 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
27 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
28 import eu
.etaxonomy
.taxeditor
.editor
.TaxonEditorInput
;
29 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.DescriptiveViewPart
;
30 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.CreateSpecimenDescriptionOperation
;
31 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.CreateTaxonDescriptionOperation
;
32 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
33 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
34 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
35 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
38 * <p>AddDescriptionHandler class.</p>
44 public class CreateDescriptionHandler
extends AbstractHandler
{
47 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
51 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
52 IWorkbenchPart part
= HandlerUtil
.getActivePart(event
);
53 IPostOperationEnabled postOperationEnabled
= (part
instanceof IPostOperationEnabled
) ?
(IPostOperationEnabled
) part
: null;
55 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
57 if (editor
instanceof FormEditor
) {
58 editor
= ((FormEditor
) editor
).getActiveEditor();
61 if (editor
== null && part
instanceof DescriptiveViewPart
){
62 input
= ((DescriptiveViewPart
)part
).getViewer().getInput();
64 input
= editor
.getEditorInput();
66 AbstractPostOperation
<?
> operation
;
69 if (input
instanceof TaxonEditorInput
) {
70 Taxon taxon
= ((TaxonEditorInput
) input
).getTaxon();
72 operation
= createTaxonOperation(event
.getCommand().getName(), taxon
, postOperationEnabled
);
73 AbstractUtility
.executeOperation(operation
);
74 } catch (NotDefinedException e
) {
75 MessagingUtils
.warn(getClass(), "Command name not set."); //$NON-NLS-1$
78 // specimen description
79 else if(part
instanceof DescriptiveViewPart
){
80 Object viewerInput
= ((DescriptiveViewPart
)part
).getViewer().getInput();
81 if(viewerInput
instanceof SpecimenOrObservationBase
<?
>){
83 operation
= new CreateSpecimenDescriptionOperation(event
.getCommand().getName(), EditorUtil
.getUndoContext(), (SpecimenOrObservationBase
<?
>) viewerInput
, postOperationEnabled
);
84 AbstractUtility
.executeOperation(operation
);
85 } catch (NotDefinedException e
) {
86 MessagingUtils
.warn(getClass(), "Command name not set."); //$NON-NLS-1$
89 if(viewerInput
instanceof TaxonBase
){
91 operation
= createTaxonOperation(event
.getCommand().getName(), (Taxon
) viewerInput
, postOperationEnabled
);
92 AbstractUtility
.executeOperation(operation
);
93 } catch (NotDefinedException e
) {
94 MessagingUtils
.warn(getClass(), "Command name not set."); //$NON-NLS-1$
103 protected CreateTaxonDescriptionOperation
createTaxonOperation(String eventLabel
, Taxon taxon
, IPostOperationEnabled postOperationEnabled
) {
104 return new CreateTaxonDescriptionOperation(eventLabel
, EditorUtil
.getUndoContext(), taxon
, postOperationEnabled
);