From: Katja Luther Date: Wed, 22 Jan 2020 14:08:10 +0000 (+0100) Subject: ref #8791: add unit to quantitative data dialog X-Git-Tag: 5.13.0^2~119 X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/commitdiff_plain/b0127ea95d5cc141bec16f5244bf57af42a349a8 ref #8791: add unit to quantitative data dialog --- diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java index ad2c0b0bb..57fbd72a2 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java @@ -616,10 +616,10 @@ public class CharacterMatrix extends Composite { //show unit for quantitative data if(feature.isSupportsQuantitativeData()){ Set recommendedMeasurementUnits = feature.getRecommendedMeasurementUnits(); - if(recommendedMeasurementUnits.size()>1){ - MessagingUtils.warningDialog(Messages.CharacterMatrix_INIT_PROBLEM, CharacterMatrix.class, - String.format(Messages.CharacterMatrix_INIT_PROBLEM_MESSAGE, feature.getLabel())); - } +// if(recommendedMeasurementUnits.size()>1){ +// MessagingUtils.warningDialog(Messages.CharacterMatrix_INIT_PROBLEM, CharacterMatrix.class, +// String.format(Messages.CharacterMatrix_INIT_PROBLEM_MESSAGE, feature.getLabel())); +// } if(recommendedMeasurementUnits.size()==1){ MeasurementUnit unit = recommendedMeasurementUnits.iterator().next(); label += " ["+unit.getIdInVocabulary()+"]"; //$NON-NLS-1$ //$NON-NLS-2$ diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataDialog.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataDialog.java index 797e1081e..bbc9f9548 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataDialog.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataDialog.java @@ -86,7 +86,15 @@ public class QuantitativeDataDialog extends CellEditDialog { .collect(Collectors.toList()); measureToValueMap.put(statisticalMeasure, values); } - rowWrapperDTO.setDataValueForQuantitativeData(editorValue.getFeature(), measureToValueMap); + rowWrapperDTO.setDataValueForQuantitativeData(editorValue.getFeature(), measureToValueMap, composite.getEditorValue().getUnit()); +// if (composite.getEditorValue().getUnit() == null && (composite.getEditorValue().getFeature().getRecommendedMeasurementUnits() != null && composite.getEditorValue().getFeature().getRecommendedMeasurementUnits().size() == 1)){ +// editorValue.setUnit(editorValue.getFeature().getRecommendedMeasurementUnits().iterator().next()); +// }else{ +// editorValue.setUnit(composite.getEditorValue().getUnit()); +// } + +// ((QuantitativeData)rowWrapperDTO.getDataValueForFeature(editorValue.getFeature())).setUnit(editorValue.getUnit()); + matrix.addRowToSave(rowWrapperDTO); matrix.setDirty(); } return super.close(); diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataDialogComposite.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataDialogComposite.java index caaafbbcb..528ee3793 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataDialogComposite.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataDialogComposite.java @@ -13,6 +13,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.ScrolledComposite; @@ -21,11 +22,13 @@ import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; import eu.etaxonomy.cdm.common.CdmUtils; +import eu.etaxonomy.cdm.model.description.MeasurementUnit; import eu.etaxonomy.cdm.model.description.QuantitativeData; import eu.etaxonomy.cdm.model.description.StatisticalMeasure; import eu.etaxonomy.taxeditor.model.ImageResources; @@ -38,9 +41,22 @@ import eu.etaxonomy.taxeditor.model.ImageResources; public class QuantitativeDataDialogComposite extends Composite { private Map> textFieldMap = new HashMap<>(); + QuantitativeData editorValue; + Combo unitCombo; + Map unitMap = null; - public QuantitativeDataDialogComposite(Character initialInput, QuantitativeData editorValue, Composite parent, int style) { + public QuantitativeDataDialogComposite(Character initialInput, QuantitativeData editorVal, Composite parent, int style) { super(parent, style); + this.editorValue = editorVal; + if (editorValue.getFeature().getRecommendedMeasurementUnits() != null && editorValue.getFeature().getRecommendedMeasurementUnits().size()>0){ + unitMap = new HashMap<>(); + Integer i = 0; + for (MeasurementUnit unit: editorValue.getFeature().getRecommendedMeasurementUnits()){ + unitMap.put(unit, i); + i++; + } + } + setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); setLayout(new GridLayout(1, false)); @@ -56,6 +72,44 @@ public class QuantitativeDataDialogComposite extends Composite { gl_valuesComposite.marginHeight = 0; valuesComposite.setLayout(gl_valuesComposite); + Composite composite_2 = new Composite(valuesComposite, SWT.NONE); + composite_2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); + GridLayout gl_composite_2 = new GridLayout(2, false); + gl_composite_2.marginHeight = 0; + gl_composite_2.marginWidth = 0; + gl_composite_2.verticalSpacing = 0; + gl_composite_2.horizontalSpacing = 2; + composite_2.setLayout(gl_composite_2); + + Label lblNewLabel = new Label(composite_2, SWT.NONE); + lblNewLabel.setText("Measurement Unit"); + lblNewLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + if (editorValue.getFeature().getRecommendedMeasurementUnits() != null && editorValue.getFeature().getRecommendedMeasurementUnits().size() == 1){ + Label lblUnit = new Label(composite_2, SWT.BORDER); + lblUnit.setText(editorValue.getFeature().getRecommendedMeasurementUnits().iterator().next().getLabel()); + lblUnit.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + }else if (editorValue.getFeature().getRecommendedMeasurementUnits() != null && editorValue.getFeature().getRecommendedMeasurementUnits().size() > 1){ + unitCombo = new Combo(composite_2, SWT.NONE | SWT.READ_ONLY); + unitCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + for (Entry unit: unitMap.entrySet()){ + unitCombo.add(unit.getKey().getTitleCache(), unit.getValue()); + unitCombo.setData(unit.getKey().getTitleCache(), unit.getKey()); + } + if (editorValue.getUnit()!= null){ + unitCombo.select(unitMap.get(editorValue.getUnit())); + } + + unitCombo.addSelectionListener(new SelectionAdapter(){ + + @Override + public void widgetSelected(SelectionEvent e) { + String name = unitCombo.getText(); + editorValue.setUnit((MeasurementUnit)unitCombo.getData(name)); + } + + }); + } + //add empty text field for exact value Text emptyTextField = addText(valuesComposite, StatisticalMeasure.EXACT_VALUE(), initialInput==null?null:initialInput.toString()); emptyTextField.setFocus(); @@ -97,7 +151,10 @@ public class QuantitativeDataDialogComposite extends Composite { lblNewLabel.setText(type.getLabel()); Text text = new Text(composite_2, SWT.BORDER); - text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + + GridData gd_text = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1); + gd_text.widthHint = 15; + text.setLayoutData(gd_text); if(value!=null){ text.setText(value); } @@ -143,4 +200,8 @@ public class QuantitativeDataDialogComposite extends Composite { return textFieldMap; } + public QuantitativeData getEditorValue() { + return editorValue; + } + }