1 |
e738c599
|
Patrick Plitzner
|
/**
|
2 |
|
|
* Copyright (C) 2018 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.workingSet.matrix;
|
10 |
|
|
|
11 |
7f1d6816
|
Patrick Plitzner
|
import java.util.HashSet;
|
12 |
|
|
import java.util.Set;
|
13 |
|
|
|
14 |
|
|
import org.apache.commons.lang.StringUtils;
|
15 |
e738c599
|
Patrick Plitzner
|
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
|
16 |
|
|
import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
|
17 |
7d199d04
|
Patrick Plitzner
|
import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
|
18 |
e738c599
|
Patrick Plitzner
|
import org.eclipse.nebula.widgets.nattable.summaryrow.DefaultSummaryRowConfiguration;
|
19 |
|
|
import org.eclipse.nebula.widgets.nattable.summaryrow.ISummaryProvider;
|
20 |
|
|
import org.eclipse.nebula.widgets.nattable.summaryrow.SummaryRowConfigAttributes;
|
21 |
|
|
import org.eclipse.nebula.widgets.nattable.summaryrow.SummaryRowLayer;
|
22 |
|
|
import org.eclipse.nebula.widgets.nattable.util.GUIHelper;
|
23 |
|
|
|
24 |
fcd7713d
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
25 |
8dcaccaf
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.model.description.CategoricalData;
|
26 |
e738c599
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.model.description.Feature;
|
27 |
|
|
import eu.etaxonomy.cdm.model.description.QuantitativeData;
|
28 |
|
|
|
29 |
|
|
/**
|
30 |
06ab7f53
|
Patrick Plitzner
|
* Configuration for the aggregation algorithm for the columns
|
31 |
|
|
* of the character matrix
|
32 |
e738c599
|
Patrick Plitzner
|
* @author pplitzner
|
33 |
|
|
* @since Jan 4, 2018
|
34 |
|
|
*
|
35 |
|
|
*/
|
36 |
|
|
public class AggregationConfiguration extends DefaultSummaryRowConfiguration {
|
37 |
|
|
|
38 |
|
|
private final IDataProvider dataProvider;
|
39 |
|
|
private Feature feature;
|
40 |
|
|
|
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;
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
@Override
|
49 |
|
|
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 |
034d4a6a
|
Patrick Plitzner
|
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));
|
63 |
|
|
}
|
64 |
e738c599
|
Patrick Plitzner
|
}
|
65 |
|
|
|
66 |
034d4a6a
|
Patrick Plitzner
|
private class QuantitativeSummaryProvider implements ISummaryProvider {
|
67 |
e738c599
|
Patrick Plitzner
|
@Override
|
68 |
|
|
public Object summarize(int columnIndex) {
|
69 |
|
|
Float minTotal = null;
|
70 |
|
|
Float maxTotal = null;
|
71 |
|
|
int rowCount = AggregationConfiguration.this.dataProvider.getRowCount();
|
72 |
|
|
|
73 |
|
|
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
|
74 |
|
|
Object dataValue = AggregationConfiguration.this.dataProvider.getDataValue(columnIndex,
|
75 |
|
|
rowIndex);
|
76 |
fcd7713d
|
Patrick Plitzner
|
if(HibernateProxyHelper.isInstanceOf(dataValue, QuantitativeData.class)){
|
77 |
|
|
QuantitativeData quantitativeData = HibernateProxyHelper.deproxy(dataValue, QuantitativeData.class);
|
78 |
e738c599
|
Patrick Plitzner
|
Float min = quantitativeData.getMin();
|
79 |
|
|
Float max = quantitativeData.getMax();
|
80 |
281b1abd
|
Patrick Plitzner
|
if(min!=null && (minTotal==null || min<minTotal)){
|
81 |
e738c599
|
Patrick Plitzner
|
minTotal = min;
|
82 |
|
|
}
|
83 |
281b1abd
|
Patrick Plitzner
|
if(max!=null && (maxTotal==null || max>maxTotal)){
|
84 |
e738c599
|
Patrick Plitzner
|
maxTotal = max;
|
85 |
|
|
}
|
86 |
|
|
}
|
87 |
|
|
}
|
88 |
35ba1a56
|
Patrick Plitzner
|
String summaryString = MatrixUtility.getQuantitativeLabel(minTotal, maxTotal);
|
89 |
e738c599
|
Patrick Plitzner
|
return summaryString;
|
90 |
|
|
}
|
91 |
35ba1a56
|
Patrick Plitzner
|
|
92 |
e738c599
|
Patrick Plitzner
|
}
|
93 |
|
|
|
94 |
034d4a6a
|
Patrick Plitzner
|
private class CategoricalSummaryProvider implements ISummaryProvider {
|
95 |
|
|
@Override
|
96 |
|
|
public Object summarize(int columnIndex) {
|
97 |
|
|
int rowCount = AggregationConfiguration.this.dataProvider.getRowCount();
|
98 |
a3782e5c
|
Patrick Plitzner
|
Set states = new HashSet<>();
|
99 |
034d4a6a
|
Patrick Plitzner
|
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
|
100 |
|
|
Object dataValue = AggregationConfiguration.this.dataProvider.getDataValue(columnIndex,
|
101 |
|
|
rowIndex);
|
102 |
8dcaccaf
|
Patrick Plitzner
|
if(dataValue instanceof CategoricalData){
|
103 |
|
|
states.addAll(((CategoricalData) dataValue).getStatesOnly());
|
104 |
034d4a6a
|
Patrick Plitzner
|
}
|
105 |
|
|
}
|
106 |
87abc2b1
|
Patrick Plitzner
|
return StringUtils.join(states, ", "); //$NON-NLS-1$
|
107 |
034d4a6a
|
Patrick Plitzner
|
}
|
108 |
|
|
}
|
109 |
e738c599
|
Patrick Plitzner
|
}
|