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.List;
|
14
|
|
15
|
import org.eclipse.swt.SWT;
|
16
|
import org.eclipse.swt.custom.ScrolledComposite;
|
17
|
import org.eclipse.swt.events.SelectionAdapter;
|
18
|
import org.eclipse.swt.events.SelectionEvent;
|
19
|
import org.eclipse.swt.layout.GridData;
|
20
|
import org.eclipse.swt.layout.GridLayout;
|
21
|
import org.eclipse.swt.widgets.Button;
|
22
|
import org.eclipse.swt.widgets.Composite;
|
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.taxeditor.model.ImageResources;
|
28
|
|
29
|
/**
|
30
|
* @author pplitzner
|
31
|
* @date 16.07.2018
|
32
|
*
|
33
|
*/
|
34
|
public class QuantitativeDataDialogComposite extends Composite {
|
35
|
|
36
|
private List<Text> textFields = new ArrayList<>();
|
37
|
|
38
|
public QuantitativeDataDialogComposite(Character initialInput, QuantitativeData editorValue, Composite parent, int style) {
|
39
|
super(parent, style);
|
40
|
setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
|
41
|
|
42
|
setLayout(new GridLayout(1, false));
|
43
|
|
44
|
|
45
|
ScrolledComposite scrolledComposite_1 = new ScrolledComposite(this, SWT.BORDER | SWT.V_SCROLL);
|
46
|
scrolledComposite_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
|
47
|
scrolledComposite_1.setExpandHorizontal(true);
|
48
|
scrolledComposite_1.setExpandVertical(true);
|
49
|
|
50
|
Composite valuesComposite = new Composite(scrolledComposite_1, SWT.NONE);
|
51
|
valuesComposite.setLayout(new GridLayout());
|
52
|
|
53
|
//add empty text field
|
54
|
Text emptyTextField = addValue(initialInput==null?null:initialInput.toString(), valuesComposite);
|
55
|
emptyTextField.setFocus();
|
56
|
emptyTextField.setSelection(emptyTextField.getText().length());
|
57
|
|
58
|
//add exisiting values
|
59
|
editorValue.getStatisticalValues().stream()
|
60
|
.filter(value->value.getType().equals(StatisticalMeasure.EXACT_VALUE()))
|
61
|
.forEach(exact->addValue(Float.toString(exact.getValue()), valuesComposite));
|
62
|
|
63
|
|
64
|
scrolledComposite_1.setContent(valuesComposite);
|
65
|
scrolledComposite_1.setMinSize(valuesComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
|
66
|
}
|
67
|
|
68
|
private Text addValue(String value, Composite valuesComposite) {
|
69
|
Composite composite_2 = new Composite(valuesComposite, SWT.NONE);
|
70
|
composite_2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
|
71
|
composite_2.setLayout(new GridLayout(2, false));
|
72
|
|
73
|
Text text = new Text(composite_2, SWT.BORDER);
|
74
|
text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
|
75
|
if(value!=null){
|
76
|
text.setText(value);
|
77
|
}
|
78
|
textFields.add(text);
|
79
|
|
80
|
Button btnNewButton_2 = new Button(composite_2, SWT.NONE);
|
81
|
btnNewButton_2.setImage(ImageResources.getImage(ImageResources.ACTIVE_DELETE_ICON));
|
82
|
btnNewButton_2.addSelectionListener(new SelectionAdapter() {
|
83
|
@Override
|
84
|
public void widgetSelected(SelectionEvent e) {
|
85
|
text.setText("");
|
86
|
textFields.remove(text);
|
87
|
((GridData)composite_2.getLayoutData()).exclude = true;
|
88
|
valuesComposite.layout();
|
89
|
}
|
90
|
});
|
91
|
return text;
|
92
|
}
|
93
|
|
94
|
public List<Text> getTextFields() {
|
95
|
return textFields;
|
96
|
}
|
97
|
|
98
|
}
|