4 package eu
.etaxonomy
.taxeditor
.editor
.view
.media
.handler
;
6 import org
.eclipse
.core
.commands
.AbstractHandler
;
7 import org
.eclipse
.core
.commands
.ExecutionEvent
;
8 import org
.eclipse
.core
.commands
.ExecutionException
;
9 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
10 import org
.eclipse
.jface
.viewers
.ISelection
;
11 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
12 import org
.eclipse
.jface
.viewers
.TreeNode
;
13 import org
.eclipse
.ui
.IEditorInput
;
14 import org
.eclipse
.ui
.IEditorPart
;
15 import org
.eclipse
.ui
.IWorkbenchPart
;
16 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
18 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
19 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
20 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditor
;
21 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditorUtil
;
22 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.OccurrenceEditorInput
;
23 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
24 import eu
.etaxonomy
.taxeditor
.editor
.TaxonEditorInput
;
25 import eu
.etaxonomy
.taxeditor
.editor
.view
.derivate
.DerivateView
;
26 import eu
.etaxonomy
.taxeditor
.editor
.view
.derivate
.DerivateViewEditorInput
;
27 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.AddDerivedUnitFacadeMediaOperation
;
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>AddImageGalleryHandler class.</p>
40 public class AddImageGalleryHandler
extends AbstractHandler
{
43 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
47 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
49 IWorkbenchPart part
= HandlerUtil
.getActivePart(event
);
50 IPostOperationEnabled postOperationEnabled
= (part
instanceof IPostOperationEnabled
) ?
(IPostOperationEnabled
) part
: null;
53 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
54 IEditorInput input
= editor
.getEditorInput();
56 if (input
instanceof TaxonEditorInput
) {
57 Taxon taxon
= ((TaxonEditorInput
) input
).getTaxon();
58 AbstractPostOperation
<?
> operation
;
60 // TODO use undo context specific to editor
61 operation
= new CreateTaxonDescriptionOperation(event
.getCommand().getName(),
62 EditorUtil
.getUndoContext(), taxon
, postOperationEnabled
, true);
63 AbstractUtility
.executeOperation(operation
);
64 } catch (NotDefinedException e
) {
65 MessagingUtils
.warn(getClass(), "Command name not set.");
68 else if(input
instanceof OccurrenceEditorInput
){
69 BulkEditor bulkEditor
= (BulkEditor
) editor
;
70 ISelection selection
= bulkEditor
.getSelectionProvider().getSelection();
71 invokeOperation(event
, postOperationEnabled
, selection
);
73 else if(input
instanceof DerivateViewEditorInput
){
74 ISelection selection
= ((DerivateView
)editor
).getSelection();
75 invokeOperation(event
, postOperationEnabled
, selection
);
82 * @param postOperationEnabled
85 private void invokeOperation(ExecutionEvent event
, IPostOperationEnabled postOperationEnabled
, ISelection selection
) {
86 if(selection
instanceof IStructuredSelection
){
87 Object element
= ((IStructuredSelection
) selection
).getFirstElement();
88 if(element
instanceof TreeNode
){
89 element
= ((TreeNode
) element
).getValue();
91 if(element
instanceof SpecimenOrObservationBase
<?
>){
93 AbstractPostOperation
<?
> operation
= new AddDerivedUnitFacadeMediaOperation(event
.getCommand().getName(),
94 BulkEditorUtil
.getUndoContext(), (SpecimenOrObservationBase
<?
>)element
, postOperationEnabled
);
95 AbstractUtility
.executeOperation(operation
);
96 } catch (NotDefinedException e
) {
97 MessagingUtils
.warn(getClass(), "Command name not set.");