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
.hibernate
.HibernateProxyHelper
;
19 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
20 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
22 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditor
;
23 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditorUtil
;
24 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.OccurrenceEditorInput
;
25 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
26 import eu
.etaxonomy
.taxeditor
.editor
.TaxonEditorInput
;
27 import eu
.etaxonomy
.taxeditor
.editor
.view
.derivate
.DerivateView
;
28 import eu
.etaxonomy
.taxeditor
.editor
.view
.derivate
.DerivateViewEditorInput
;
29 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.DescriptiveViewPart
;
30 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.AddDerivedUnitFacadeMediaOperation
;
31 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.CreateSpecimenDescriptionOperation
;
32 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.CreateTaxonDescriptionOperation
;
33 import eu
.etaxonomy
.taxeditor
.editor
.view
.media
.MediaViewPart
;
34 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
35 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
36 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
37 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
40 * <p>AddImageGalleryHandler class.</p>
45 public class AddImageGalleryHandler
extends AbstractHandler
{
48 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
52 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
54 IWorkbenchPart part
= HandlerUtil
.getActivePart(event
);
55 IPostOperationEnabled postOperationEnabled
= (part
instanceof IPostOperationEnabled
) ?
(IPostOperationEnabled
) part
: null;
58 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
59 IEditorInput input
= editor
.getEditorInput();
61 if (input
instanceof TaxonEditorInput
) {
62 Taxon taxon
= ((TaxonEditorInput
) input
).getTaxon();
63 AbstractPostOperation
<?
> operation
;
65 // TODO use undo context specific to editor
66 operation
= new CreateTaxonDescriptionOperation(event
.getCommand().getName(),
67 EditorUtil
.getUndoContext(), taxon
, postOperationEnabled
, true);
68 AbstractUtility
.executeOperation(operation
);
69 } catch (NotDefinedException e
) {
70 MessagingUtils
.warn(getClass(), "Command name not set.");
73 else if(input
instanceof OccurrenceEditorInput
){
74 BulkEditor bulkEditor
= (BulkEditor
) editor
;
75 ISelection selection
= bulkEditor
.getSelectionProvider().getSelection();
76 invokeOperation(event
, postOperationEnabled
, selection
);
78 else if(input
instanceof DerivateViewEditorInput
){
79 ISelection selection
= ((DerivateView
)editor
).getSelection();
80 invokeOperation(event
, postOperationEnabled
, selection
);
81 } else if(part
instanceof MediaViewPart
){
82 Object viewerInput
= ((MediaViewPart
)part
).getViewer().getInput();
84 if(viewerInput
instanceof Taxon
){
85 Taxon taxon
= HibernateProxyHelper
.deproxy(viewerInput
, Taxon
.class);
86 AbstractPostOperation
<?
> operation
;
88 // TODO use undo context specific to editor
89 operation
= new CreateTaxonDescriptionOperation(event
.getCommand().getName(),
90 EditorUtil
.getUndoContext(), taxon
, postOperationEnabled
, true);
91 AbstractUtility
.executeOperation(operation
);
92 } catch (NotDefinedException e
) {
93 MessagingUtils
.warn(getClass(), "Command name not set.");
104 * @param postOperationEnabled
107 private void invokeOperation(ExecutionEvent event
, IPostOperationEnabled postOperationEnabled
, ISelection selection
) {
108 if(selection
instanceof IStructuredSelection
){
109 Object element
= ((IStructuredSelection
) selection
).getFirstElement();
110 if(element
instanceof TreeNode
){
111 element
= ((TreeNode
) element
).getValue();
113 if(element
instanceof SpecimenOrObservationBase
<?
>){
115 AbstractPostOperation
<?
> operation
= new AddDerivedUnitFacadeMediaOperation(event
.getCommand().getName(),
116 BulkEditorUtil
.getUndoContext(), (SpecimenOrObservationBase
<?
>)element
, postOperationEnabled
);
117 AbstractUtility
.executeOperation(operation
);
118 } catch (NotDefinedException e
) {
119 MessagingUtils
.warn(getClass(), "Command name not set.");