1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2018 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative;
|
11
|
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.HashMap;
|
14
|
import java.util.List;
|
15
|
import java.util.Map;
|
16
|
|
17
|
import org.eclipse.swt.SWT;
|
18
|
import org.eclipse.swt.custom.ScrolledComposite;
|
19
|
import org.eclipse.swt.events.SelectionAdapter;
|
20
|
import org.eclipse.swt.events.SelectionEvent;
|
21
|
import org.eclipse.swt.layout.GridData;
|
22
|
import org.eclipse.swt.layout.GridLayout;
|
23
|
import org.eclipse.swt.widgets.Button;
|
24
|
import org.eclipse.swt.widgets.Composite;
|
25
|
import org.eclipse.swt.widgets.Label;
|
26
|
import org.eclipse.swt.widgets.Text;
|
27
|
|
28
|
import eu.etaxonomy.cdm.model.description.QuantitativeData;
|
29
|
import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
|
30
|
import eu.etaxonomy.taxeditor.model.ImageResources;
|
31
|
|
32
|
/**
|
33
|
* @author pplitzner
|
34
|
* @date 16.07.2018
|
35
|
*
|
36
|
*/
|
37
|
public class QuantitativeDataDialogComposite extends Composite {
|
38
|
|
39
|
private Map<StatisticalMeasure, List<Text>> textFieldMap = new HashMap<>();
|
40
|
|
41
|
public QuantitativeDataDialogComposite(Character initialInput, QuantitativeData editorValue, Composite parent, int style) {
|
42
|
super(parent, style);
|
43
|
setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
|
44
|
|
45
|
setLayout(new GridLayout(1, false));
|
46
|
|
47
|
ScrolledComposite scrolledComposite_1 = new ScrolledComposite(this, SWT.BORDER | SWT.V_SCROLL);
|
48
|
scrolledComposite_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
|
49
|
scrolledComposite_1.setExpandHorizontal(true);
|
50
|
scrolledComposite_1.setExpandVertical(true);
|
51
|
|
52
|
Composite valuesComposite = new Composite(scrolledComposite_1, SWT.NONE);
|
53
|
GridLayout gl_valuesComposite = new GridLayout();
|
54
|
gl_valuesComposite.marginWidth = 0;
|
55
|
gl_valuesComposite.marginHeight = 0;
|
56
|
valuesComposite.setLayout(gl_valuesComposite);
|
57
|
|
58
|
//add empty text field for exact value
|
59
|
Text emptyTextField = addText(valuesComposite, StatisticalMeasure.EXACT_VALUE(), initialInput==null?null:initialInput.toString());
|
60
|
emptyTextField.setFocus();
|
61
|
emptyTextField.setSelection(emptyTextField.getText().length());
|
62
|
|
63
|
//add existing exact values
|
64
|
editorValue.getStatisticalValues().stream()
|
65
|
.filter(measure->measure.getType().equals(StatisticalMeasure.EXACT_VALUE()))
|
66
|
.forEach(exact->addText(valuesComposite, exact.getType(), Float.toString(exact.getValue())));
|
67
|
|
68
|
//add aggregation values
|
69
|
editorValue.getFeature().getRecommendedStatisticalMeasures()
|
70
|
.stream()
|
71
|
.filter(sm->!sm.equals(StatisticalMeasure.EXACT_VALUE()))
|
72
|
.forEach(measure->{
|
73
|
Float specificStatisticalValue = editorValue.getSpecificStatisticalValue(measure);
|
74
|
addText(valuesComposite, measure, specificStatisticalValue!=null?Float.toString(specificStatisticalValue):null);
|
75
|
});
|
76
|
|
77
|
scrolledComposite_1.setContent(valuesComposite);
|
78
|
scrolledComposite_1.setMinSize(valuesComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
|
79
|
}
|
80
|
|
81
|
private Text addText(Composite valuesComposite, StatisticalMeasure type, String value){
|
82
|
Composite composite_2 = new Composite(valuesComposite, SWT.NONE);
|
83
|
composite_2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
|
84
|
GridLayout gl_composite_2 = new GridLayout(4, false);
|
85
|
gl_composite_2.marginHeight = 0;
|
86
|
gl_composite_2.marginWidth = 0;
|
87
|
gl_composite_2.verticalSpacing = 0;
|
88
|
gl_composite_2.horizontalSpacing = 2;
|
89
|
composite_2.setLayout(gl_composite_2);
|
90
|
|
91
|
Label lblNewLabel = new Label(composite_2, SWT.NONE);
|
92
|
lblNewLabel.setText(type.getLabel().substring(0, 3));
|
93
|
|
94
|
Text text = new Text(composite_2, SWT.BORDER);
|
95
|
text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
|
96
|
if(value!=null){
|
97
|
text.setText(value);
|
98
|
}
|
99
|
|
100
|
List<Text> list = textFieldMap.get(type);
|
101
|
if(list==null){
|
102
|
list = new ArrayList<>();
|
103
|
}
|
104
|
textFieldMap.put(type, list);
|
105
|
list.add(text);
|
106
|
|
107
|
Button btnNewButton_2 = new Button(composite_2, SWT.NONE);
|
108
|
btnNewButton_2.setImage(ImageResources.getImage(ImageResources.TRASH_ICON));
|
109
|
new Label(composite_2, SWT.NONE);
|
110
|
btnNewButton_2.addSelectionListener(new SelectionAdapter() {
|
111
|
@Override
|
112
|
public void widgetSelected(SelectionEvent e) {
|
113
|
text.setText("");
|
114
|
}
|
115
|
});
|
116
|
return text;
|
117
|
}
|
118
|
|
119
|
public Map<StatisticalMeasure, List<Text>> getTextFields() {
|
120
|
return textFieldMap;
|
121
|
}
|
122
|
|
123
|
}
|