Open a newly created specimen in specimen editor
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / handler / OpenDerivateViewHandler.java
index 318191f82fa760fed8d2b965fd9bf183f57cb0a0..aff2935620f5a99c002d8eaa4637624e0df2fd02 100644 (file)
@@ -21,41 +21,46 @@ import eu.etaxonomy.taxeditor.model.MessagingUtils;
 
 public class OpenDerivateViewHandler extends AbstractHandler {
 
-    /* (non-Javadoc)
-     * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
-     */
     @Override
     public Object execute(ExecutionEvent event) throws ExecutionException {
-        ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
-        if(currentSelection instanceof IStructuredSelection){
-            Iterator<?> selectionIterator = ((IStructuredSelection) currentSelection).iterator();
-            Set<UUID> selectedElementUUIDs = new HashSet<UUID>();
-            while(selectionIterator.hasNext()){
-                Object object = selectionIterator.next();
-                if(object instanceof SpecimenOrObservationBase<?>){
-                    selectedElementUUIDs.add(((SpecimenOrObservationBase<?>) object).getUuid());
-                }
-                else if(object instanceof IndividualsAssociation){
-                    SpecimenOrObservationBase specimen = ((IndividualsAssociation) object).getAssociatedSpecimenOrObservation();
-                    if(specimen!=null){
-                        selectedElementUUIDs.add(specimen.getUuid());
+        Set<UUID> selectedElementUUIDs = new HashSet<UUID>();
+        //check if parameter is set
+        Object parameter = event.getObjectParameterForExecution("eu.etaxonomy.taxeditor.specimenUuidParameter");
+        if(parameter instanceof UUID){
+            selectedElementUUIDs.add((UUID) parameter);
+        }
+        else{
+            //if not, try with current selection
+            ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
+            if(currentSelection instanceof IStructuredSelection){
+                Iterator<?> selectionIterator = ((IStructuredSelection) currentSelection).iterator();
+                while(selectionIterator.hasNext()){
+                    Object object = selectionIterator.next();
+                    if(object instanceof SpecimenOrObservationBase<?>){
+                        selectedElementUUIDs.add(((SpecimenOrObservationBase<?>) object).getUuid());
+                    }
+                    else if(object instanceof IndividualsAssociation){
+                        SpecimenOrObservationBase specimen = ((IndividualsAssociation) object).getAssociatedSpecimenOrObservation();
+                        if(specimen!=null){
+                            selectedElementUUIDs.add(specimen.getUuid());
+                        }
                     }
                 }
             }
-            if(!selectedElementUUIDs.isEmpty()){
-                DerivateViewEditorInput input = new DerivateViewEditorInput(selectedElementUUIDs);
-                try {
-                    EditorUtil.open(input);
-                } catch (PartInitException e) {
-                    MessagingUtils.error(OpenDerivateViewHandler.class, "Could not open Derivative Editor", e);
-                } catch (NullPointerException npe){
-                    MessagingUtils.messageDialog("Failed to open Editor", OpenDerivateViewHandler.class, "Could not open Derivative Editor. The derivate hierarchy is corrupted!", npe);
-                }
-            }
-            else{
-                MessagingUtils.informationDialog("Empty selection", "No Specimen selected.");
+        }
+        if(!selectedElementUUIDs.isEmpty()){
+            DerivateViewEditorInput input = new DerivateViewEditorInput(selectedElementUUIDs);
+            try {
+                EditorUtil.open(input);
+            } catch (PartInitException e) {
+                MessagingUtils.error(OpenDerivateViewHandler.class, "Could not open Derivative Editor", e);
+            } catch (NullPointerException npe){
+                MessagingUtils.messageDialog("Failed to open Editor", OpenDerivateViewHandler.class, "Could not open Derivative Editor. The derivate hierarchy is corrupted!", npe);
             }
         }
+        else{
+            MessagingUtils.informationDialog("Empty selection", "No Specimen selected.");
+        }
         return null;
     }