Project

General

Profile

Revision b0127ea9

IDb0127ea95d5cc141bec16f5244bf57af42a349a8
Parent 72836bf3
Child b19e08c1

Added by Katja Luther 7 months ago

ref #8791: add unit to quantitative data dialog

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java
616 616
        //show unit for quantitative data
617 617
        if(feature.isSupportsQuantitativeData()){
618 618
            Set<MeasurementUnit> recommendedMeasurementUnits = feature.getRecommendedMeasurementUnits();
619
            if(recommendedMeasurementUnits.size()>1){
620
                MessagingUtils.warningDialog(Messages.CharacterMatrix_INIT_PROBLEM, CharacterMatrix.class,
621
                        String.format(Messages.CharacterMatrix_INIT_PROBLEM_MESSAGE, feature.getLabel()));
622
            }
619
//            if(recommendedMeasurementUnits.size()>1){
620
//                MessagingUtils.warningDialog(Messages.CharacterMatrix_INIT_PROBLEM, CharacterMatrix.class,
621
//                        String.format(Messages.CharacterMatrix_INIT_PROBLEM_MESSAGE, feature.getLabel()));
622
//            }
623 623
            if(recommendedMeasurementUnits.size()==1){
624 624
                MeasurementUnit unit = recommendedMeasurementUnits.iterator().next();
625 625
                label += " ["+unit.getIdInVocabulary()+"]"; //$NON-NLS-1$ //$NON-NLS-2$
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataDialog.java
86 86
                        .collect(Collectors.toList());
87 87
                measureToValueMap.put(statisticalMeasure, values);
88 88
            }
89
            rowWrapperDTO.setDataValueForQuantitativeData(editorValue.getFeature(), measureToValueMap);
89
            rowWrapperDTO.setDataValueForQuantitativeData(editorValue.getFeature(), measureToValueMap, composite.getEditorValue().getUnit());
90
//            if (composite.getEditorValue().getUnit() == null && (composite.getEditorValue().getFeature().getRecommendedMeasurementUnits() != null && composite.getEditorValue().getFeature().getRecommendedMeasurementUnits().size() == 1)){
91
//                editorValue.setUnit(editorValue.getFeature().getRecommendedMeasurementUnits().iterator().next());
92
//            }else{
93
//                editorValue.setUnit(composite.getEditorValue().getUnit());
94
//            }
95

  
96
//            ((QuantitativeData)rowWrapperDTO.getDataValueForFeature(editorValue.getFeature())).setUnit(editorValue.getUnit());
97
            matrix.addRowToSave(rowWrapperDTO);
90 98
            matrix.setDirty();
91 99
        }
