list specimen-taxon associations separately in specimen details view
authorPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 30 Nov 2015 06:01:23 +0000 (07:01 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 30 Nov 2015 06:01:42 +0000 (07:01 +0100)
 - remove determination info from derivative label

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/association/TaxonAssociationDetailElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/derivateSearch/DerivateLabelProvider.java

index 53d9ea6aba3146b8216d25b0d01c4f5f37fa8613..eb81115f57c8a903d7e09914d26aaa206e18ff89 100644 (file)
@@ -11,6 +11,8 @@ 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;
@@ -24,6 +26,7 @@ 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.swt.SWT;
 import org.eclipse.swt.widgets.Label;
@@ -34,6 +37,9 @@ import org.eclipse.ui.handlers.IHandlerService;
 
 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
 import eu.etaxonomy.cdm.api.service.IOccurrenceService;
+import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
+import eu.etaxonomy.cdm.model.name.TaxonNameBase;
+import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.store.CdmStore;
@@ -49,8 +55,6 @@ import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
  */
 public class TaxonAssociationDetailElement extends AbstractCdmDetailElement<DerivedUnitFacade> implements IDoubleClickListener{
 
-    private TableViewer associationsViewer;
-
     public TaxonAssociationDetailElement(CdmFormFactory formFactory, ICdmFormElement formElement) {
         super(formFactory, formElement);
     }
@@ -61,20 +65,70 @@ public class TaxonAssociationDetailElement extends AbstractCdmDetailElement<Deri
 
         //TODO add context menu for deleting associations
 
-        Collection<TaxonBase<?>> associatedTaxa = CdmStore.getService(IOccurrenceService.class).listAssociatedTaxa(entity.innerDerivedUnit(), null, null, null, null);
+        Collection<TaxonBase<?>> associatedTaxa = CdmStore.getService(IOccurrenceService.class).listIndividualsAssociationTaxa(entity.innerDerivedUnit(), null, null, null, null);
+        Collection<SpecimenTypeDesignation> typeDesignations = CdmStore.getService(IOccurrenceService.class).listTypeDesignations(entity.innerDerivedUnit(), null, null, null, null);
+        Collection<DeterminationEvent> determinationEvents = CdmStore.getService(IOccurrenceService.class).listDeterminationEvents(entity.innerDerivedUnit(), null, null, null, null);
 
-        if(!associatedTaxa.isEmpty()){
-            associationsViewer = new TableViewer(getLayoutComposite(), SWT.FULL_SELECTION);
-            associationsViewer.getTable().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
-            associationsViewer.setContentProvider(new ArrayContentProvider());
-            associationsViewer.setInput(associatedTaxa);
-            associationsViewer.addDoubleClickListener(this);
-        }
-        else{
+        if(associatedTaxa.isEmpty() && typeDesignations.isEmpty() && determinationEvents.isEmpty()){
             Label label = formFactory.createLabel(getLayoutComposite(), "No associations");
             label.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+            return;
+        }
+        if(!associatedTaxa.isEmpty()){
+            TableViewer viewer = new TableViewer(getLayoutComposite(), SWT.FULL_SELECTION);
+            viewer.getTable().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+            viewer.setContentProvider(new ArrayContentProvider());
+            viewer.setLabelProvider(new LabelProvider(){
+                @Override
+                public String getText(Object element) {
+                    return "Associated with "+element.toString();
+                }
+            });
+            viewer.setInput(associatedTaxa);
+            viewer.addDoubleClickListener(this);
+        }
+        if(!typeDesignations.isEmpty()){
+            TableViewer viewer = new TableViewer(getLayoutComposite(), SWT.FULL_SELECTION);
+            viewer.getTable().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+            viewer.setContentProvider(new ArrayContentProvider());
+            viewer.setLabelProvider(new LabelProvider(){
+                @Override
+                public String getText(Object element) {
+                    SpecimenTypeDesignation typeDesignation = (SpecimenTypeDesignation)element;
+                    String label = typeDesignation.getTypeStatus().getLabel()+" of ";
+                        Set<TaxonNameBase> typifiedNames = typeDesignation.getTypifiedNames();
+                        for (TaxonNameBase taxonNameBase : typifiedNames) {
+                            label += taxonNameBase+", ";
+                        }
+                        if(label.endsWith(", ")){
+                            label = label.substring(0, label.length()-2);
+                        }
+                    return label;
+                }
+            });
+            viewer.setInput(typeDesignations);
+            viewer.addDoubleClickListener(this);
+        }
+        if(!determinationEvents.isEmpty()){
+            TableViewer viewer = new TableViewer(getLayoutComposite(), SWT.FULL_SELECTION);
+            viewer.getTable().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+            viewer.setContentProvider(new ArrayContentProvider());
+            viewer.setLabelProvider(new LabelProvider(){
+                @Override
+                public String getText(Object element) {
+                    DeterminationEvent determinationEvent = (DeterminationEvent)element;
+                    if(determinationEvent.getTaxon()!=null){
+                        return "Determined as taxon "+determinationEvent.getTaxon();
+                    }
+                    if(determinationEvent.getTaxonName()!=null){
+                        return "Determined as name "+determinationEvent.getTaxonName();
+                    }
+                    return element.toString();
+                }
+            });
+            viewer.setInput(determinationEvents);
+            viewer.addDoubleClickListener(this);
         }
-
     }
 
     /** {@inheritDoc} */
@@ -87,8 +141,22 @@ public class TaxonAssociationDetailElement extends AbstractCdmDetailElement<Deri
     public void doubleClick(DoubleClickEvent event) {
         if(event.getSelection() instanceof IStructuredSelection){
             Object firstElement = ((IStructuredSelection) event.getSelection()).getFirstElement();
+            UUID taxonToOpenUuid = null;
             if(firstElement instanceof TaxonBase<?>){
-                TaxonBase<?> taxonBase = (TaxonBase<?>)firstElement;
+                taxonToOpenUuid = ((TaxonBase<?>)firstElement).getUuid();
+            }
+            else if(firstElement instanceof SpecimenTypeDesignation){
+                //TODO how to open an editor for all typed names?
+            }
+            else if(firstElement instanceof DeterminationEvent){
+                if(((DeterminationEvent) firstElement).getTaxon()!=null){
+                    taxonToOpenUuid = ((DeterminationEvent) firstElement).getTaxon().getUuid();
+                }
+                else if(((DeterminationEvent) firstElement).getTaxonName()!=null){
+                    //TODO how to open editor for taxon name
+                }
+            }
+            if(taxonToOpenUuid!=null){
                 String commandId = "eu.etaxonomy.taxeditor.editor.openTaxonEditor";
 
 
@@ -106,7 +174,7 @@ public class TaxonAssociationDetailElement extends AbstractCdmDetailElement<Deri
                 } catch (NotDefinedException e1) {
                     MessagingUtils.error(this.getClass(), "Command not defined", e1);
                 }
-                Parameterization params = new Parameterization(iparam, (taxonBase).getUuid().toString());
+                Parameterization params = new Parameterization(iparam, taxonToOpenUuid.toString());
                 parameters.add(params);
 
                 //build the parameterized command
@@ -128,5 +196,4 @@ public class TaxonAssociationDetailElement extends AbstractCdmDetailElement<Deri
             }
         }
     }
-
 }
