Open a newly created specimen in specimen editor
authorPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 14 Sep 2015 14:28:12 +0000 (16:28 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 15 Sep 2015 08:54:23 +0000 (10:54 +0200)
eu.etaxonomy.taxeditor.editor/plugin.xml
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/OpenDerivateViewHandler.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/UuidParameterConverter.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/newWizard/NewDerivedUnitBaseWizard.java

index 66def47309837982fcbfaea4fa1efb79fc917fc0..e681c8a01c067e1dcd1bb9b244eeff7ea0d275e2 100644 (file)
             id="eu.etaxonomy.taxeditor.editor.view.descriptive.command.moveDescriptionElements"
             name="%command.name.12">
       </command>
             id="eu.etaxonomy.taxeditor.editor.view.descriptive.command.moveDescriptionElements"
             name="%command.name.12">
       </command>
+      <command
+            defaultHandler="eu.etaxonomy.taxeditor.editor.handler.OpenDerivateViewHandler"
+            id="eu.etaxonomy.taxeditor.editor.openSpecimenEditor"
+            name="Open Specimen Editor">
+         <commandParameter
+               id="eu.etaxonomy.taxeditor.specimenUuidParameter"
+               name="Specimen UUID parameter"
+               optional="true"
+               typeId="eu.etaxonomy.taxeditor.specimenUuidParameterType">
+         </commandParameter>
+      </command>
         
    </extension>
         
    </extension>
+   <extension
+         point="org.eclipse.ui.commands">
+      <commandParameterType
+            converter="eu.etaxonomy.taxeditor.handler.UuidParameterConverter"
+            id="eu.etaxonomy.taxeditor.specimenUuidParameterType"
+            type="java.util.UUID">
+      </commandParameterType>
+   </extension>
    <extension
          point="org.eclipse.core.expressions.definitions">
       <definition
    <extension
          point="org.eclipse.core.expressions.definitions">
       <definition
index 318191f82fa760fed8d2b965fd9bf183f57cb0a0..aff2935620f5a99c002d8eaa4637624e0df2fd02 100644 (file)
@@ -21,41 +21,46 @@ import eu.etaxonomy.taxeditor.model.MessagingUtils;
 
 public class OpenDerivateViewHandler extends AbstractHandler {
 
 
 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 {
     @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;
     }
 
         return null;
     }
 
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/UuidParameterConverter.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/UuidParameterConverter.java
new file mode 100644 (file)
index 0000000..5bd3db1
--- /dev/null
@@ -0,0 +1,24 @@
+package eu.etaxonomy.taxeditor.handler;
+
+import java.util.UUID;
+
+import org.eclipse.core.commands.AbstractParameterValueConverter;
+import org.eclipse.core.commands.ParameterValueConversionException;
+
+public class UuidParameterConverter extends AbstractParameterValueConverter {
+
+    public UuidParameterConverter() {
+        // TODO Auto-generated constructor stub
+    }
+
+    @Override
+    public Object convertToObject(String parameterValue) throws ParameterValueConversionException {
+        return UUID.fromString(parameterValue);
+    }
+
+    @Override
+    public String convertToString(Object parameterValue) throws ParameterValueConversionException {
+        return parameterValue.toString();
+    }
+
+}
index 3b9036faf261b9b7eb15a43d959ec1c6c6b4dae7..c4215fd34cf05ea40f0c8b96e0d8b40d9446e0a4 100644 (file)
 
 package eu.etaxonomy.taxeditor.newWizard;
 
 
 package eu.etaxonomy.taxeditor.newWizard;
 
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import org.eclipse.core.commands.Command;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.NotEnabledException;
+import org.eclipse.core.commands.NotHandledException;
+import org.eclipse.core.commands.ParameterizedCommand;
+import org.eclipse.core.commands.common.NotDefinedException;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.handlers.IHandlerService;
+
 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException;
 import eu.etaxonomy.cdm.api.service.IOccurrenceService;
 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException;
 import eu.etaxonomy.cdm.api.service.IOccurrenceService;
@@ -19,7 +34,9 @@ import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
 import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
 import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.IDerivedUnitFacadePart;
 import eu.etaxonomy.taxeditor.model.IDerivedUnitFacadePart;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.ui.section.occurrence.DerivedUnitBaseWizardPage;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.ui.section.occurrence.DerivedUnitBaseWizardPage;
@@ -27,6 +44,7 @@ import eu.etaxonomy.taxeditor.ui.section.occurrence.DerivedUnitGeneralWizardPage
 import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldUnitGeneralWizardPage;
 import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldUnitWizardPage;
 import eu.etaxonomy.taxeditor.ui.section.occurrence.GatheringEventWizardPage;
 import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldUnitGeneralWizardPage;
 import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldUnitWizardPage;
 import eu.etaxonomy.taxeditor.ui.section.occurrence.GatheringEventWizardPage;
+import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateSearchCompositeController;
 
 /**
  * @author n.hoffmann
 
 /**
  * @author n.hoffmann
@@ -99,5 +117,38 @@ public class NewDerivedUnitBaseWizard extends AbstractNewEntityWizard<SpecimenOr
                return "Specimen";
        }
 
                return "Specimen";
        }
 
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public boolean performFinish() {
+           boolean performFinish = super.performFinish();
+
+        IHandlerService handlerService = (IHandlerService) AbstractUtility.getService(IHandlerService.class);
+
+        //get the command from plugin.xml
+        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+        ICommandService cmdService = (ICommandService)window.getService(ICommandService.class);
+        Command command = cmdService.getCommand("eu.etaxonomy.taxeditor.editor.openSpecimenEditor");
+        Map<String, UUID> parameters = new HashMap<String, UUID>();
+        parameters.put("eu.etaxonomy.taxeditor.specimenUuidParameter", getEntity().getUuid());
+        ParameterizedCommand parameterizedCommand = ParameterizedCommand.generateCommand(command, parameters);
+
+        //execute the command
+        try {
+            handlerService.executeCommand(parameterizedCommand, null);
+        } catch (ExecutionException e) {
+            MessagingUtils.error(DerivateSearchCompositeController.class, e);
+        } catch (NotDefinedException e) {
+            MessagingUtils.error(DerivateSearchCompositeController.class, e);
+        } catch (NotEnabledException e) {
+            MessagingUtils.error(DerivateSearchCompositeController.class, e);
+        } catch (NotHandledException e) {
+            MessagingUtils.error(DerivateSearchCompositeController.class, e);
+        }
+
+        return performFinish;
+       }
+
 
 }
 
 }