ref #5616 Add alternative to double click execution in search view
authorPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 8 Aug 2016 14:58:55 +0000 (16:58 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 8 Aug 2016 14:58:55 +0000 (16:58 +0200)
 - Opens either in name or bulk editor

eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationUtil.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerContextMenu.java

index 61e8b1d73292d7cd2f5c449388e8832d33adf80a..da31d1c5bf1f797c3aec7823aa8431a0a78ff28e 100644 (file)
@@ -9,9 +9,14 @@
 
 package eu.etaxonomy.taxeditor.navigation;
 
+import java.util.HashMap;
+import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
 
+import org.eclipse.core.commands.Command;
+import org.eclipse.core.commands.ParameterizedCommand;
+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;
@@ -23,6 +28,8 @@ import org.eclipse.ui.IEditorReference;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.handlers.IHandlerService;
 import org.eclipse.ui.navigator.CommonViewer;
 
 import eu.etaxonomy.cdm.api.service.IClassificationService;
@@ -103,10 +110,15 @@ public class NavigationUtil extends AbstractUtility{
                        else if(selectedObject instanceof TaxonNode){
                                EditorUtil.openTaxonNode(entityUuid);
                        }else if(selectedObject instanceof TaxonBase){
-                               EditorUtil.openTaxonBase(entityUuid);
+                               TaxonBase taxonBase = (TaxonBase)selectedObject;
+                               if(taxonBase.isOrphaned()){
+                                       openInBulkEditor(taxonBase);
+                               }
+                               else{
+                                       EditorUtil.openTaxonBase(entityUuid);
+                               }
                        }else if(selectedObject instanceof TaxonNameBase){
-                               // TODO open bulk editor
-                               MessagingUtils.warningDialog("Not implemented yet", NavigationUtil.class, "You tried to open a name. This is not handled by the software yet. For open a pure name you can use the bulk editor");
+                               openInBulkEditor(selectedObject);
                        }else if(selectedObject instanceof PolytomousKey){
                                EditorUtil.openPolytomousKey(entityUuid);
                        }else{
@@ -124,6 +136,32 @@ public class NavigationUtil extends AbstractUtility{
                }
        }
 
+       private static void openInBulkEditor(ICdmBase selectedObject) {
+               ICommandService commandService = (ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class);
+               IHandlerService handlerService = (IHandlerService)PlatformUI.getWorkbench().getService(IHandlerService.class);
+               String openInBulkEditorCommand = "eu.etaxonomy.taxeditor.bulkeditor.openBulkEditorForIdentifiableEntity";
+               Command command = commandService.getCommand(openInBulkEditorCommand);
+               if(command.isDefined()){
+                       Map<String, UUID> params = new HashMap<String, UUID>();
+                       params.put(openInBulkEditorCommand+".uuid", ((ICdmBase) selectedObject).getUuid()); //$NON-NLS-1$
+                       ParameterizedCommand parameterizedCommand = ParameterizedCommand.generateCommand(command, params);
+                       try {
+                               if(parameterizedCommand!=null){
+                                       handlerService.executeCommand(parameterizedCommand, null);
+                                       return;
+                               }
+                               else{
+                                       handlerService.executeCommand(command.getId(), null);
+                                       return;
+                               }
+                       } catch (NotDefinedException nde) {
+                               throw new RuntimeException("Could not find open command: " + command.getId()); //$NON-NLS-1$
+                       } catch (Exception exception) {
+                               MessagingUtils.error(NavigationUtil.class, "An exception occured while trying to execute "+command.getId(), exception); //$NON-NLS-1$
+                       }
+               }
+       }
+
        /**
         * <p>openEmpty</p>
         *
index b73d604d5bf7fc35156d3777c4cff8a9dcb89d02..1adc652868c6aee513d69b56f35ad4ae5025b955 100644 (file)
@@ -110,9 +110,8 @@ public class CdmViewerContextMenu extends CompoundContributionItem {
             } catch (NotDefinedException nde) {
                 throw new RuntimeException("Could not find open command: " + command.getId()); //$NON-NLS-1$
             } catch (Exception exception) {
-                MessagingUtils.error(getClass(), "An exception occured while trying execute "+command.getId(), exception); //$NON-NLS-1$
+                MessagingUtils.error(getClass(), "An exception occured while trying to execute "+command.getId(), exception); //$NON-NLS-1$
             }
-            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection();
         }
     }