ref #8450 Create and cache label for quantitative data in row wrapper
authorPatrick Plitzner <p.plitzner@bgbm.org>
Thu, 19 Sep 2019 07:55:41 +0000 (09:55 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Thu, 19 Sep 2019 07:55:41 +0000 (09:55 +0200)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/SpecimenColumnPropertyAccessor.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataDialog.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataDialogEditor.java

index 497034aec9b96d55673d0a30c0d0edcd8bbf8d26..72bd65ff33b0b794a88bee202e9737fcd6e82caa 100644 (file)
@@ -87,7 +87,9 @@ public class SpecimenColumnPropertyAccessor implements IColumnPropertyAccessor<O
             RowWrapperDTO rowWrapper = (RowWrapperDTO)rowObject;
             matrix.addRowToSave(rowWrapper);
             Feature feature = matrix.getIndexToFeatureMap().get(columnIndex);
-            if(newValue instanceof Collection && ((Collection) newValue).stream().allMatch(o->o instanceof TermDto)){
+            if(feature.isSupportsCategoricalData()
+                    && newValue instanceof Collection
+                    && ((Collection) newValue).stream().allMatch(o->o instanceof TermDto)){
                 List<TermDto> dtos = (List<TermDto>)newValue;
                 List<UUID> termUuids = dtos.stream().map(dto->dto.getUuid()).collect(Collectors.toList());
                 List<DefinedTermBase> terms = CdmStore.getService(ITermService.class).load(termUuids, null);
@@ -97,7 +99,7 @@ public class SpecimenColumnPropertyAccessor implements IColumnPropertyAccessor<O
                         states.add((State) definedTermBase);
                     }
                 }
-                rowWrapper.setDataValueForFeature(feature, states);
+                rowWrapper.setDataValueForCategoricalData(feature, states);
             }
         }
     }
index cf12519fb0b8966720d284caaa8d06c2fd0fd676..797e1081e681b9ddb16eb8bf4987e15669d15d6f 100644 (file)
@@ -8,8 +8,12 @@
 */
 package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative;
 
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.stream.Collectors;
 
 import org.eclipse.jface.window.Window;
 import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
@@ -22,9 +26,9 @@ import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Text;
 
+import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
 import eu.etaxonomy.cdm.model.description.QuantitativeData;
 import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
-import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue;
 import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrix;
 
 /**
@@ -46,6 +50,7 @@ public class QuantitativeDataDialog extends CellEditDialog {
     }
 
     private QuantitativeData editorValue;
+    private RowWrapperDTO<?> rowWrapperDTO;
 
     private QuantitativeDataDialogComposite composite;
 
@@ -59,32 +64,32 @@ public class QuantitativeDataDialog extends CellEditDialog {
         this.editorValue = editorValue;
     }
 
+    void setRowWrapper(RowWrapperDTO<?> rowWrapperDTO) {
+        this.rowWrapperDTO = rowWrapperDTO;
+    }
+
     @Override
     public boolean close() {
         if(getReturnCode()==Window.OK){
-            updateQuantitativeData(editorValue);
+            //clear values
+            editorValue.getStatisticalValues().clear();
+            //add back all values from text fields
+            Map<StatisticalMeasure, List<String>> measureToValueMap = new HashMap<>();
+
+            Map<StatisticalMeasure, List<Text>> textFields = composite.getTextFields();
+            Set<Entry<StatisticalMeasure,List<Text>>> entrySet = textFields.entrySet();
+            for (Entry<StatisticalMeasure, List<Text>> entry : entrySet) {
+                StatisticalMeasure statisticalMeasure = entry.getKey();
+                List<String> values = entry.getValue().stream()
+                        .filter(text->text.isEnabled())
+                        .map(text->text.getText())
+                        .collect(Collectors.toList());
+                measureToValueMap.put(statisticalMeasure, values);
+            }
+            rowWrapperDTO.setDataValueForQuantitativeData(editorValue.getFeature(), measureToValueMap);
             matrix.setDirty();
         }
         return super.close();
     }
 
-    void updateQuantitativeData(QuantitativeData quantitativeData){
-        //clear values
-        quantitativeData.getStatisticalValues().clear();
-        //add back all values from text fields
-        Map<StatisticalMeasure, List<Text>> textFields = composite.getTextFields();
-        textFields.forEach((measure, texts)->{
-            texts.forEach(text->{
-                if(text.isEnabled()){
-                    String string = text.getText();
-                    try {
-                        float exactValue = Float.parseFloat(string);
-                        quantitativeData.addStatisticalValue(StatisticalMeasurementValue.NewInstance(measure, exactValue));
-                    } catch (NumberFormatException e) {
-                    }
-                }
-            });
-        });
-    }
-
 }
index 215b4be1da6f505d79d7431f487457c9fa63f818..c109621d286b0d97c914bb87ef344b9a3368d246 100644 (file)
@@ -20,6 +20,7 @@ import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 
 import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
+import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
 import eu.etaxonomy.cdm.model.description.Feature;
 import eu.etaxonomy.cdm.model.description.QuantitativeData;
 import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrix;
@@ -32,6 +33,7 @@ import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrix;
 public class QuantitativeDataDialogEditor extends AbstractDialogCellEditor {
 
     private QuantitativeData editorValue;
+    private RowWrapperDTO<?> rowWrapperDTO;
     private boolean closed;
     private CharacterMatrix matrix;
     private Character initialInput;
@@ -69,6 +71,7 @@ public class QuantitativeDataDialogEditor extends AbstractDialogCellEditor {
     @Override
     public void setEditorValue(Object value) {
         ((QuantitativeDataDialog)this.dialog).setEditorValue((QuantitativeData) value);
+        ((QuantitativeDataDialog)this.dialog).setRowWrapper(rowWrapperDTO);
         this.editorValue = (QuantitativeData) value;
     }
 
@@ -92,11 +95,13 @@ public class QuantitativeDataDialogEditor extends AbstractDialogCellEditor {
         Feature feature = matrix.getIndexToFeatureMap().get(cell.getColumnIndex());
         QuantitativeData quantitativeData = null;
         if(rowObject instanceof RowWrapperDTO){
-            if(cell.getDataValue() instanceof QuantitativeData){
-                quantitativeData = (QuantitativeData) cell.getDataValue();
+            rowWrapperDTO = (RowWrapperDTO<?>) rowObject;
+            DescriptionElementBase dataValueForFeature = rowWrapperDTO.getDataValueForFeature(feature);
+            if(dataValueForFeature instanceof QuantitativeData){
+                quantitativeData = (QuantitativeData) dataValueForFeature;
             }
             //create new Quantitative Data
-            if (cell.getDataValue() == null) {
+            if (quantitativeData == null) {
                 quantitativeData = ((RowWrapperDTO) rowObject).addQuantitativeData(feature);
             }
             /**