Revision c42c7bec
Added by Patrick Plitzner over 6 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/quantitative/QuantitativeDataCellEditor.java | ||
---|---|---|
13 | 13 |
import java.util.Set; |
14 | 14 |
|
15 | 15 |
import org.eclipse.nebula.widgets.nattable.edit.editor.AbstractCellEditor; |
16 |
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum; |
|
16 | 17 |
import org.eclipse.swt.SWT; |
17 | 18 |
import org.eclipse.swt.layout.FillLayout; |
18 | 19 |
import org.eclipse.swt.layout.GridData; |
... | ... | |
20 | 21 |
import org.eclipse.swt.widgets.Composite; |
21 | 22 |
import org.eclipse.swt.widgets.Control; |
22 | 23 |
import org.eclipse.swt.widgets.Label; |
24 |
import org.eclipse.swt.widgets.Listener; |
|
23 | 25 |
import org.eclipse.swt.widgets.Text; |
24 | 26 |
|
25 |
import eu.etaxonomy.cdm.model.description.CategoricalData;
|
|
27 |
import eu.etaxonomy.cdm.model.description.QuantitativeData;
|
|
26 | 28 |
import eu.etaxonomy.cdm.model.description.StatisticalMeasure; |
29 |
import eu.etaxonomy.taxeditor.editor.workingSet.matrix.CharacterMatrix; |
|
27 | 30 |
|
28 | 31 |
/** |
29 | 32 |
* @author pplitzner |
... | ... | |
38 | 41 |
|
39 | 42 |
private Map<StatisticalMeasure, Text> measureToTextMap = new HashMap<>(); |
40 | 43 |
|
41 |
public QuantitativeDataCellEditor(Set<StatisticalMeasure> statisticalMeasures) { |
|
44 |
private Object editorValue; |
|
45 |
|
|
46 |
private CharacterMatrix matrix; |
|
47 |
|
|
48 |
private boolean dirty = false; |
|
49 |
|
|
50 |
public QuantitativeDataCellEditor(Set<StatisticalMeasure> statisticalMeasures, CharacterMatrix matrix) { |
|
42 | 51 |
super(); |
52 |
this.matrix = matrix; |
|
43 | 53 |
this.statisticalMeasures = statisticalMeasures; |
44 | 54 |
} |
45 | 55 |
|
56 |
|
|
46 | 57 |
/** |
47 | 58 |
* {@inheritDoc} |
48 | 59 |
*/ |
49 | 60 |
@Override |
50 | 61 |
public Object getEditorValue() { |
51 |
return null;
|
|
62 |
return this.editorValue;
|
|
52 | 63 |
} |
53 | 64 |
|
54 | 65 |
/** |
... | ... | |
56 | 67 |
*/ |
57 | 68 |
@Override |
58 | 69 |
public void setEditorValue(Object value) { |
59 |
if(value instanceof CategoricalData){ |
|
60 |
} |
|
70 |
this.editorValue = value; |
|
61 | 71 |
} |
62 | 72 |
|
63 | 73 |
/** |
... | ... | |
101 | 111 |
return composite; |
102 | 112 |
} |
103 | 113 |
|
114 |
/** |
|
115 |
* {@inheritDoc} |
|
116 |
*/ |
|
117 |
@Override |
|
118 |
public boolean commit(MoveDirectionEnum direction, boolean closeAfterCommit, boolean skipValidation) { |
|
119 |
if(dirty){ |
|
120 |
matrix.setDirty(); |
|
121 |
dirty = false; |
|
122 |
} |
|
123 |
return super.commit(direction, closeAfterCommit, skipValidation); |
|
124 |
} |
|
125 |
|
|
104 | 126 |
/** |
105 | 127 |
* {@inheritDoc} |
106 | 128 |
*/ |
107 | 129 |
@Override |
108 | 130 |
protected Control activateCell(Composite parent, Object originalCanonicalValue) { |
109 |
System.out.println(originalCanonicalValue); |
|
110 | 131 |
this.editorControl = createEditorControl(parent); |
132 |
this.setEditorValue(originalCanonicalValue); |
|
133 |
|
|
134 |
if(originalCanonicalValue instanceof QuantitativeData){ |
|
135 |
QuantitativeData quantitativeData = (QuantitativeData)originalCanonicalValue; |
|
136 |
Set<StatisticalMeasure> statisticalValues = quantitativeData.getFeature().getRecommendedStatisticalMeasures(); |
|
137 |
//Fill text controls with actual values and add modify listeners for editing |
|
138 |
for (StatisticalMeasure value : statisticalValues) { |
|
139 |
Text text = measureToTextMap.get(value); |
|
140 |
text.addModifyListener(e->{ |
|
141 |
quantitativeData.setSpecificStatisticalValue(Float.parseFloat(text.getText()), null, value); |
|
142 |
dirty = true; |
|
143 |
}); |
|
144 |
|
|
145 |
Float specificStatisticalValue = quantitativeData.getSpecificStatisticalValue(value); |
|
146 |
if(specificStatisticalValue!=null){ |
|
147 |
Listener[] listeners = text.getListeners(SWT.Modify); |
|
148 |
for (Listener listener : listeners) { |
|
149 |
text.removeListener(SWT.Modify, listener); |
|
150 |
} |
|
151 |
text.setText(Float.toString(specificStatisticalValue)); |
|
152 |
for (Listener listener : listeners) { |
|
153 |
text.addListener(SWT.Modify, listener); |
|
154 |
} |
|
155 |
} |
|
156 |
} |
|
157 |
} |
|
111 | 158 |
return this.editorControl; |
112 | 159 |
} |
113 | 160 |
|
114 |
|
|
115 | 161 |
} |
Also available in: Unified diff
ref #7095 Handle dirty state of character matrix when editing