Fix double click on taxa in taxon navigator and search results
authorPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 13 Jan 2016 13:30:32 +0000 (14:30 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 13 Jan 2016 13:30:32 +0000 (14:30 +0100)
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationUtil.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigator.java
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/CdmViewerUtil.java

index 613dbab..8c36e2a 100644 (file)
@@ -12,10 +12,6 @@ package eu.etaxonomy.taxeditor.navigation;
 import java.util.Set;
 import java.util.UUID;
 
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.NotEnabledException;
-import org.eclipse.core.commands.NotHandledException;
-import org.eclipse.core.commands.common.NotDefinedException;
 import org.eclipse.core.commands.operations.IUndoContext;
 import org.eclipse.core.commands.operations.UndoContext;
 import org.eclipse.jface.viewers.StructuredSelection;
@@ -25,7 +21,6 @@ import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.IEditorReference;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.handlers.IHandlerService;
 import org.eclipse.ui.navigator.CommonViewer;
 
 import eu.etaxonomy.cdm.model.common.ICdmBase;
@@ -55,27 +50,6 @@ public class NavigationUtil extends AbstractUtility{
        private static IUndoContext defaultUndoContext;
 
        /**
-        * <p>executeEditHandler</p>
-        */
-       public static void executeEditHandler(){
-
-               String commandId = "eu.etaxonomy.taxeditor.navigation.command.update.editSelection";
-
-               IHandlerService handlerService = (IHandlerService) AbstractUtility.getService(IHandlerService.class);
-               try {
-                       handlerService.executeCommand(commandId, null);
-               } catch (ExecutionException e) {
-                       MessagingUtils.error(NavigationUtil.class, e);
-               } catch (NotDefinedException e) {
-                       MessagingUtils.error(NavigationUtil.class, e);
-               } catch (NotEnabledException e) {
-                       MessagingUtils.error(NavigationUtil.class, e);
-               } catch (NotHandledException e) {
-                       MessagingUtils.error(NavigationUtil.class, e);
-               }
-       }
-
-       /**
         * <p>openEditor</p>
         *
         * @param selectedObject a {@link eu.etaxonomy.cdm.model.common.CdmBase} object.
index c2d28d3..fe13ff0 100644 (file)
@@ -25,6 +25,7 @@ import java.util.UUID;
 import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.TreePath;
 import org.eclipse.ui.IMemento;
 import org.eclipse.ui.IViewSite;
@@ -54,6 +55,7 @@ import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
 import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.store.LoginManager;
+import eu.etaxonomy.taxeditor.view.CdmViewerChooser;
 
 /**
  * Taxonomic tree implementation using Common Navigator Framework.
@@ -449,8 +451,12 @@ public class TaxonNavigator extends CommonNavigator implements
 
        /** {@inheritDoc} */
        @Override
-       protected void handleDoubleClick(DoubleClickEvent anEvent) {
-               NavigationUtil.executeEditHandler();
+       protected void handleDoubleClick(DoubleClickEvent event) {
+        if(event.getSelection() instanceof IStructuredSelection){
+            Object selectedObject = ((IStructuredSelection) event.getSelection()).getFirstElement();
+            CdmViewerChooser chooser = new CdmViewerChooser(getSite().getShell());
+            chooser.chooseViewer(selectedObject);
+        }
                // If the double click is passed up to the super-class it will
                // expand/collapse trees.
                // We do not want that
index 74fdee6..8651303 100644 (file)
@@ -21,6 +21,7 @@ import org.eclipse.jface.action.MenuManager;
 import org.eclipse.jface.viewers.ArrayContentProvider;
 import org.eclipse.jface.viewers.DoubleClickEvent;
 import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.TableViewer;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.layout.GridData;
@@ -37,17 +38,21 @@ 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;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.ContextListenerAdapter;
 import eu.etaxonomy.taxeditor.model.IContextListener;
-import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
 import eu.etaxonomy.taxeditor.navigation.search.SearchBar.SearchOption;
 import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.view.CdmViewerChooser;
 
 /**
  * <p>SearchResultView class.</p>
@@ -116,7 +121,17 @@ public class SearchResultView extends ViewPart implements IConversationEnabled{
                resultViewer.addDoubleClickListener(new IDoubleClickListener() {
                        @Override
             public void doubleClick(DoubleClickEvent event) {
-                               NavigationUtil.executeEditHandler();
+                           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);
+                                   }
+                               }
+                           }
                        }
                });
 
index af8b60f..4436ced 100644 (file)
@@ -12,9 +12,12 @@ package eu.etaxonomy.taxeditor.view;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.eclipse.core.commands.Command;
 import org.eclipse.core.runtime.IConfigurationElement;
 import org.eclipse.core.runtime.IExtensionRegistry;
 import org.eclipse.core.runtime.Platform;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.commands.ICommandService;
 
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 
@@ -49,7 +52,12 @@ public class CdmViewerUtil {
                         String viewerName = configElement.getAttribute("viewerName"); //$NON-NLS-1$
                         Class<?> selectionClass = Class.forName(configElement.getAttribute("selection")); //$NON-NLS-1$
                         if(selectionClass.isAssignableFrom(input.getClass())){
-                            commandViewerNameMap.put(commandId, viewerName);
+                            ICommandService commandService = (ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class);
+                            Command command = commandService.getCommand(commandId);
+                            //TODO: maybe pass the command directly instead of just the command id
+                            if(command.isEnabled()){
+                                commandViewerNameMap.put(commandId, viewerName);
+                            }
                         }
                     } catch (ClassNotFoundException e) {
                         MessagingUtils.error(CdmViewerChooser.class, "Could not initalize selection class element of cdmViewer extension", e); //$NON-NLS-1$