From ef9f1df06605ca4f40069e787ac6cbed8bb002e0 Mon Sep 17 00:00:00 2001
From: Patrick Plitzner
Date: Tue, 9 Aug 2016 11:28:27 +0200
Subject: [PATCH] ref #5348 Reduce space of taxon associations - Use generic
open framework for double-click on list item
---
.../TaxonAssociationDetailElement.java | 87 +++++--------------
.../taxeditor/view/CdmViewerUtil.java | 1 -
2 files changed, 20 insertions(+), 68 deletions(-)
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/association/TaxonAssociationDetailElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/association/TaxonAssociationDetailElement.java
index 697565e07..7a9297445 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/association/TaxonAssociationDetailElement.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/association/TaxonAssociationDetailElement.java
@@ -9,31 +9,17 @@
*/
package eu.etaxonomy.taxeditor.ui.section.occurrence.association;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.Set;
-import java.util.UUID;
-import org.eclipse.core.commands.Command;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.IParameter;
-import org.eclipse.core.commands.NotEnabledException;
-import org.eclipse.core.commands.NotHandledException;
-import org.eclipse.core.commands.Parameterization;
-import org.eclipse.core.commands.ParameterizedCommand;
-import org.eclipse.core.commands.common.NotDefinedException;
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.LabelProvider;
-import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.ListViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Label;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.commands.ICommandService;
-import org.eclipse.ui.handlers.IHandlerService;
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
@@ -47,6 +33,7 @@ import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
+import eu.etaxonomy.taxeditor.view.CdmViewerChooser;
/**
* @author pplitzner
@@ -75,8 +62,8 @@ public class TaxonAssociationDetailElement extends AbstractCdmDetailElement){
- taxonToOpenUuid = ((TaxonBase>)firstElement).getUuid();
- }
- else if(firstElement instanceof SpecimenTypeDesignation){
- //TODO how to open an editor for all typed names?
+ if(firstElement instanceof SpecimenTypeDesignation){
+ SpecimenTypeDesignation typeDesignation = (SpecimenTypeDesignation)firstElement;
+ Set typifiedNames = typeDesignation.getTypifiedNames();
+ if(typifiedNames.size()==1){
+ firstElement = typifiedNames.iterator().next();
+ }
+ if(typifiedNames.size()==0 || typifiedNames.size()>=2){
+ MessagingUtils.informationDialog("Could not open name", "Type designation has either 0 or more than 1 names associated");
+ }
}
else if(firstElement instanceof DeterminationEvent){
if(((DeterminationEvent) firstElement).getTaxon()!=null){
- taxonToOpenUuid = ((DeterminationEvent) firstElement).getTaxon().getUuid();
+ firstElement = ((DeterminationEvent) firstElement).getTaxon();
}
else if(((DeterminationEvent) firstElement).getTaxonName()!=null){
- //TODO how to open editor for taxon name
- }
- }
- if(taxonToOpenUuid!=null){
- String commandId = "eu.etaxonomy.taxeditor.editor.openTaxonEditor";
-
-
- ArrayList parameters = new ArrayList();
- IParameter iparam = null;
-
- //get the command from plugin.xml
- IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- ICommandService cmdService = (ICommandService)window.getService(ICommandService.class);
- Command cmd = cmdService.getCommand(commandId);
-
- //get the parameter
- try {
- iparam = cmd.getParameter("eu.etaxonomy.taxeditor.editor.taxonParameter");
- } catch (NotDefinedException e1) {
- MessagingUtils.error(this.getClass(), "Command not defined", e1);
- }
- Parameterization params = new Parameterization(iparam, taxonToOpenUuid.toString());
- parameters.add(params);
-
- //build the parameterized command
- ParameterizedCommand pc = new ParameterizedCommand(cmd, (Parameterization[]) parameters.toArray(new Parameterization[parameters.size()]));
-
- //execute the command
- IHandlerService handlerService = (IHandlerService)window.getService(IHandlerService.class);
- try {
- handlerService.executeCommand(pc, null);
- } catch (ExecutionException e) {
- MessagingUtils.error(TaxonAssociationDetailElement.class, e);
- } catch (NotDefinedException e) {
- MessagingUtils.error(TaxonAssociationDetailElement.class, e);
- } catch (NotEnabledException e) {
- MessagingUtils.error(TaxonAssociationDetailElement.class, e);
- } catch (NotHandledException e) {
- MessagingUtils.error(TaxonAssociationDetailElement.class, e);
+ firstElement = ((DeterminationEvent) firstElement).getTaxonName();
}
}
+ new CdmViewerChooser(event.getViewer().getControl().getShell()).chooseViewer(firstElement);
}
}
}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerUtil.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerUtil.java
index 698f94233..9f25e6804 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerUtil.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerUtil.java
@@ -74,7 +74,6 @@ public class CdmViewerUtil {
if(selectionClass.isAssignableFrom(input.getClass())){
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(command, viewerName);
}
--
2.34.1