From 1d81ea4a74d535bea9b66b471792a69848182052 Mon Sep 17 00:00:00 2001
From: Patrick Plitzner
Date: Mon, 8 Aug 2016 16:58:55 +0200
Subject: [PATCH] ref #5616 Add alternative to double click execution in search
view - Opens either in name or bulk editor
---
.../taxeditor/navigation/NavigationUtil.java | 44 +++++++++++++++++--
.../taxeditor/view/CdmViewerContextMenu.java | 3 +-
2 files changed, 42 insertions(+), 5 deletions(-)
diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationUtil.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationUtil.java
index 61e8b1d73..da31d1c5b 100644
--- a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationUtil.java
+++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationUtil.java
@@ -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 params = new HashMap();
+ 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$
+ }
+ }
+ }
+
/**
* openEmpty
*
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerContextMenu.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerContextMenu.java
index b73d604d5..1adc65286 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerContextMenu.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerContextMenu.java
@@ -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();
}
}
--
2.34.1