Revision bbed9d01
Added by Patrick Plitzner almost 6 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/AggregationConfiguration.java | ||
---|---|---|
13 | 13 |
|
14 | 14 |
import org.apache.commons.lang.StringUtils; |
15 | 15 |
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry; |
16 |
import org.eclipse.nebula.widgets.nattable.data.IDataProvider; |
|
17 | 16 |
import org.eclipse.nebula.widgets.nattable.style.DisplayMode; |
18 | 17 |
import org.eclipse.nebula.widgets.nattable.summaryrow.DefaultSummaryRowConfiguration; |
19 | 18 |
import org.eclipse.nebula.widgets.nattable.summaryrow.ISummaryProvider; |
20 | 19 |
import org.eclipse.nebula.widgets.nattable.summaryrow.SummaryRowConfigAttributes; |
21 | 20 |
import org.eclipse.nebula.widgets.nattable.summaryrow.SummaryRowLayer; |
22 |
import org.eclipse.nebula.widgets.nattable.util.GUIHelper; |
|
23 | 21 |
|
24 | 22 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
25 | 23 |
import eu.etaxonomy.cdm.model.description.CategoricalData; |
... | ... | |
35 | 33 |
*/ |
36 | 34 |
public class AggregationConfiguration extends DefaultSummaryRowConfiguration { |
37 | 35 |
|
38 |
private final IDataProvider dataProvider; |
|
39 |
private Feature feature; |
|
36 |
private CharacterMatrix matrix; |
|
40 | 37 |
|
41 |
public AggregationConfiguration(IDataProvider dataProvider, Feature feature) { |
|
42 |
this.dataProvider = dataProvider; |
|
43 |
this.feature = feature; |
|
44 |
this.summaryRowBgColor = GUIHelper.COLOR_BLUE; |
|
45 |
this.summaryRowFgColor = GUIHelper.COLOR_WHITE; |
|
38 |
public AggregationConfiguration(CharacterMatrix matrix) { |
|
39 |
this.matrix = matrix; |
|
46 | 40 |
} |
47 | 41 |
|
48 | 42 |
@Override |
49 | 43 |
public void addSummaryProviderConfig(IConfigRegistry configRegistry) { |
50 |
if(feature.isSupportsQuantitativeData()){ |
|
51 |
configRegistry.registerConfigAttribute( |
|
52 |
SummaryRowConfigAttributes.SUMMARY_PROVIDER, |
|
53 |
new QuantitativeSummaryProvider(), |
|
54 |
DisplayMode.NORMAL, |
|
55 |
SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX+MatrixUtility.getProperty(feature)); |
|
56 |
} |
|
57 |
if(feature.isSupportsCategoricalData()){ |
|
58 |
configRegistry.registerConfigAttribute( |
|
59 |
SummaryRowConfigAttributes.SUMMARY_PROVIDER, |
|
60 |
new CategoricalSummaryProvider(), |
|
61 |
DisplayMode.NORMAL, |
|
62 |
SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX+MatrixUtility.getProperty(feature)); |
|
44 |
for(int i=0;i<matrix.getFeatures().size();i++){ |
|
45 |
//no summary for the supplemental columns |
|
46 |
if(i<CharacterMatrix.LEADING_COLUMN_COUNT){ |
|
47 |
int index = i; |
|
48 |
configRegistry.registerConfigAttribute( |
|
49 |
SummaryRowConfigAttributes.SUMMARY_PROVIDER, |
|
50 |
columnIndex -> "", |
|
51 |
DisplayMode.NORMAL, |
|
52 |
SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX+index); |
|
53 |
} |
|
54 |
//register aggregation configuration for each feature |
|
55 |
Feature feature = matrix.getFeatures().get(i); |
|
56 |
if(feature.isSupportsQuantitativeData()){ |
|
57 |
configRegistry.registerConfigAttribute( |
|
58 |
SummaryRowConfigAttributes.SUMMARY_PROVIDER, |
|
59 |
new QuantitativeSummaryProvider(), |
|
60 |
DisplayMode.NORMAL, |
|
61 |
SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX+MatrixUtility.getProperty(feature)); |
|
62 |
} |
|
63 |
if(feature.isSupportsCategoricalData()){ |
|
64 |
configRegistry.registerConfigAttribute( |
|
65 |
SummaryRowConfigAttributes.SUMMARY_PROVIDER, |
|
66 |
new CategoricalSummaryProvider(), |
|
67 |
DisplayMode.NORMAL, |
|
68 |
SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX+MatrixUtility.getProperty(feature)); |
|
69 |
} |
|
63 | 70 |
} |
64 | 71 |
} |
65 | 72 |
|
... | ... | |
68 | 75 |
public Object summarize(int columnIndex) { |
69 | 76 |
Float minTotal = null; |
70 | 77 |
Float maxTotal = null; |
71 |
int rowCount = AggregationConfiguration.this.dataProvider.getRowCount();
|
|
78 |
int rowCount = AggregationConfiguration.this.matrix.getBodyDataProvider().getRowCount();
|
|
72 | 79 |
|
73 | 80 |
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { |
74 |
Object dataValue = AggregationConfiguration.this.dataProvider.getDataValue(columnIndex,
|
|
81 |
Object dataValue = AggregationConfiguration.this.matrix.getBodyDataProvider().getDataValue(columnIndex,
|
|
75 | 82 |
rowIndex); |
76 | 83 |
if(HibernateProxyHelper.isInstanceOf(dataValue, QuantitativeData.class)){ |
77 | 84 |
QuantitativeData quantitativeData = HibernateProxyHelper.deproxy(dataValue, QuantitativeData.class); |
... | ... | |
94 | 101 |
private class CategoricalSummaryProvider implements ISummaryProvider { |
95 | 102 |
@Override |
96 | 103 |
public Object summarize(int columnIndex) { |
97 |
int rowCount = AggregationConfiguration.this.dataProvider.getRowCount();
|
|
104 |
int rowCount = AggregationConfiguration.this.matrix.getBodyDataProvider().getRowCount();
|
|
98 | 105 |
Set states = new HashSet<>(); |
99 | 106 |
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { |
100 |
Object dataValue = AggregationConfiguration.this.dataProvider.getDataValue(columnIndex,
|
|
107 |
Object dataValue = AggregationConfiguration.this.matrix.getBodyDataProvider().getDataValue(columnIndex,
|
|
101 | 108 |
rowIndex); |
102 | 109 |
if(dataValue instanceof CategoricalData){ |
103 | 110 |
states.addAll(((CategoricalData) dataValue).getStatesOnly()); |
Also available in: Unified diff
Refactor character matrix