Project

General

Profile

Download (4.09 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.HashMap;
12
import java.util.List;
13
import java.util.Map;
14
import java.util.Map.Entry;
15
import java.util.Set;
16
import java.util.stream.Collectors;
17

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

    
29
import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
30
import eu.etaxonomy.cdm.model.description.QuantitativeData;
31
import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
32
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrix;
33

    
34
/**
35
 * @author pplitzner
36
 * @since Jul 19, 2018
37
 *
38
 */
39
public class QuantitativeDataDialog extends CellEditDialog {
40

    
41
    private Character initialInput;
42

    
43
    private CharacterMatrix matrix;
44

    
45
    public QuantitativeDataDialog(Character initialInput, CharacterMatrix matrix, Shell parentShell, Object originalCanonicalValue, ILayerCell cell,
46
            ICellEditor cellEditor, IConfigRegistry configRegistry) {
47
        super(parentShell, originalCanonicalValue, cell, cellEditor, configRegistry);
48
        this.initialInput = initialInput;
49
        this.matrix = matrix;
50
    }
51

    
52
    private QuantitativeData editorValue;
53
    private RowWrapperDTO<?> rowWrapperDTO;
54

    
55
    private QuantitativeDataDialogComposite composite;
56

    
57
    @Override
58
    protected Control createDialogArea(Composite parent) {
59
        composite = new QuantitativeDataDialogComposite(initialInput, editorValue, parent, SWT.NONE);
60
        return composite;
61
    }
62

    
63
    void setEditorValue(QuantitativeData editorValue) {
64
        this.editorValue = editorValue;
65
    }
66

    
67
    void setRowWrapper(RowWrapperDTO<?> rowWrapperDTO) {
68
        this.rowWrapperDTO = rowWrapperDTO;
69
    }
70

    
71
    @Override
72
    public boolean close() {
73
        if(getReturnCode()==Window.OK){
74
            //clear values
75
            editorValue.getStatisticalValues().clear();
76
            //add back all values from text fields
77
            Map<StatisticalMeasure, List<String>> measureToValueMap = new HashMap<>();
78

    
79
            Map<StatisticalMeasure, List<Text>> textFields = composite.getTextFields();
80
            Set<Entry<StatisticalMeasure,List<Text>>> entrySet = textFields.entrySet();
81
            for (Entry<StatisticalMeasure, List<Text>> entry : entrySet) {
82
                StatisticalMeasure statisticalMeasure = entry.getKey();
83
                List<String> values = entry.getValue().stream()
84
                        .filter(text->text.isEnabled())
85
                        .map(text->text.getText())
86
                        .collect(Collectors.toList());
87
                measureToValueMap.put(statisticalMeasure, values);
88
            }
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);
98
            matrix.setDirty();
99
        }
100
        return super.close();
101
    }
102

    
103
}
(1-1/5)