Merge branch 'hotfix/3.12.4' into develop
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / view / derivateSearch / DerivateLabelProvider.java
index 92276048f3f058dbca11ba4d618db6c618654bc8..14265f1d5f179233886d219201d6128b78435e42 100644 (file)
@@ -27,6 +27,8 @@ import org.hibernate.LazyInitializationException;
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.service.IOccurrenceService;
 import eu.etaxonomy.cdm.api.service.molecular.ISequenceService;
+import eu.etaxonomy.cdm.format.CdmFormatter;
+import eu.etaxonomy.cdm.format.ICdmFormatter.FormatKey;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.common.DefinedTerm;
@@ -59,7 +61,7 @@ public class DerivateLabelProvider extends ColumnLabelProvider {
 
     private static Set<SingleRead> multiLinkSingleReads;
 
-    private static Map<DerivedUnit, List<SpecimenTypeDesignation>> typeDesignations;
+    private static Map<DerivedUnit, Collection<SpecimenTypeDesignation>> typeDesignations;
 
     private ConversationHolder conversation;
 
@@ -130,7 +132,26 @@ public class DerivateLabelProvider extends ColumnLabelProvider {
     /** {@inheritDoc} */
     @Override
     public String getText(Object element) {
-        return getDerivateText(element);
+        if(element instanceof TreeNode){
+            element = ((TreeNode) element).getValue();
+        }
+        CdmFormatter formatter = new CdmFormatter(
+                FormatKey.GATHERING_COUNTRY, FormatKey.SPACE,
+                FormatKey.GATHERING_LOCALITY_TEXT, FormatKey.SPACE,
+                FormatKey.GATHERING_DATE, FormatKey.SPACE,
+                FormatKey.GATHERING_COLLECTOR, FormatKey.SPACE,
+                FormatKey.FIELD_NUMBER, FormatKey.SPACE,
+                FormatKey.COLLECTION_CODE, FormatKey.SPACE,
+                FormatKey.MOST_SIGNIFICANT_IDENTIFIER, FormatKey.SPACE,
+                FormatKey.KIND_OF_UNIT, FormatKey.SPACE,
+                FormatKey.SAMPLE_DESIGNATION, FormatKey.SPACE,
+                FormatKey.SINGLE_READ_PRIMER, FormatKey.SPACE,
+                FormatKey.SEQUENCE_DNA_MARKER, FormatKey.SPACE,
+                FormatKey.AMPLIFICATION_LABEL, FormatKey.SPACE,
+                FormatKey.MEDIA_TITLE, FormatKey.SPACE,
+                FormatKey.MEDIA_ARTIST, FormatKey.SPACE
+                );
+        return formatter.format(element);
     }
 
     /** {@inheritDoc} */
@@ -331,11 +352,6 @@ 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);
                 }
@@ -346,6 +362,9 @@ public class DerivateLabelProvider extends ColumnLabelProvider {
                     return hasCharacterData?ImageResources.getImage(ImageResources.TISSUE_SAMPLE_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.TISSUE_SAMPLE_DERIVATE);
                 }
                 else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.PreservedSpecimen){
+                    if(typeDesignations.get(derivedUnit)!=null && !typeDesignations.get(derivedUnit).isEmpty()){
+                        return ImageResources.getImage(ImageResources.SPECIMEN_DERIVATE_TYPE);
+                    }
                     return hasCharacterData?ImageResources.getImage(ImageResources.SPECIMEN_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.SPECIMEN_DERIVATE);
                 }
                 else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.Media){
@@ -400,22 +419,8 @@ public class DerivateLabelProvider extends ColumnLabelProvider {
         return null;
     }
 
-    /**
-     * Refreshes cached label extensions
-     * @param multiLinkSingleReads
-     */
-    public void refresh() {
-        DerivateLabelProvider.multiLinkSingleReads = new HashSet<SingleRead>();
-        for(Entry<SingleRead, Collection<Sequence>> entry:CdmStore.getService(ISequenceService.class).getSingleReadSequencesMap().entrySet()){
-            if(entry.getValue().size()>1){
-                multiLinkSingleReads.add(entry.getKey());
-            }
-        }
-        DerivateLabelProvider.typeDesignations = new HashMap<DerivedUnit, List<SpecimenTypeDesignation>>();
-    }
-
     private static void addTypeDesignation(DerivedUnit derivedUnit, SpecimenTypeDesignation typeDesignation){
-        List<SpecimenTypeDesignation> list = typeDesignations.get(derivedUnit);
+        Collection<SpecimenTypeDesignation> list = typeDesignations.get(derivedUnit);
         if(list==null){
             list = new ArrayList<SpecimenTypeDesignation>();
         }
@@ -427,4 +432,24 @@ public class DerivateLabelProvider extends ColumnLabelProvider {
         return multiLinkSingleReads;
     }
 
+    public void updateLabelCache(Collection<SpecimenOrObservationBase<?>> rootElements) {
+        DerivateLabelProvider.multiLinkSingleReads = new HashSet<SingleRead>();
+        DerivateLabelProvider.typeDesignations = new HashMap<DerivedUnit, Collection<SpecimenTypeDesignation>>();
+        for(Entry<SingleRead, Collection<Sequence>> entry:CdmStore.getService(ISequenceService.class).getSingleReadSequencesMap().entrySet()){
+            if(entry.getValue().size()>1){
+                multiLinkSingleReads.add(entry.getKey());
+            }
+        }
+        if(rootElements!=null){
+            Collection<DerivedUnit> derivedUnits = new ArrayList<DerivedUnit>();
+            for (SpecimenOrObservationBase specimenOrObservationBase : rootElements) {
+                derivedUnits.addAll(CdmStore.getService(IOccurrenceService.class).getAllChildDerivatives(specimenOrObservationBase.getUuid()));
+                if(specimenOrObservationBase.isInstanceOf(DerivedUnit.class)){
+                    derivedUnits.add(HibernateProxyHelper.deproxy(specimenOrObservationBase, DerivedUnit.class));
+                }
+            }
+            typeDesignations = CdmStore.getService(IOccurrenceService.class).listTypeDesignations(derivedUnits, null, null, null, null);
+        }
+    }
+
 }