Merge branch 'master' into develop
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / view / derivateSearch / DerivateLabelProvider.java
index 80d49bca772aaaaea4f424300c8060e3e7851059..7b9a8d0630138f0f4bd428a3a5a07504709c9611 100644 (file)
@@ -19,7 +19,6 @@ import org.eclipse.swt.graphics.Image;
 import org.hibernate.LazyInitializationException;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
-import eu.etaxonomy.cdm.api.service.IOccurrenceService;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.common.DefinedTerm;
@@ -155,7 +154,7 @@ public class DerivateLabelProvider extends ColumnLabelProvider {
         conversation.bind();
 
         final String emptyString = "";
-        final String separator = ", ";
+        final String separator = " ";
 
         String label = emptyString;
 
@@ -164,10 +163,6 @@ public class DerivateLabelProvider extends ColumnLabelProvider {
             FieldUnit fieldUnit = (FieldUnit)derivate;
             if(fieldUnit.getGatheringEvent()!=null){
                 GatheringEvent gatheringEvent = fieldUnit.getGatheringEvent();
-                if(CdmStore.getService(IOccurrenceService.class).exists(fieldUnit.getUuid()) && !conversation.getSession().contains(gatheringEvent)){
-                    fieldUnit = (FieldUnit) CdmStore.getService(IOccurrenceService.class).load(fieldUnit.getUuid());
-                    gatheringEvent = fieldUnit.getGatheringEvent();
-                }
                 label += gatheringEvent.getCountry()!=null?gatheringEvent.getCountry().getLabel()+separator:emptyString;
                 label += gatheringEvent.getLocality()!=null?gatheringEvent.getLocality().getText()+separator:emptyString;
                 label += gatheringEvent.getGatheringDate()!=null?gatheringEvent.getGatheringDate()+separator:emptyString;
@@ -220,24 +215,27 @@ public class DerivateLabelProvider extends ColumnLabelProvider {
         else if(derivate instanceof DerivedUnit){
             DerivedUnit derivedUnit = (DerivedUnit)derivate;
             if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.PreservedSpecimen){
-                java.util.Collection<FieldUnit> fieldUnits = CdmStore.getService(IOccurrenceService.class).getFieldUnits(derivedUnit.getUuid());
-                if(fieldUnits!=null && !fieldUnits.isEmpty()){
-                    FieldUnit fieldUnit = fieldUnits.iterator().next();
-                    GatheringEvent gatheringEvent = fieldUnit.getGatheringEvent();
-//                  gatheringEvent = HibernateProxyHelper.deproxy(gatheringEvent, GatheringEvent.class);
-                    if(gatheringEvent!=null){
-                        label += gatheringEvent.getCollector()!=null?gatheringEvent.getCollector()+separator:emptyString;
+                //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();
+                if(originals!=null && originals.size() ==1) {
+                    SpecimenOrObservationBase specimen = originals.iterator().next();
+                    if(specimen instanceof FieldUnit) {
+                        FieldUnit fieldUnit = (FieldUnit)specimen;
+                        GatheringEvent gatheringEvent = fieldUnit.getGatheringEvent();
+                        if(gatheringEvent!=null){
+                            label += gatheringEvent.getCollector()!=null?gatheringEvent.getCollector()+separator:emptyString;
+                        }
+                        label += fieldUnit.getFieldNumber()!=null?fieldUnit.getFieldNumber()+separator:emptyString;
                     }
-                    label += fieldUnit.getFieldNumber()!=null?fieldUnit.getFieldNumber()+separator:emptyString;
                 }
+
                 eu.etaxonomy.cdm.model.occurrence.Collection collection = derivedUnit.getCollection();
                 if(collection!=null){
-                    label += collection.getName()!=null?collection.getName()+" ":emptyString;
-                    label += collection.getCode()!=null?"("+collection.getCode()+"), ":emptyString;
+                    label += collection.getCode()!=null?"("+collection.getCode()+")"+separator:emptyString;
                 }
-                String mostSignificantIdentifier = CdmStore.getService(IOccurrenceService.class).getMostSignificantIdentifier(derivedUnit);
+                String mostSignificantIdentifier = derivedUnit.getMostSignificantIdentifier();
                 label += mostSignificantIdentifier!=null?mostSignificantIdentifier+separator:emptyString;
-                label += derivedUnit.getBarcode()!=null?derivedUnit.getBarcode():emptyString;
             }
             else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.TissueSample){
                 //TissueSample should only be created by using it's own class
@@ -307,7 +305,7 @@ public class DerivateLabelProvider extends ColumnLabelProvider {
             boolean hasCharacterData = false;
             if(cdmBase.isInstanceOf(SpecimenOrObservationBase.class)){
                 SpecimenOrObservationBase<?> specimen = HibernateProxyHelper.deproxy(cdmBase, SpecimenOrObservationBase.class);
-                if(!CdmStore.getService(IOccurrenceService.class).getCharacterDataForSpecimen(specimen).isEmpty()){
+                if(specimen.hasCharacterData()){
                     hasCharacterData = true;
                 }
             }