92 100
        return super.close();
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataDialogComposite.java
13 13
import java.util.HashMap;
14 14
import java.util.List;
15 15
import java.util.Map;
16
import java.util.Map.Entry;
16 17

  
17 18
import org.eclipse.swt.SWT;
18 19
import org.eclipse.swt.custom.ScrolledComposite;
......
21 22
import org.eclipse.swt.layout.GridData;
22 23
import org.eclipse.swt.layout.GridLayout;
23 24
import org.eclipse.swt.widgets.Button;
25
import org.eclipse.swt.widgets.Combo;
24 26
import org.eclipse.swt.widgets.Composite;
25 27
import org.eclipse.swt.widgets.Label;
26 28
import org.eclipse.swt.widgets.Text;
27 29

  
28 30
import eu.etaxonomy.cdm.common.CdmUtils;
31
import eu.etaxonomy.cdm.model.description.MeasurementUnit;
29 32
import eu.etaxonomy.cdm.model.description.QuantitativeData;
30 33
import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
31 34
import eu.etaxonomy.taxeditor.model.ImageResources;
......
38 41
public class QuantitativeDataDialogComposite extends Composite {
39 42

  
40 43
    private Map<StatisticalMeasure, List<Text>> textFieldMap = new HashMap<>();
44
    QuantitativeData editorValue;
45
    Combo unitCombo;
46
    Map<MeasurementUnit, Integer> unitMap = null;
41 47

  
42
    public QuantitativeDataDialogComposite(Character initialInput, QuantitativeData editorValue, Composite parent, int style) {
48
    public QuantitativeDataDialogComposite(Character initialInput, QuantitativeData editorVal, Composite parent, int style) {
43 49
        super(parent, style);
50
        this.editorValue = editorVal;
51
        if (editorValue.getFeature().getRecommendedMeasurementUnits() != null && editorValue.getFeature().getRecommendedMeasurementUnits().size()>0){
52
            unitMap = new HashMap<>();
53
            Integer i = 0;
54
            for (MeasurementUnit unit: editorValue.getFeature().getRecommendedMeasurementUnits()){
55
                unitMap.put(unit, i);
56
                i++;
57
            }
58
        }
59

  
44 60
        setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
45 61

  
46 62
        setLayout(new GridLayout(1, false));
......
56 72
        gl_valuesComposite.marginHeight = 0;
57 73
        valuesComposite.setLayout(gl_valuesComposite);
58 74

  
75
        Composite composite_2 = new Composite(valuesComposite, SWT.NONE);
76
        composite_2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
77
        GridLayout gl_composite_2 = new GridLayout(2, false);
78
        gl_composite_2.marginHeight = 0;
79
        gl_composite_2.marginWidth = 0;
80
        gl_composite_2.verticalSpacing = 0;
81
        gl_composite_2.horizontalSpacing = 2;
82
        composite_2.setLayout(gl_composite_2);
83

  
84
        Label lblNewLabel = new Label(composite_2, SWT.NONE);
85
        lblNewLabel.setText("Measurement Unit");
86
        lblNewLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
87
        if (editorValue.getFeature().getRecommendedMeasurementUnits() != null && editorValue.getFeature().getRecommendedMeasurementUnits().size() == 1){
88
            Label lblUnit = new Label(composite_2, SWT.BORDER);
89
            lblUnit.setText(editorValue.getFeature().getRecommendedMeasurementUnits().iterator().next().getLabel());
90
            lblUnit.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
91
        }else if (editorValue.getFeature().getRecommendedMeasurementUnits() != null && editorValue.getFeature().getRecommendedMeasurementUnits().size() > 1){
92
            unitCombo = new Combo(composite_2, SWT.NONE | SWT.READ_ONLY);
93
            unitCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
94
            for (Entry<MeasurementUnit, Integer> unit: unitMap.entrySet()){
95
                unitCombo.add(unit.getKey().getTitleCache(), unit.getValue());
96
                unitCombo.setData(unit.getKey().getTitleCache(), unit.getKey());
97
            }
98
            if (editorValue.getUnit()!= null){
99
                unitCombo.select(unitMap.get(editorValue.getUnit()));
100
            }
101

  
102
            unitCombo.addSelectionListener(new SelectionAdapter(){
103

  
104
                @Override
105
                public void widgetSelected(SelectionEvent e) {
106
                    String name = unitCombo.getText();
107
                    editorValue.setUnit((MeasurementUnit)unitCombo.getData(name));
108
                }
109

  
110
            });
111
        }
112

  
59 113
        //add empty text field for exact value
60 114
        Text emptyTextField = addText(valuesComposite, StatisticalMeasure.EXACT_VALUE(), initialInput==null?null:initialInput.toString());
61 115
        emptyTextField.setFocus();
......
97 151
        lblNewLabel.setText(type.getLabel());
98 152

  
99 153
        Text text = new Text(composite_2, SWT.BORDER);
100
        text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
154

  
155
        GridData gd_text = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
156
        gd_text.widthHint = 15;
157
        text.setLayoutData(gd_text);
101 158
        if(value!=null){
102 159
            text.setText(value);
103 160
        }
......
143 200
        return textFieldMap;
144 201
    }
145 202

  
203
    public QuantitativeData getEditorValue() {
204
        return editorValue;
205
    }
206

  
146 207
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)