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
.ui
.IEditorInput
;
13 import org
.eclipse
.ui
.IEditorPart
;
14 import org
.eclipse
.ui
.IWorkbenchPart
;
15 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
17 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
18 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
19 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditor
;
20 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditorUtil
;
21 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.OccurrenceEditorInput
;
22 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
23 import eu
.etaxonomy
.taxeditor
.editor
.TaxonEditorInput
;
24 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.AddDerivedUnitFacadeMediaOperation
;
25 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.CreateTaxonDescriptionOperation
;
26 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
27 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
28 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
29 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
32 * <p>AddImageGalleryHandler class.</p>
37 public class AddImageGalleryHandler
extends AbstractHandler
{
40 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
44 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
46 IWorkbenchPart part
= HandlerUtil
.getActivePart(event
);
47 IPostOperationEnabled postOperationEnabled
= (part
instanceof IPostOperationEnabled
) ?
(IPostOperationEnabled
) part
: null;
50 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
51 IEditorInput input
= editor
.getEditorInput();
53 if (input
instanceof TaxonEditorInput
) {
54 Taxon taxon
= ((TaxonEditorInput
) input
).getTaxon();
55 AbstractPostOperation
<?
> operation
;
57 // TODO use undo context specific to editor
58 operation
= new CreateTaxonDescriptionOperation(event
.getCommand().getName(),
59 EditorUtil
.getUndoContext(), taxon
, postOperationEnabled
, true);
60 AbstractUtility
.executeOperation(operation
);
61 } catch (NotDefinedException e
) {
62 MessagingUtils
.warn(getClass(), "Command name not set.");
65 else if(input
instanceof OccurrenceEditorInput
){
66 BulkEditor bulkEditor
= (BulkEditor
) editor
;
67 ISelection selection
= bulkEditor
.getSelectionProvider().getSelection();
69 if(selection
instanceof IStructuredSelection
){
70 Object element
= ((IStructuredSelection
) selection
).getFirstElement();
71 if(element
instanceof SpecimenOrObservationBase
<?
>){
73 AbstractPostOperation
<?
> operation
= new AddDerivedUnitFacadeMediaOperation(event
.getCommand().getName(),
74 BulkEditorUtil
.getUndoContext(), (SpecimenOrObservationBase
<?
>)element
, postOperationEnabled
);
75 AbstractUtility
.executeOperation(operation
);
76 } catch (NotDefinedException e
) {
77 MessagingUtils
.warn(getClass(), "Command name not set.");