ref #7095 Cache description elements in row wrapper for performance
authorPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 30 Jan 2018 06:54:11 +0000 (07:54 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 30 Jan 2018 12:41:49 +0000 (13:41 +0100)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/CharacterMatrix.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/RowWrapper.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/SpecimenColumnPropertyAccessor.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/categorical/CategoricalDataCellEditor.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/quantitative/QuantitativeDataCellEditor.java

index 4f4118ee1584d7b7a22c272f1ff7bb2cf3464af1..c305f1bb5a747e92b9952599ae5c265f6d769d20 100644 (file)
@@ -127,7 +127,6 @@ import ca.odell.glazedlists.TreeList;
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
 import eu.etaxonomy.cdm.api.service.IWorkingSetService;
-import eu.etaxonomy.cdm.model.common.TermVocabulary;
 import eu.etaxonomy.cdm.model.description.DescriptionBase;
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
 import eu.etaxonomy.cdm.model.description.Feature;
@@ -199,6 +198,8 @@ ICdmEntitySessionEnabled{
 
     private Map<Integer, Feature> indexToFeatureMap = new HashMap<>();
 
+    private Map<Feature, List<State>> categoricalFeatureToStateMap = new HashMap<>();
+
     private LinkedMap<String, String> propertyToLabelMap = new LinkedMap<>();
 
     private Properties natTableState;
@@ -473,6 +474,15 @@ ICdmEntitySessionEnabled{
             FeatureTree tree = workingSet.getDescriptiveSystem();
             features = new ArrayList<>(tree.getDistinctFeatures());
             Collections.sort(features);
+            //init state data for categorical features
+            features.forEach(feature->
+            {
+                if(feature.isSupportsCategoricalData()){
+                    List<State> supportedStates = new ArrayList<>();
+                    feature.getSupportedCategoricalEnumerations().forEach(voc->supportedStates.addAll(voc.getTerms()));
+                    categoricalFeatureToStateMap.put(feature, supportedStates);
+                }
+            });
 
             descriptions = GlazedLists.eventList(getDescriptions(workingSet));
         }
@@ -909,17 +919,10 @@ ICdmEntitySessionEnabled{
 
                 @Override
                 public List<?> getValues(int columnIndex, int rowIndex) {
-                    List<State> states = new ArrayList<>();
                     Feature feature = indexToFeatureMap.get(columnIndex);
-                    if(feature.isSupportsCategoricalData()){
-                        Set<TermVocabulary<State>> stateVocs = feature.getSupportedCategoricalEnumerations();
-                        for (TermVocabulary<State> voc : stateVocs) {
-                            states.addAll(voc.getTerms());
-                        }
-                    }
-                    return states;
+                    return getSupportedStatesForCategoricalFeature(feature);
                 }
-            }, 5, this, feature);
+            }, 10, this, feature);
             //register editor
             configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR,
                     comboBoxCellEditor,
@@ -941,6 +944,10 @@ ICdmEntitySessionEnabled{
         return rowWrappers;
     }
 
+    public List<State> getSupportedStatesForCategoricalFeature(Feature feature){
+        return categoricalFeatureToStateMap.get(feature);
+    }
+
     public Map<Integer, Feature> getIndexToFeatureMap() {
         return indexToFeatureMap;
     }
index 4be78b86e5629549daacb7c4463450177b39fff8..f195b34b3831bbb52cd39c2c26b57c86d2c81adb 100644 (file)
@@ -9,9 +9,16 @@
 package eu.etaxonomy.taxeditor.editor.workingSet.matrix;
 
 import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
 
 import eu.etaxonomy.cdm.api.service.IOccurrenceService;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
+import eu.etaxonomy.cdm.model.description.CategoricalData;
+import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
+import eu.etaxonomy.cdm.model.description.Feature;
+import eu.etaxonomy.cdm.model.description.QuantitativeData;
 import eu.etaxonomy.cdm.model.description.SpecimenDescription;
 import eu.etaxonomy.cdm.model.location.NamedArea;
 import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
