Project

General

Profile

Download (3.08 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.Map;
13

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

    
25
import eu.etaxonomy.cdm.model.description.QuantitativeData;
26
import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
27
import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue;
28
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrix;
29

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

    
37
    private Character initialInput;
38

    
39
    private CharacterMatrix matrix;
40

    
41
    public QuantitativeDataDialog(Character initialInput, CharacterMatrix matrix, Shell parentShell, Object originalCanonicalValue, ILayerCell cell,
42
            ICellEditor cellEditor, IConfigRegistry configRegistry) {
43
        super(parentShell, originalCanonicalValue, cell, cellEditor, configRegistry);
44
        this.initialInput = initialInput;
45
        this.matrix = matrix;
46
    }
47

    
48
    private QuantitativeData editorValue;
49

    
50
    private QuantitativeDataDialogComposite composite;
51

    
52
    @Override
53
    protected Control createDialogArea(Composite parent) {
54
        composite = new QuantitativeDataDialogComposite(initialInput, editorValue, parent, SWT.NONE);
55
        return composite;
56
    }
57

    
58
    void setEditorValue(QuantitativeData editorValue) {
59
        this.editorValue = editorValue;
60
    }
61

    
62
    @Override
63
    public boolean close() {
64
        if(getReturnCode()==Window.OK){
65
            updateQuantitativeData(editorValue);
66
            matrix.setDirty();
67
        }
68
        return super.close();
69
    }
70

    
71
    void updateQuantitativeData(QuantitativeData quantitativeData){
72
        //clear values
73
        quantitativeData.getStatisticalValues().clear();
74
        //add back all values from text fields
75
        Map<StatisticalMeasure, List<Text>> textFields = composite.getTextFields();
76
        textFields.forEach((measure, texts)->{
77
            texts.forEach(text->{
78
                if(text.isEnabled()){
79
                    String string = text.getText();
80
                    try {
81
                        float exactValue = Float.parseFloat(string);
82
                        quantitativeData.addStatisticalValue(StatisticalMeasurementValue.NewInstance(measure, exactValue));
83
                    } catch (NumberFormatException e) {
84
                    }
85
                }
86
            });
87
        });
88
    }
89

    
90
}
(1-1/5)