index 3a7c48b0c54d2fae1242a5301fa0c2a6a81467c3..92276048f3f058dbca11ba4d618db6c618654bc8 100644 (file)
@@ -35,9 +35,7 @@ import eu.etaxonomy.cdm.model.molecular.DnaSample;
 import eu.etaxonomy.cdm.model.molecular.Sequence;
 import eu.etaxonomy.cdm.model.molecular.SingleRead;
 import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
-import eu.etaxonomy.cdm.model.name.TaxonNameBase;
 import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
-import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
 import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
 import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
 import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
@@ -61,8 +59,6 @@ public class DerivateLabelProvider extends ColumnLabelProvider {
 
     private static Set<SingleRead> multiLinkSingleReads;
 
-    private static Map<DerivedUnit, List<DeterminationEvent>> determinationEvents;
-
     private static Map<DerivedUnit, List<SpecimenTypeDesignation>> typeDesignations;
 
     private ConversationHolder conversation;
@@ -238,12 +234,6 @@ public class DerivateLabelProvider extends ColumnLabelProvider {
                         addTypeDesignation(derivedUnit, specimenTypeDesignation);
                     }
                 }
-                //check for determination events
-                if(determinationEvents.get(derivedUnit)==null){
-                    for (DeterminationEvent determinationEvent : CdmStore.getService(IOccurrenceService.class).listDeterminationEvents(derivedUnit, null, null, null, null)) {
-                        addDeterminationEvent(derivedUnit, determinationEvent);
-                    }
-                }
                 //java.util.Collection<FieldUnit> fieldUnits = CdmStore.getService(IOccurrenceService.class).getFieldUnits(derivedUnit.getUuid());
                 //TODO : This is not generic anymore for performance reasons
                 Set<SpecimenOrObservationBase> originals = derivedUnit.getOriginals();
