ref #8791: add unit to quantitative data dialog
authorKatja Luther <k.luther@bgbm.org>
Wed, 22 Jan 2020 14:08:10 +0000 (15:08 +0100)
committerKatja Luther <k.luther@bgbm.org>
Wed, 22 Jan 2020 14:08:10 +0000 (15:08 +0100)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.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/QuantitativeDataDialogComposite.java

index ad2c0b0bbfe93eb5298134a1b31540310d239b5c..57fbd72a2d827a597b39cb581c36ba53ad1997e1 100644 (file)
@@ -616,10 +616,10 @@ public class CharacterMatrix extends Composite {
         //show unit for quantitative data
         if(feature.isSupportsQuantitativeData()){
             Set<MeasurementUnit> 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$
index 797e1081e681b9ddb16eb8bf4987e15669d15d6f..bbc9f9548a285a83fec25638f94728c67c76de2e 100644 (file)
@@ -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();
index caaafbbcb56c47fdfd88512ef5d5b54e6eda514e..528ee3793c5c6230984fb48649fc24e4f3ff9b4e 100644 (file)
@@ -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<StatisticalMeasure, List<Text>> textFieldMap = new HashMap<>();
+    QuantitativeData editorValue;
+    Combo unitCombo;
+    Map<MeasurementUnit, Integer> 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<MeasurementUnit, Integer> 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;
+    }
+
 }