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
.ui
.IWorkbenchPart
;
11 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
13 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
14 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
15 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
16 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
17 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditorUtil
;
18 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
19 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.AddDerivedUnitFacadeMediaOperation
;
20 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.CreateTaxonDescriptionOperation
;
21 import eu
.etaxonomy
.taxeditor
.editor
.view
.media
.MediaViewPart
;
22 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
23 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
24 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
25 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
31 public class AddImageGalleryHandler
extends AbstractHandler
{
35 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
37 IWorkbenchPart part
= HandlerUtil
.getActivePart(event
);
38 IPostOperationEnabled postOperationEnabled
= (part
instanceof IPostOperationEnabled
) ?
(IPostOperationEnabled
) part
: null;
40 if(part
instanceof MediaViewPart
){
41 Object viewerInput
= ((MediaViewPart
)part
).getViewer().getInput();
43 if(viewerInput
instanceof CdmBase
){
44 if(((CdmBase
) viewerInput
).isInstanceOf(Taxon
.class)){
45 Taxon taxon
= HibernateProxyHelper
.deproxy(viewerInput
, Taxon
.class);
47 AbstractPostOperation
<?
> operation
= new CreateTaxonDescriptionOperation(event
.getCommand().getName(),
48 EditorUtil
.getUndoContext(), taxon
, postOperationEnabled
, true);
50 AbstractUtility
.executeOperation(operation
);
52 else if(((CdmBase
) viewerInput
).isInstanceOf(SpecimenOrObservationBase
.class)){
53 SpecimenOrObservationBase
<?
> specimen
= HibernateProxyHelper
.deproxy(viewerInput
, SpecimenOrObservationBase
.class);
55 AbstractPostOperation
<?
> operation
= new AddDerivedUnitFacadeMediaOperation(event
.getCommand().getName(),
56 BulkEditorUtil
.getUndoContext(), specimen
, postOperationEnabled
);
58 AbstractUtility
.executeOperation(operation
);
61 } catch (NotDefinedException e
) {
62 MessagingUtils
.warn(getClass(), "Command name not set.");