Revision 302af519
Added by Patrick Plitzner almost 6 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataComposite.java | ||
---|---|---|
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 org.eclipse.swt.SWT; |
|
13 |
import org.eclipse.swt.layout.GridData; |
|
14 |
import org.eclipse.swt.layout.GridLayout; |
|
15 |
import org.eclipse.swt.widgets.Button; |
|
16 |
import org.eclipse.swt.widgets.Composite; |
|
17 |
import org.eclipse.swt.widgets.Text; |
|
18 |
|
|
19 |
/** |
|
20 |
* @author pplitzner |
|
21 |
* @date 17.07.2018 |
|
22 |
* |
|
23 |
*/ |
|
24 |
public class QuantitativeDataComposite extends Composite { |
|
25 |
private Text text; |
|
26 |
private Button btnAdvancedEdit; |
|
27 |
|
|
28 |
public QuantitativeDataComposite(Composite parent, int style) { |
|
29 |
super(parent, style); |
|
30 |
setLayout(new GridLayout(2, false)); |
|
31 |
|
|
32 |
text = new Text(this, SWT.BORDER); |
|
33 |
text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); |
|
34 |
|
|
35 |
btnAdvancedEdit = new Button(this, SWT.NONE); |
|
36 |
btnAdvancedEdit.setText("+"); |
|
37 |
// TODO Auto-generated constructor stub |
|
38 |
} |
|
39 |
|
|
40 |
public Text getText() { |
|
41 |
return text; |
|
42 |
} |
|
43 |
public Button getBtnAdvancedEdit() { |
|
44 |
return btnAdvancedEdit; |
|
45 |
} |
|
46 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataDialogComposite.java | ||
---|---|---|
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 org.eclipse.swt.SWT; |
|
13 |
import org.eclipse.swt.custom.ScrolledComposite; |
|
14 |
import org.eclipse.swt.layout.GridData; |
|
15 |
import org.eclipse.swt.layout.GridLayout; |
|
16 |
import org.eclipse.swt.widgets.Button; |
|
17 |
import org.eclipse.swt.widgets.Composite; |
|
18 |
import org.eclipse.swt.widgets.Label; |
|
19 |
import org.eclipse.swt.widgets.Text; |
|
20 |
|
|
21 |
/** |
|
22 |
* @author pplitzner |
|
23 |
* @date 16.07.2018 |
|
24 |
* |
|
25 |
*/ |
|
26 |
public class QuantitativeDataDialogComposite extends Composite { |
|
27 |
private Text text; |
|
28 |
|
|
29 |
public QuantitativeDataDialogComposite(Composite parent, int style) { |
|
30 |
super(parent, style); |
|
31 |
setLayout(new GridLayout(1, false)); |
|
32 |
|
|
33 |
|
|
34 |
ScrolledComposite scrolledComposite_1 = new ScrolledComposite(this, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); |
|
35 |
scrolledComposite_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); |
|
36 |
scrolledComposite_1.setExpandHorizontal(true); |
|
37 |
scrolledComposite_1.setExpandVertical(true); |
|
38 |
|
|
39 |
Composite composite_2 = new Composite(scrolledComposite_1, SWT.NONE); |
|
40 |
composite_2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); |
|
41 |
composite_2.setLayout(new GridLayout(3, false)); |
|
42 |
|
|
43 |
text = new Text(composite_2, SWT.BORDER); |
|
44 |
text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); |
|
45 |
|
|
46 |
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"); |
|
58 |
|
|
59 |
Button btnOk = new Button(bottomComposite, SWT.NONE); |
|
60 |
btnOk.setText("OK"); |
|
61 |
} |
|
62 |
|
|
63 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataExactValueCellEditor.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2017 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.Map; |
|
13 |
|
|
14 |
import org.eclipse.nebula.widgets.nattable.edit.editor.AbstractCellEditor; |
|
15 |
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum; |
|
16 |
import org.eclipse.swt.SWT; |
|
17 |
import org.eclipse.swt.widgets.Composite; |
|
18 |
import org.eclipse.swt.widgets.Control; |
|
19 |
import org.eclipse.swt.widgets.Listener; |
|
20 |
import org.eclipse.swt.widgets.Text; |
|
21 |
|
|
22 |
import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO; |
|
23 |
import eu.etaxonomy.cdm.model.description.Feature; |
|
24 |
import eu.etaxonomy.cdm.model.description.QuantitativeData; |
|
25 |
import eu.etaxonomy.cdm.model.description.StatisticalMeasure; |
|
26 |
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrix; |
|
27 |
|
|
28 |
/** |
|
29 |
* |
|
30 |
* Cell editor for QuantitativeData |
|
31 |
* @author pplitzner |
|
32 |
* @date 17.07.2018 |
|
33 |
* |
|
34 |
*/ |
|
35 |
public class QuantitativeDataExactValueCellEditor extends AbstractCellEditor{ |
|
36 |
|
|
37 |
private Control editorControl; |
|
38 |
|
|
39 |
private Feature feature; |
|
40 |
|
|
41 |
private Map<StatisticalMeasure, Text> measureToTextMap = new HashMap<>(); |
|
42 |
|
|
43 |
private Object editorValue; |
|
44 |
|
|
45 |
private CharacterMatrix matrix; |
|
46 |
|
|
47 |
private boolean dirty = false; |
|
48 |
|
|
49 |
private QuantitativeDataComposite dataComposite; |
|
50 |
|
|
51 |
public QuantitativeDataExactValueCellEditor(Feature feature, CharacterMatrix matrix) { |
|
52 |
super(); |
|
53 |
this.matrix = matrix; |
|
54 |
this.feature = feature; |
|
55 |
} |
|
56 |
|
|
57 |
|
|
58 |
@Override |
|
59 |
public Object getEditorValue() { |
|
60 |
return this.editorValue; |
|
61 |
} |
|
62 |
|
|
63 |
@Override |
|
64 |
public void setEditorValue(Object value) { |
|
65 |
this.editorValue = value; |
|
66 |
} |
|
67 |
|
|
68 |
@Override |
|
69 |
public Control getEditorControl() { |
|
70 |
return editorControl; |
|
71 |
} |
|
72 |
|
|
73 |
@Override |
|
74 |
public Control createEditorControl(Composite parent) { |
|
75 |
dataComposite = new QuantitativeDataComposite(parent, SWT.NONE); |
|
76 |
return dataComposite; |
|
77 |
} |
|
78 |
|
|
79 |
@Override |
|
80 |
public boolean commit(MoveDirectionEnum direction, boolean closeAfterCommit, boolean skipValidation) { |
|
81 |
if(dirty){ |
|
82 |
matrix.setDirty(); |
|
83 |
dirty = false; |
|
84 |
} |
|
85 |
return super.commit(direction, closeAfterCommit, skipValidation); |
|
86 |
} |
|
87 |
|
|
88 |
@Override |
|
89 |
protected Control activateCell(Composite parent, Object originalCanonicalValue) { |
|
90 |
Object rowObject = matrix.getBodyDataProvider().getRowObject(this.getRowIndex()); |
|
91 |
if(rowObject instanceof RowWrapperDTO){ |
|
92 |
this.editorControl = createEditorControl(parent); |
|
93 |
if(originalCanonicalValue==null){ |
|
94 |
originalCanonicalValue = ((RowWrapperDTO) rowObject).addQuantitativeData(feature); |
|
95 |
} |
|
96 |
this.setEditorValue(originalCanonicalValue); |
|
97 |
|
|
98 |
//Fill text controls with actual values and add modify listeners for editing |
|
99 |
if(originalCanonicalValue instanceof QuantitativeData){ |
|
100 |
QuantitativeData quantitativeData = (QuantitativeData)originalCanonicalValue; |
|
101 |
long exactValuesCount = quantitativeData.getStatisticalValues().stream() |
|
102 |
.filter(val->val.getType().equals(StatisticalMeasure.EXACT_VALUE())) |
|
103 |
.count(); |
|
104 |
if(exactValuesCount>1){ |
|
105 |
dataComposite.getText().setText("..."); |
|
106 |
dataComposite.getText().setEnabled(false); |
|
107 |
} |
|
108 |
else if(exactValuesCount==1){ |
|
109 |
Float exactValue = quantitativeData.getSpecificStatisticalValue(StatisticalMeasure.EXACT_VALUE()); |
|
110 |
dataComposite.getText().setText(exactValue.toString()); |
|
111 |
dataComposite.getText().addModifyListener(e->{ |
|
112 |
try { |
|
113 |
float parseFloat = Float.parseFloat(dataComposite.getText().getText()); |
|
114 |
quantitativeData.setSpecificStatisticalValue(parseFloat, null, StatisticalMeasure.EXACT_VALUE()); |
|
115 |
dirty = true; |
|
116 |
} catch (NumberFormatException|NullPointerException ex) { |
|
117 |
// ignore exception for wrong number format |
|
118 |
} |
|
119 |
}); |
|
120 |
} |
|
121 |
} |
|
122 |
} |
|
123 |
return this.editorControl; |
|
124 |
} |
|
125 |
|
|
126 |
private void setText(Float specificStatisticalValue, Text text){ |
|
127 |
if(specificStatisticalValue!=null){ |
|
128 |
Listener[] listeners = text.getListeners(SWT.Modify); |
|
129 |
for (Listener listener : listeners) { |
|
130 |
text.removeListener(SWT.Modify, listener); |
|
131 |
} |
|
132 |
text.setText(Float.toString(specificStatisticalValue)); |
|
133 |
for (Listener listener : listeners) { |
|
134 |
text.addListener(SWT.Modify, listener); |
|
135 |
} |
|
136 |
} |
|
137 |
} |
|
138 |
|
|
139 |
} |
Also available in: Unified diff
Implement QuantitativeData cell editor prototypes