Revision b119ef11
Added by Patrick Plitzner almost 6 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataDialogComposite.java | ||
---|---|---|
9 | 9 |
*/ |
10 | 10 |
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative; |
11 | 11 |
|
12 |
import java.util.ArrayList; |
|
13 |
import java.util.List; |
|
14 |
|
|
12 | 15 |
import org.eclipse.swt.SWT; |
13 | 16 |
import org.eclipse.swt.custom.ScrolledComposite; |
17 |
import org.eclipse.swt.events.SelectionAdapter; |
|
18 |
import org.eclipse.swt.events.SelectionEvent; |
|
14 | 19 |
import org.eclipse.swt.layout.GridData; |
15 | 20 |
import org.eclipse.swt.layout.GridLayout; |
16 | 21 |
import org.eclipse.swt.widgets.Button; |
17 | 22 |
import org.eclipse.swt.widgets.Composite; |
18 |
import org.eclipse.swt.widgets.Label; |
|
19 | 23 |
import org.eclipse.swt.widgets.Text; |
20 | 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 |
|
|
21 | 29 |
/** |
22 | 30 |
* @author pplitzner |
23 | 31 |
* @date 16.07.2018 |
24 | 32 |
* |
25 | 33 |
*/ |
26 | 34 |
public class QuantitativeDataDialogComposite extends Composite { |
27 |
private Text text; |
|
28 | 35 |
|
29 |
public QuantitativeDataDialogComposite(Composite parent, int style) { |
|
36 |
private List<Text> textFields = new ArrayList<>(); |
|
37 |
|
|
38 |
public QuantitativeDataDialogComposite(Character initialInput, QuantitativeData editorValue, Composite parent, int style) { |
|
30 | 39 |
super(parent, style); |
40 |
setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); |
|
41 |
|
|
31 | 42 |
setLayout(new GridLayout(1, false)); |
32 | 43 |
|
33 | 44 |
|
34 |
ScrolledComposite scrolledComposite_1 = new ScrolledComposite(this, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
|
|
45 |
ScrolledComposite scrolledComposite_1 = new ScrolledComposite(this, SWT.BORDER | SWT.V_SCROLL); |
|
35 | 46 |
scrolledComposite_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); |
36 | 47 |
scrolledComposite_1.setExpandHorizontal(true); |
37 | 48 |
scrolledComposite_1.setExpandVertical(true); |
38 | 49 |
|
39 |
Composite composite_2 = new Composite(scrolledComposite_1, SWT.NONE); |
|
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); |
|
40 | 70 |
composite_2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); |
41 |
composite_2.setLayout(new GridLayout(3, false));
|
|
71 |
composite_2.setLayout(new GridLayout(2, false));
|
|
42 | 72 |
|
43 |
text = new Text(composite_2, SWT.BORDER); |
|
73 |
Text text = new Text(composite_2, SWT.BORDER);
|
|
44 | 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); |
|
45 | 79 |
|
46 | 80 |
Button btnNewButton_2 = new Button(composite_2, SWT.NONE); |
47 |
btnNewButton_2.setText("Remove"); |
|
48 |
new Label(composite_2, SWT.NONE); |
|
49 |
scrolledComposite_1.setContent(composite_2); |
|
50 |
scrolledComposite_1.setMinSize(composite_2.computeSize(SWT.DEFAULT, SWT.DEFAULT)); |
|
51 |
|
|
52 |
Composite bottomComposite = new Composite(this, SWT.NONE); |
|
53 |
bottomComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1)); |
|
54 |
bottomComposite.setLayout(new GridLayout(2, false)); |
|
55 |
|
|
56 |
Button btnAddValue = new Button(bottomComposite, SWT.NONE); |
|
57 |
btnAddValue.setText("Add"); |
|
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 |
} |
|
58 | 93 |
|
59 |
Button btnOk = new Button(bottomComposite, SWT.NONE);
|
|
60 |
btnOk.setText("OK");
|
|
94 |
public List<Text> getTextFields() {
|
|
95 |
return textFields;
|
|
61 | 96 |
} |
62 | 97 |
|
63 | 98 |
} |
Also available in: Unified diff
ref #7575 Add (still disabled) quantitative dialog cell editor