Correctly handle UuidAndTitleCache objects in "Open in..." menu
authorPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 5 Apr 2016 15:01:46 +0000 (17:01 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 12 Apr 2016 09:10:36 +0000 (11:10 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerChooser.java

index 6301707..3d14e03 100644 (file)
@@ -34,8 +34,15 @@ import org.eclipse.swt.widgets.Table;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.handlers.IHandlerService;
 
+import eu.etaxonomy.cdm.api.service.IOccurrenceService;
+import eu.etaxonomy.cdm.api.service.ITaxonService;
 import eu.etaxonomy.cdm.model.common.ICdmBase;
+import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
+import eu.etaxonomy.cdm.model.taxon.Synonym;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
  * This class opens a popup dialog and provides the possibility to choose from a
@@ -84,6 +91,17 @@ public class CdmViewerChooser extends PopupDialog implements ISelectionChangedLi
     }
 
     private void executeCommand(Command command, Object input) {
+        //for generic UuidAndTitleCache objects try to load the object
+        if (input instanceof UuidAndTitleCache){
+            UuidAndTitleCache uuidAndTitleCache = (UuidAndTitleCache)input;
+            Class type = uuidAndTitleCache.getType();
+            if(type == Taxon.class || type == Synonym.class){
+               input = CdmStore.getService(ITaxonService.class).load(uuidAndTitleCache.getUuid());
+            }
+            else if(SpecimenOrObservationBase.class.isAssignableFrom(type)){
+               input = CdmStore.getService(IOccurrenceService.class).load(uuidAndTitleCache.getUuid());
+            }
+        }
         //set uuid parameter
         if(input instanceof ICdmBase){
             Map<String, UUID> params = new HashMap<String, UUID>();