@@ -265,35 +255,6 @@ public class DerivateLabelProvider extends ColumnLabelProvider {
                 }
                 String mostSignificantIdentifier = derivedUnit.getMostSignificantIdentifier();
                 label += mostSignificantIdentifier!=null?mostSignificantIdentifier+separator:emptyString;
-                //type designation extension
-                List<SpecimenTypeDesignation> typeDesignationList = typeDesignations.get(derivedUnit);
-                if(typeDesignationList!=null){
-                    for (SpecimenTypeDesignation specimenTypeDesignation : typeDesignationList) {
-                        label += "("+specimenTypeDesignation.getTypeStatus()+" of ";
-                        for (TaxonNameBase taxonNameBase : specimenTypeDesignation.getTypifiedNames()) {
-                            label += taxonNameBase+separator;
-                        }
-                        if(label.endsWith(separator)){
-                            label = label.substring(0, label.length()-separator.length());
-                        }
-                        label += ")";
-                    }
-                }
-                //determination event extension
-                List<DeterminationEvent> determinationEventList = determinationEvents.get(derivedUnit);
-                if(determinationEventList!=null){
-                    for (DeterminationEvent determinationEvent : determinationEventList) {
-                        label += "(";
-                        if(determinationEvent.getTaxon()!=null){
-                            label += "Determined as "+determinationEvent.getTaxon();
-                        }
-
-                        if(label.endsWith(separator)){
-                            label = label.substring(0, label.length()-separator.length());
-                        }
-                        label += ")";
-                    }
-                }
             }
             else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.TissueSample){
                 //TissueSample should only be created by using it's own class
@@ -369,6 +330,12 @@ public class DerivateLabelProvider extends ColumnLabelProvider {
             }
             else if(cdmBase.isInstanceOf(DerivedUnit.class)){
                 DerivedUnit derivedUnit = HibernateProxyHelper.deproxy(element, DerivedUnit.class);
+
+                boolean isType = false;
+                //type designation extension
+                if(typeDesignations.get(derivedUnit)!=null){
+                    isType = true;
+                }
                 if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.FieldUnit){
                     return hasCharacterData?ImageResources.getImage(ImageResources.FIELD_UNIT_CHARACTER_DATA):ImageResources.getImage(ImageResources.FIELD_UNIT);
                 }
@@ -445,16 +412,6 @@ public class DerivateLabelProvider extends ColumnLabelProvider {
             }
         }
         DerivateLabelProvider.typeDesignations = new HashMap<DerivedUnit, List<SpecimenTypeDesignation>>();
-        DerivateLabelProvider.determinationEvents = new HashMap<DerivedUnit, List<DeterminationEvent>>();
-    }
-
-    private static void addDeterminationEvent(DerivedUnit derivedUnit, DeterminationEvent determinationEvent){
-        List<DeterminationEvent> list = determinationEvents.get(derivedUnit);
-        if(list==null){
-            list = new ArrayList<DeterminationEvent>();
-        }
-        list.add(determinationEvent);
-        determinationEvents.put(derivedUnit, list);
     }
 
     private static void addTypeDesignation(DerivedUnit derivedUnit, SpecimenTypeDesignation typeDesignation){