Revision 6b3711bc
Added by Patrick Plitzner almost 6 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/CharacterMatrix.java | ||
---|---|---|
51 | 51 |
import org.eclipse.nebula.widgets.nattable.data.IDataProvider; |
52 | 52 |
import org.eclipse.nebula.widgets.nattable.data.ListDataProvider; |
53 | 53 |
import org.eclipse.nebula.widgets.nattable.edit.EditConfigAttributes; |
54 |
import org.eclipse.nebula.widgets.nattable.edit.editor.IComboBoxDataProvider; |
|
55 | 54 |
import org.eclipse.nebula.widgets.nattable.export.command.ExportCommand; |
56 | 55 |
import org.eclipse.nebula.widgets.nattable.export.command.ExportCommandHandler; |
57 | 56 |
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer; |
... | ... | |
915 | 914 |
MatrixUtility.getProperty(feature)); |
916 | 915 |
|
917 | 916 |
//add combo box cell editor |
918 |
CategoricalDataCellEditor comboBoxCellEditor = new CategoricalDataCellEditor(new IComboBoxDataProvider() { |
|
919 |
|
|
920 |
@Override |
|
921 |
public List<?> getValues(int columnIndex, int rowIndex) { |
|
922 |
Feature feature = indexToFeatureMap.get(columnIndex); |
|
923 |
return getSupportedStatesForCategoricalFeature(feature); |
|
924 |
} |
|
925 |
}, 10, this, feature); |
|
926 | 917 |
//register editor |
927 | 918 |
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, |
928 |
comboBoxCellEditor,
|
|
919 |
new CategoricalDataCellEditor(getSupportedStatesForCategoricalFeature(feature), this, feature),
|
|
929 | 920 |
DisplayMode.EDIT, |
930 | 921 |
MatrixUtility.getProperty(feature)); |
931 | 922 |
|
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/RowWrapper.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.taxeditor.editor.workingSet.matrix; |
10 | 10 |
|
11 |
import java.util.ArrayList; |
|
11 | 12 |
import java.util.Collection; |
12 | 13 |
import java.util.HashMap; |
14 |
import java.util.List; |
|
13 | 15 |
import java.util.Map; |
14 | 16 |
import java.util.Set; |
15 | 17 |
|
... | ... | |
20 | 22 |
import eu.etaxonomy.cdm.model.description.Feature; |
21 | 23 |
import eu.etaxonomy.cdm.model.description.QuantitativeData; |
22 | 24 |
import eu.etaxonomy.cdm.model.description.SpecimenDescription; |
25 |
import eu.etaxonomy.cdm.model.description.State; |
|
26 |
import eu.etaxonomy.cdm.model.description.StateData; |
|
23 | 27 |
import eu.etaxonomy.cdm.model.location.NamedArea; |
24 | 28 |
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit; |
25 | 29 |
import eu.etaxonomy.cdm.model.occurrence.FieldUnit; |
... | ... | |
111 | 115 |
return country; |
112 | 116 |
} |
113 | 117 |
|
114 |
public DescriptionElementBase getDescriptionElementForFeature(Feature feature){ |
|
115 |
return featureToElementMap.get(feature); |
|
118 |
public Object getDataValueForFeature(Feature feature){ |
|
119 |
DescriptionElementBase descriptionElementBase = featureToElementMap.get(feature); |
|
120 |
if(descriptionElementBase!=null && descriptionElementBase.isInstanceOf(CategoricalData.class)){ |
|
121 |
CategoricalData categoricalData = HibernateProxyHelper.deproxy(descriptionElementBase, CategoricalData.class); |
|
122 |
return categoricalData.getStatesOnly(); |
|
123 |
} |
|
124 |
return descriptionElementBase; |
|
125 |
} |
|
126 |
|
|
127 |
public void setDataValueForFeature(Feature feature, Object newValue){ |
|
128 |
DescriptionElementBase descriptionElementBase = featureToElementMap.get(feature); |
|
129 |
//FIXME move this to cdmlib service layer |
|
130 |
if(descriptionElementBase!=null && descriptionElementBase.isInstanceOf(CategoricalData.class) && newValue instanceof Collection){ |
|
131 |
CategoricalData categoricalData = HibernateProxyHelper.deproxy(descriptionElementBase, CategoricalData.class); |
|
132 |
List<StateData> stateData = new ArrayList<>(categoricalData.getStateData()); |
|
133 |
for (StateData stateData2 : stateData) { |
|
134 |
categoricalData.removeStateData(stateData2); |
|
135 |
} |
|
136 |
Collection<State> states = (Collection<State>) newValue; |
|
137 |
for (State state : states) { |
|
138 |
categoricalData.addStateData(state); |
|
139 |
} |
|
140 |
} |
|
116 | 141 |
} |
117 | 142 |
|
118 | 143 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/SpecimenColumnPropertyAccessor.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.taxeditor.editor.workingSet.matrix; |
10 | 10 |
|
11 |
import java.util.ArrayList; |
|
12 |
import java.util.Collection; |
|
13 |
import java.util.List; |
|
14 |
import java.util.Set; |
|
15 |
|
|
16 | 11 |
import org.eclipse.nebula.widgets.nattable.data.IColumnPropertyAccessor; |
17 | 12 |
|
18 |
import eu.etaxonomy.cdm.model.description.CategoricalData; |
|
19 |
import eu.etaxonomy.cdm.model.description.DescriptionElementBase; |
|
20 | 13 |
import eu.etaxonomy.cdm.model.description.Feature; |
21 |
import eu.etaxonomy.cdm.model.description.State; |
|
22 |
import eu.etaxonomy.cdm.model.description.StateData; |
|
23 | 14 |
|
24 | 15 |
/** |
25 | 16 |
* @author pplitzner |
... | ... | |
56 | 47 |
break; |
57 | 48 |
} |
58 | 49 |
Feature feature = matrix.getIndexToFeatureMap().get(columnIndex); |
59 |
return rowWrapper.getDescriptionElementForFeature(feature);
|
|
50 |
return rowWrapper.getDataValueForFeature(feature);
|
|
60 | 51 |
} else if (columnIndex == 0) { |
61 | 52 |
return rowObject; |
62 | 53 |
} |
... | ... | |
71 | 62 |
if(rowObject instanceof RowWrapper){ |
72 | 63 |
RowWrapper rowWrapper = (RowWrapper)rowObject; |
73 | 64 |
Feature feature = matrix.getIndexToFeatureMap().get(columnIndex); |
74 |
Set<DescriptionElementBase> elements = rowWrapper.getSpecimenDescription().getElements(); |
|
75 |
for (DescriptionElementBase descriptionElementBase : elements) { |
|
76 |
if(descriptionElementBase.getFeature().equals(feature)){ |
|
77 |
setDescriptionElement(descriptionElementBase, feature, newValue); |
|
78 |
return; |
|
79 |
} |
|
80 |
} |
|
81 |
} |
|
82 |
} |
|
83 |
|
|
84 |
|
|
85 |
private void setDescriptionElement(DescriptionElementBase descriptionElementBase, Feature feature, Object newValue) { |
|
86 |
//FIXME move this to cdmlib service layer |
|
87 |
if(feature.isSupportsCategoricalData() && descriptionElementBase instanceof CategoricalData && newValue instanceof Collection){ |
|
88 |
CategoricalData categoricalData = (CategoricalData)descriptionElementBase; |
|
89 |
List<StateData> stateData = new ArrayList<>(categoricalData.getStateData()); |
|
90 |
for (StateData stateData2 : stateData) { |
|
91 |
categoricalData.removeStateData(stateData2); |
|
92 |
} |
|
93 |
Collection<State> states = (Collection<State>) newValue; |
|
94 |
for (State state : states) { |
|
95 |
categoricalData.addStateData(state); |
|
96 |
} |
|
65 |
rowWrapper.setDataValueForFeature(feature, newValue); |
|
97 | 66 |
} |
98 | 67 |
} |
99 | 68 |
|
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/categorical/CategoricalDataCellEditor.java | ||
---|---|---|
10 | 10 |
|
11 | 11 |
import java.util.List; |
12 | 12 |
|
13 |
import org.eclipse.nebula.widgets.nattable.edit.editor.IComboBoxDataProvider; |
|
14 |
import org.eclipse.nebula.widgets.nattable.filterrow.combobox.FilterRowComboBoxCellEditor; |
|
13 |
import org.eclipse.nebula.widgets.nattable.edit.editor.ComboBoxCellEditor; |
|
15 | 14 |
import org.eclipse.nebula.widgets.nattable.widget.NatCombo; |
16 | 15 |
import org.eclipse.swt.events.SelectionEvent; |
17 | 16 |
import org.eclipse.swt.events.SelectionListener; |
18 | 17 |
import org.eclipse.swt.widgets.Composite; |
19 | 18 |
import org.eclipse.swt.widgets.Control; |
20 | 19 |
|
21 |
import eu.etaxonomy.cdm.model.description.CategoricalData; |
|
22 | 20 |
import eu.etaxonomy.cdm.model.description.Feature; |
23 | 21 |
import eu.etaxonomy.cdm.model.description.State; |
24 | 22 |
import eu.etaxonomy.taxeditor.editor.workingSet.matrix.CharacterMatrix; |
... | ... | |
29 | 27 |
* @since Dec 7, 2017 |
30 | 28 |
* |
31 | 29 |
*/ |
32 |
public class CategoricalDataCellEditor extends FilterRowComboBoxCellEditor{
|
|
30 |
public class CategoricalDataCellEditor extends ComboBoxCellEditor{ |
|
33 | 31 |
|
34 | 32 |
private CharacterMatrix matrix; |
35 | 33 |
private Feature feature; |
36 | 34 |
|
37 |
public CategoricalDataCellEditor(IComboBoxDataProvider dataProvider, int maxVisibleItems, CharacterMatrix matrix, Feature feature) {
|
|
38 |
super(dataProvider, maxVisibleItems);
|
|
35 |
public CategoricalDataCellEditor(List<State> list, CharacterMatrix matrix, Feature feature) {
|
|
36 |
super(list, 10);
|
|
39 | 37 |
this.matrix = matrix; |
40 | 38 |
this.feature = feature; |
39 |
setUseCheckbox(true); |
|
40 |
setMultiselect(true); |
|
41 | 41 |
} |
42 | 42 |
|
43 | 43 |
@Override |
... | ... | |
45 | 45 |
if(canonicalValue==null){ |
46 | 46 |
Object rowWrapper = matrix.getBodyDataProvider().getRowObject(this.getRowIndex()); |
47 | 47 |
if(rowWrapper instanceof RowWrapper){ |
48 |
canonicalValue = ((RowWrapper) rowWrapper).addCategoricalData(feature);
|
|
48 |
((RowWrapper) rowWrapper).addCategoricalData(feature); |
|
49 | 49 |
} |
50 | 50 |
} |
51 |
else if (canonicalValue instanceof CategoricalData) { |
|
52 |
CategoricalData data = (CategoricalData)canonicalValue; |
|
53 |
List<State> states = data.getStatesOnly(); |
|
54 |
String[] result = new String[states.size()]; |
|
55 |
for (int i = 0; i < states.size(); i++) { |
|
56 |
result[i] = (String) this.displayConverter.canonicalToDisplayValue( |
|
57 |
this.layerCell, this.configRegistry, states.get(i)); |
|
58 |
} |
|
59 |
setEditorValue(result); |
|
60 |
} |
|
51 |
super.setCanonicalValue(canonicalValue); |
|
61 | 52 |
} |
62 | 53 |
|
63 | 54 |
/** |
... | ... | |
66 | 57 |
@Override |
67 | 58 |
protected Control activateCell(Composite parent, Object originalCanonicalValue) { |
68 | 59 |
if(matrix.getBodyDataProvider().getRowObject(this.getRowIndex()) instanceof RowWrapper){ |
69 |
Control editorControl = super.activateCell(parent, originalCanonicalValue);
|
|
70 |
((NatCombo)editorControl).addSelectionListener(new SelectionListener() {
|
|
60 |
NatCombo natCombo = (NatCombo) super.activateCell(parent, originalCanonicalValue);
|
|
61 |
natCombo.addSelectionListener(new SelectionListener() {
|
|
71 | 62 |
@Override |
72 | 63 |
public void widgetSelected(SelectionEvent e) { |
73 | 64 |
matrix.setDirty(); |
... | ... | |
76 | 67 |
public void widgetDefaultSelected(SelectionEvent e) { |
77 | 68 |
} |
78 | 69 |
}); |
79 |
return editorControl;
|
|
70 |
return natCombo;
|
|
80 | 71 |
} |
81 | 72 |
return null; |
82 | 73 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/categorical/CategoricalDataDisplayConverter.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.taxeditor.editor.workingSet.matrix.categorical; |
10 | 10 |
|
11 |
import java.util.Collection; |
|
12 |
|
|
11 | 13 |
import org.eclipse.nebula.widgets.nattable.data.convert.DisplayConverter; |
12 | 14 |
|
13 | 15 |
import eu.etaxonomy.cdm.model.description.CategoricalData; |
... | ... | |
32 | 34 |
else if(canonicalValue instanceof State){ |
33 | 35 |
return ((State) canonicalValue).getLabel(); |
34 | 36 |
} |
37 |
else if (canonicalValue instanceof Collection) { |
|
38 |
// Collection.toString() will add [ and ] around |
|
39 |
// the values in the Collection |
|
40 |
// So by removing the leading and ending |
|
41 |
// character, we remove the brackets |
|
42 |
String result = canonicalValue.toString(); |
|
43 |
result = result.substring(1, result.length() - 1); |
|
44 |
return result; |
|
45 |
} |
|
35 | 46 |
else if(canonicalValue!=null){ |
36 | 47 |
return canonicalValue.toString(); |
37 | 48 |
} |
Also available in: Unified diff
ref #7095 Overhauled categorical data cell editor