Cache cdm formatter in DerivateLabelProvider
authorp.plitzner <p.plitzner@bgbm.org>
Mon, 22 Feb 2016 17:07:54 +0000 (18:07 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 23 Feb 2016 14:50:15 +0000 (15:50 +0100)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/derivateSearch/DerivateLabelProvider.java

index 42d538a0c97d8745eb389eae500a7216a923d14a..980a464f36c3a6850017e2f6997ab816a2db656f 100644 (file)
@@ -28,6 +28,7 @@ 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.CdmFormatterFactory;
+import eu.etaxonomy.cdm.format.ICdmFormatter;
 import eu.etaxonomy.cdm.format.ICdmFormatter.FormatKey;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.common.CdmBase;
@@ -62,6 +63,8 @@ public class DerivateLabelProvider extends ColumnLabelProvider {
     private static Set<SingleRead> multiLinkSingleReads;
 
     private static Map<DerivedUnit, Collection<SpecimenTypeDesignation>> typeDesignations;
+    
+    private static Map<Class<? extends Object>, ICdmFormatter> formatterMap = new HashMap<>();
 
     private ConversationHolder conversation;
 
@@ -135,7 +138,7 @@ public class DerivateLabelProvider extends ColumnLabelProvider {
         if(element instanceof TreeNode){
             element = ((TreeNode) element).getValue();
         }
-        return CdmFormatterFactory.format(element,
+        FormatKey[] formatKeys = {
                 FormatKey.GATHERING_COUNTRY, FormatKey.SPACE,
                 FormatKey.GATHERING_LOCALITY_TEXT, FormatKey.SPACE,
                 FormatKey.GATHERING_DATE, FormatKey.SPACE,
@@ -150,7 +153,13 @@ public class DerivateLabelProvider extends ColumnLabelProvider {
                 FormatKey.AMPLIFICATION_LABEL, FormatKey.SPACE,
                 FormatKey.MEDIA_TITLE, FormatKey.SPACE,
                 FormatKey.MEDIA_ARTIST, FormatKey.SPACE
-                );
+        };
+        ICdmFormatter formatter = formatterMap.get(element.getClass());
+        if(formatter==null){
+               formatter = CdmFormatterFactory.getFormatter(element, formatKeys);
+               formatterMap.put(element.getClass(), formatter);
+        }
+        return formatter.format(element);
     }
 
     /** {@inheritDoc} */
@@ -432,8 +441,8 @@ public class DerivateLabelProvider extends ColumnLabelProvider {
     }
 
     public void updateLabelCache(Collection<SpecimenOrObservationBase<?>> rootElements) {
-        DerivateLabelProvider.multiLinkSingleReads = new HashSet<SingleRead>();
-        DerivateLabelProvider.typeDesignations = new HashMap<DerivedUnit, Collection<SpecimenTypeDesignation>>();
+        multiLinkSingleReads = new HashSet<SingleRead>();
+        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());