Add "Open in..." to taxon search #5616
authorPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 5 Apr 2016 14:37:25 +0000 (16:37 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 5 Apr 2016 14:37:25 +0000 (16:37 +0200)
eu.etaxonomy.taxeditor.navigation/plugin.xml
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/search/SearchResultView.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerContextMenu.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerUtil.java

index bb55990..c01bb7a 100644 (file)
       </menuContribution>
       <menuContribution
             locationURI="popup:eu.etaxonomy.taxeditor.navigation.search.searchResultView">
-         <command
-               commandId="eu.etaxonomy.taxeditor.navigation.command.editTaxon"
-               label="%command.label.1"
-               style="push">
-         </command>
+         <dynamic
+               class="eu.etaxonomy.taxeditor.view.CdmViewerContextMenu"
+               id="eu.etaxonomy.taxeditor.navigation.cdmViewerContextMenu">
+         </dynamic>
+         <separator
+               name="eu.etaxonomy.taxeditor.navigation.separator2">
+         </separator>
       </menuContribution>
       <menuContribution
             locationURI="popup:eu.etaxonomy.taxeditor.navigation.navigatorpopup">
index 8651303..45925d8 100644 (file)
@@ -38,12 +38,8 @@ import org.eclipse.ui.part.ViewPart;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
-import eu.etaxonomy.cdm.api.service.ITaxonService;
 import eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator;
 import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
-import eu.etaxonomy.cdm.model.taxon.Synonym;
-import eu.etaxonomy.cdm.model.taxon.Taxon;
-import eu.etaxonomy.cdm.model.taxon.TaxonBase;
 import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
 import eu.etaxonomy.cdm.persistence.query.MatchMode;
@@ -123,14 +119,8 @@ public class SearchResultView extends ViewPart implements IConversationEnabled{
             public void doubleClick(DoubleClickEvent event) {
                            if(event.getSelection() instanceof IStructuredSelection){
                                Object selectedObject = ((IStructuredSelection) event.getSelection()).getFirstElement();
-                               if (selectedObject instanceof UuidAndTitleCache){
-                                   Class type = ((UuidAndTitleCache) selectedObject).getType();
-                                   if(type == Taxon.class || type == Synonym.class){
-                                       TaxonBase taxonBase = CdmStore.getService(ITaxonService.class).load(((UuidAndTitleCache) selectedObject).getUuid());
-                                       CdmViewerChooser chooser = new CdmViewerChooser(getSite().getShell());
-                                       chooser.chooseViewer(taxonBase);
-                                   }
-                               }
+                               CdmViewerChooser chooser = new CdmViewerChooser(getSite().getShell());
+                               chooser.chooseViewer(selectedObject);
                            }
                        }
                });
index bfe10e7..1359195 100644 (file)
@@ -22,9 +22,16 @@ import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.actions.CompoundContributionItem;
 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.Messages;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
  * Generic context menu for opening elements in the taxeditor.
@@ -78,7 +85,7 @@ public class CdmViewerContextMenu extends CompoundContributionItem {
 
     private final class CommandInvoker extends SelectionAdapter {
         private final Command command;
-        private final Object selectedObject;
+        private Object selectedObject;
 
         private CommandInvoker(Command command, Object selectedObject) {
             this.command = command;
@@ -89,6 +96,17 @@ public class CdmViewerContextMenu extends CompoundContributionItem {
         public void widgetSelected(SelectionEvent e) {
             IHandlerService handlerService = (IHandlerService)PlatformUI.getWorkbench().getService(IHandlerService.class);
             Map<String, UUID> params = new HashMap<String, UUID>();
+            //for generic UuidAndTitleCache objects try to load the object
+            if (selectedObject instanceof UuidAndTitleCache){
+                UuidAndTitleCache uuidAndTitleCache = (UuidAndTitleCache)selectedObject;
+                Class type = uuidAndTitleCache.getType();
+                if(type == Taxon.class || type == Synonym.class){
+                    selectedObject = CdmStore.getService(ITaxonService.class).load(uuidAndTitleCache.getUuid());
+                }
+                else if(SpecimenOrObservationBase.class.isAssignableFrom(type)){
+                    selectedObject = CdmStore.getService(IOccurrenceService.class).load(uuidAndTitleCache.getUuid());
+                }
+            }
             if(selectedObject instanceof ICdmBase){
                 params.put(command.getId()+".uuid", ((ICdmBase) selectedObject).getUuid()); //$NON-NLS-1$
             }
index 8113b97..698f942 100644 (file)
@@ -19,7 +19,14 @@ import org.eclipse.core.runtime.Platform;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.commands.ICommandService;
 
+import eu.etaxonomy.cdm.api.service.IOccurrenceService;
+import eu.etaxonomy.cdm.api.service.ITaxonService;
+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;
 
 /**
  * Scans eu.etaxonomy.taxeditor.store.cdmViewer extension point.
@@ -42,6 +49,19 @@ public class CdmViewerUtil {
         Map<Command, String> commandViewerNameMap = new HashMap<Command, String>();
 
         if(input!=null){
+            //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());
+                }
+            }
+
+
             IExtensionRegistry reg = Platform.getExtensionRegistry();
             IConfigurationElement[] extensions = reg
                     .getConfigurationElementsFor("eu.etaxonomy.taxeditor.store.cdmViewer"); //$NON-NLS-1$