From: Patrick Plitzner Date: Thu, 19 Sep 2019 07:55:41 +0000 (+0200) Subject: ref #8450 Create and cache label for quantitative data in row wrapper X-Git-Tag: 5.10.0~2^2~13 X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/commitdiff_plain/c335a01c5842d8e424159034815438d35500ddc5 ref #8450 Create and cache label for quantitative data in row wrapper --- diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/SpecimenColumnPropertyAccessor.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/SpecimenColumnPropertyAccessor.java index 497034aec..72bd65ff3 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/SpecimenColumnPropertyAccessor.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/SpecimenColumnPropertyAccessor.java @@ -87,7 +87,9 @@ public class SpecimenColumnPropertyAccessor implements IColumnPropertyAccessoro instanceof TermDto)){ + if(feature.isSupportsCategoricalData() + && newValue instanceof Collection + && ((Collection) newValue).stream().allMatch(o->o instanceof TermDto)){ List dtos = (List)newValue; List termUuids = dtos.stream().map(dto->dto.getUuid()).collect(Collectors.toList()); List terms = CdmStore.getService(ITermService.class).load(termUuids, null); @@ -97,7 +99,7 @@ public class SpecimenColumnPropertyAccessor implements IColumnPropertyAccessor 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> measureToValueMap = new HashMap<>(); + + Map> textFields = composite.getTextFields(); + Set>> entrySet = textFields.entrySet(); + for (Entry> entry : entrySet) { + StatisticalMeasure statisticalMeasure = entry.getKey(); + List 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> 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) { - } - } - }); - }); - } - } diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataDialogEditor.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataDialogEditor.java index 215b4be1d..c109621d2 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataDialogEditor.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataDialogEditor.java @@ -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); } /**