From: Patrick Plitzner
AddImageGalleryHandler class.
- * * @author p.ciardelli * @version $Id: $ */ public class AddImageGalleryHandler extends AbstractHandler { - /* (non-Javadoc) - * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) - */ /** {@inheritDoc} */ @Override public Object execute(ExecutionEvent event) throws ExecutionException { - IWorkbenchPart part = HandlerUtil.getActivePart(event); - IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null; + IWorkbenchPart part = HandlerUtil.getActivePart(event); + IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null; + if(part instanceof MediaViewPart){ + Object viewerInput = ((MediaViewPart)part).getViewer().getInput(); + try { + if(viewerInput instanceof CdmBase){ + if(((CdmBase) viewerInput).isInstanceOf(Taxon.class)){ + Taxon taxon = HibernateProxyHelper.deproxy(viewerInput, Taxon.class); - IEditorPart editor = HandlerUtil.getActiveEditor(event); - IEditorInput input = editor.getEditorInput(); + AbstractPostOperation> operation = new CreateTaxonDescriptionOperation(event.getCommand().getName(), + EditorUtil.getUndoContext(), taxon, postOperationEnabled, true); - if (input instanceof TaxonEditorInput) { - Taxon taxon = ((TaxonEditorInput) input).getTaxon(); - AbstractPostOperation> operation; - try { - // TODO use undo context specific to editor - operation = new CreateTaxonDescriptionOperation(event.getCommand().getName(), - EditorUtil.getUndoContext(), taxon, postOperationEnabled, true); - AbstractUtility.executeOperation(operation); - } catch (NotDefinedException e) { - MessagingUtils.warn(getClass(), "Command name not set."); - } - } - else if(input instanceof OccurrenceEditorInput){ - BulkEditor bulkEditor = (BulkEditor) editor; - ISelection selection = bulkEditor.getSelectionProvider().getSelection(); - invokeOperation(event, postOperationEnabled, selection); - } - else if(input instanceof DerivateViewEditorInput){ - ISelection selection = ((DerivateView)editor).getSelection(); - invokeOperation(event, postOperationEnabled, selection); - } else if(part instanceof MediaViewPart){ - Object viewerInput = ((MediaViewPart)part).getViewer().getInput(); - - if(viewerInput instanceof Taxon){ - Taxon taxon = HibernateProxyHelper.deproxy(viewerInput, Taxon.class); - AbstractPostOperation> operation; - try { - // TODO use undo context specific to editor - operation = new CreateTaxonDescriptionOperation(event.getCommand().getName(), - EditorUtil.getUndoContext(), taxon, postOperationEnabled, true); - AbstractUtility.executeOperation(operation); - } catch (NotDefinedException e) { - MessagingUtils.warn(getClass(), "Command name not set."); - } - - } - } - - return null; - } + AbstractUtility.executeOperation(operation); + } + else if(((CdmBase) viewerInput).isInstanceOf(SpecimenOrObservationBase.class)){ + SpecimenOrObservationBase> specimen = HibernateProxyHelper.deproxy(viewerInput, SpecimenOrObservationBase.class); - /** - * @param event - * @param postOperationEnabled - * @param selection - */ - private void invokeOperation(ExecutionEvent event, IPostOperationEnabled postOperationEnabled, ISelection selection) { - if(selection instanceof IStructuredSelection){ - Object element = ((IStructuredSelection) selection).getFirstElement(); - if(element instanceof TreeNode){ - element = ((TreeNode) element).getValue(); - } - if(element instanceof SpecimenOrObservationBase>){ - try { - AbstractPostOperation> operation = new AddDerivedUnitFacadeMediaOperation(event.getCommand().getName(), - BulkEditorUtil.getUndoContext(), (SpecimenOrObservationBase>)element, postOperationEnabled); - AbstractUtility.executeOperation(operation); - } catch (NotDefinedException e) { - MessagingUtils.warn(getClass(), "Command name not set."); - } - } - } - } + AbstractPostOperation> operation = new AddDerivedUnitFacadeMediaOperation(event.getCommand().getName(), + BulkEditorUtil.getUndoContext(), specimen, postOperationEnabled); + + AbstractUtility.executeOperation(operation); + } + } + } catch (NotDefinedException e) { + MessagingUtils.warn(getClass(), "Command name not set."); + } + } + return null; + } -} +} \ No newline at end of file