ticket #4575
authorKatja Luther <k.luther@bgbm.org>
Tue, 17 Feb 2015 21:02:47 +0000 (21:02 +0000)
committerKatja Luther <k.luther@bgbm.org>
Tue, 17 Feb 2015 21:02:47 +0000 (21:02 +0000)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/AddImageGalleryHandler.java

index 00ec54f6e42058c573ec5b5d2495545f3c991209..4664282982638f122139ec308f039423d4e558e3 100644 (file)
@@ -15,8 +15,10 @@ import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.handlers.HandlerUtil;
 
 import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.handlers.HandlerUtil;
 
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.model.taxon.TaxonBase;
 import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
 import eu.etaxonomy.taxeditor.bulkeditor.BulkEditorUtil;
 import eu.etaxonomy.taxeditor.bulkeditor.input.OccurrenceEditorInput;
 import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
 import eu.etaxonomy.taxeditor.bulkeditor.BulkEditorUtil;
 import eu.etaxonomy.taxeditor.bulkeditor.input.OccurrenceEditorInput;
@@ -24,8 +26,11 @@ import eu.etaxonomy.taxeditor.editor.EditorUtil;
 import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
 import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
 import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateViewEditorInput;
 import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
 import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
 import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateViewEditorInput;
+import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveViewPart;
 import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.AddDerivedUnitFacadeMediaOperation;
 import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.AddDerivedUnitFacadeMediaOperation;
+import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateSpecimenDescriptionOperation;
 import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateTaxonDescriptionOperation;
 import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateTaxonDescriptionOperation;
+import eu.etaxonomy.taxeditor.editor.view.media.MediaViewPart;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
@@ -73,7 +78,24 @@ public class AddImageGalleryHandler extends AbstractHandler {
                else if(input instanceof DerivateViewEditorInput){
                    ISelection selection = ((DerivateView)editor).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;
        }
 
                return null;
        }