@@ -35,12 +42,14 @@ public class RowWrapper {
     private FieldUnit fieldUnit;
     private String identifier;
     private NamedArea country;
+    private Map<Feature, DescriptionElementBase> featureToElementMap = new HashMap<>();
 
     public RowWrapper(SpecimenDescription description) {
         this.description = description;
 
         IOccurrenceService occurrenceService = CdmStore.getService(IOccurrenceService.class);
         SpecimenOrObservationBase<?> specimen = HibernateProxyHelper.deproxy(description.getDescribedSpecimenOrObservation(), SpecimenOrObservationBase.class);
+        //supplemental information
         if(specimen!=null){
             Collection<TaxonBase<?>> associatedTaxa = occurrenceService.listAssociatedTaxa(specimen, null, null, null, null);
             if(associatedTaxa!=null){
@@ -60,6 +69,26 @@ public class RowWrapper {
                 country = fieldUnit.getGatheringEvent().getCountry();
             }
         }
+        //description elements
+        Set<DescriptionElementBase> elements = description.getElements();
+        for (DescriptionElementBase descriptionElementBase : elements) {
+            Feature feature = descriptionElementBase.getFeature();
+            featureToElementMap.put(feature, descriptionElementBase);
+        }
+    }
+
+    public QuantitativeData addQuantitativeData(Feature feature){
+        QuantitativeData data = QuantitativeData.NewInstance(feature);
+        description.addElement(data);
+        featureToElementMap.put(feature, data);
+        return data;
+    }
+
+    public CategoricalData addCategoricalData(Feature feature){
+        CategoricalData data = CategoricalData.NewInstance(feature);
+        description.addElement(data);
+        featureToElementMap.put(feature, data);
+        return data;
     }
 
     public SpecimenDescription getSpecimenDescription() {
@@ -82,4 +111,8 @@ public class RowWrapper {
         return country;
     }
 
+    public DescriptionElementBase getDescriptionElementForFeature(Feature feature){
+        return featureToElementMap.get(feature);
+    }
+
 }
index c1db2bdf7be48a589009b666f73a948d0cc59c48..25e3ad1e3b767956d1982128cb4cc31616160b33 100644 (file)
@@ -56,12 +56,7 @@ public class SpecimenColumnPropertyAccessor implements IColumnPropertyAccessor<O
                 break;
             }
             Feature feature = matrix.getIndexToFeatureMap().get(columnIndex);
-            Set<DescriptionElementBase> elements = rowWrapper.getSpecimenDescription().getElements();
-            for (DescriptionElementBase descriptionElementBase : elements) {
-                if(descriptionElementBase.getFeature().equals(feature)){
-                    return descriptionElementBase;
-                }
-            }
+            return rowWrapper.getDescriptionElementForFeature(feature);
         } else if (columnIndex == 0) {
             return rowObject;
         }
index 3e1dffcc03d2e861456b888238e1288ce916ad25..6d7d6fc8b1e0b4c6763b7202588221360ce4586c 100644 (file)
@@ -45,12 +45,10 @@ public class CategoricalDataCellEditor extends FilterRowComboBoxCellEditor{
         if(canonicalValue==null){
             Object rowWrapper = matrix.getBodyDataProvider().getRowObject(this.getRowIndex());
             if(rowWrapper instanceof RowWrapper){
-                CategoricalData data = CategoricalData.NewInstance(feature);
-                ((RowWrapper) rowWrapper).getSpecimenDescription().addElement(data);
-                canonicalValue = data;
+                canonicalValue = ((RowWrapper) rowWrapper).addCategoricalData(feature);
             }
         }
-        if (canonicalValue instanceof CategoricalData) {
+        else if (canonicalValue instanceof CategoricalData) {
             CategoricalData data = (CategoricalData)canonicalValue;
             List<State> states = data.getStatesOnly();
             String[] result = new String[states.size()];
index fad2ad0484291ee8eefb3d5ff6200a3bedf91476..ebe3c0391cd3ca8df4310f2f5605679142155b37 100644 (file)
@@ -134,9 +134,7 @@ public class QuantitativeDataCellEditor extends AbstractCellEditor{
         if(rowObject instanceof RowWrapper){
             this.editorControl = createEditorControl(parent);
             if(originalCanonicalValue==null){
-                QuantitativeData data = QuantitativeData.NewInstance(feature);
-                ((RowWrapper) rowObject).getSpecimenDescription().addElement(data);
-                originalCanonicalValue = data;
+                originalCanonicalValue = ((RowWrapper) rowObject).addQuantitativeData(feature);
             }
             this.setEditorValue(originalCanonicalValue);