Project

General

Profile

Download (2.94 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2018 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative;
10

    
11
import java.util.List;
12
import java.util.stream.Collectors;
13

    
14
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
15
import org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor;
16
import org.eclipse.nebula.widgets.nattable.edit.gui.CellEditDialog;
17
import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
18
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.widgets.Composite;
20
import org.eclipse.swt.widgets.Control;
21
import org.eclipse.swt.widgets.Shell;
22
import org.eclipse.swt.widgets.Text;
23

    
24
import eu.etaxonomy.cdm.model.description.QuantitativeData;
25
import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
26
import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue;
27

    
28
/**
29
 * @author pplitzner
30
 * @since Jul 19, 2018
31
 *
32
 */
33
public class QuantitativeDataDialog extends CellEditDialog {
34

    
35
    private Character initialInput;
36

    
37
    public QuantitativeDataDialog(Character initialInput, Shell parentShell, Object originalCanonicalValue, ILayerCell cell,
38
            ICellEditor cellEditor, IConfigRegistry configRegistry) {
39
        super(parentShell, originalCanonicalValue, cell, cellEditor, configRegistry);
40
        this.initialInput = initialInput;
41
    }
42

    
43
    private QuantitativeData editorValue;
44

    
45
    private QuantitativeDataDialogComposite composite;
46

    
47
    @Override
48
    protected Control createDialogArea(Composite parent) {
49
        composite = new QuantitativeDataDialogComposite(initialInput, editorValue, parent, SWT.NONE);
50
        return composite;
51
    }
52

    
53
    void setEditorValue(QuantitativeData editorValue) {
54
        this.editorValue = editorValue;
55
    }
56

    
57
    void updateQuantitativeData(QuantitativeData object){
58
        QuantitativeData quantitativeData = object;
59
        //get all non-exact values
60
        List<StatisticalMeasurementValue> values = quantitativeData.getStatisticalValues().stream()
61
                .filter(value->!value.getType().equals(StatisticalMeasure.EXACT_VALUE()))
62
                .collect(Collectors.toList());
63
        //clear values
64
        quantitativeData.getStatisticalValues().clear();
65
        //add back all non-exact values
66
        values.forEach(value->quantitativeData.addStatisticalValue(value));
67
        //get exact values from text fields
68
        List<Text> textFields = composite.getTextFields();
69
        for (Text text : textFields) {
70
            String string = text.getText();
71
            try {
72
                float exactValue = Float.parseFloat(string);
73
                quantitativeData.addStatisticalValue(StatisticalMeasurementValue.NewInstance(StatisticalMeasure.EXACT_VALUE(), exactValue));
74
            } catch (NumberFormatException e) {
75
            }
76
        }
77

    
78
    }
79

    
80
}
(3-3/7)