1
|
/**
|
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
|
import java.util.HashSet;
|
12
|
import java.util.Set;
|
13
|
|
14
|
import org.apache.commons.lang.StringUtils;
|
15
|
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
|
16
|
import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
|
17
|
import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
|
18
|
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
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
25
|
import eu.etaxonomy.cdm.model.description.CategoricalData;
|
26
|
import eu.etaxonomy.cdm.model.description.Feature;
|
27
|
import eu.etaxonomy.cdm.model.description.QuantitativeData;
|
28
|
import eu.etaxonomy.cdm.model.description.State;
|
29
|
|
30
|
/**
|
31
|
* @author pplitzner
|
32
|
* @since Jan 4, 2018
|
33
|
*
|
34
|
*/
|
35
|
public class AggregationConfiguration extends DefaultSummaryRowConfiguration {
|
36
|
|
37
|
private final IDataProvider dataProvider;
|
38
|
private Feature feature;
|
39
|
|
40
|
public AggregationConfiguration(IDataProvider dataProvider, Feature feature) {
|
41
|
this.dataProvider = dataProvider;
|
42
|
this.feature = feature;
|
43
|
this.summaryRowBgColor = GUIHelper.COLOR_BLUE;
|
44
|
this.summaryRowFgColor = GUIHelper.COLOR_WHITE;
|
45
|
}
|
46
|
|
47
|
@Override
|
48
|
public void addSummaryProviderConfig(IConfigRegistry configRegistry) {
|
49
|
if(feature.isSupportsQuantitativeData()){
|
50
|
configRegistry.registerConfigAttribute(
|
51
|
SummaryRowConfigAttributes.SUMMARY_PROVIDER,
|
52
|
new QuantitativeSummaryProvider(),
|
53
|
DisplayMode.NORMAL,
|
54
|
SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX+MatrixUtility.getProperty(feature));
|
55
|
}
|
56
|
if(feature.isSupportsCategoricalData()){
|
57
|
configRegistry.registerConfigAttribute(
|
58
|
SummaryRowConfigAttributes.SUMMARY_PROVIDER,
|
59
|
new CategoricalSummaryProvider(),
|
60
|
DisplayMode.NORMAL,
|
61
|
SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX+MatrixUtility.getProperty(feature));
|
62
|
}
|
63
|
}
|
64
|
|
65
|
private class QuantitativeSummaryProvider implements ISummaryProvider {
|
66
|
@Override
|
67
|
public Object summarize(int columnIndex) {
|
68
|
Float minTotal = null;
|
69
|
Float maxTotal = null;
|
70
|
int rowCount = AggregationConfiguration.this.dataProvider.getRowCount();
|
71
|
|
72
|
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
|
73
|
Object dataValue = AggregationConfiguration.this.dataProvider.getDataValue(columnIndex,
|
74
|
rowIndex);
|
75
|
if(HibernateProxyHelper.isInstanceOf(dataValue, QuantitativeData.class)){
|
76
|
QuantitativeData quantitativeData = HibernateProxyHelper.deproxy(dataValue, QuantitativeData.class);
|
77
|
Float min = quantitativeData.getMin();
|
78
|
Float max = quantitativeData.getMax();
|
79
|
if(min!=null && (minTotal==null || min<minTotal)){
|
80
|
minTotal = min;
|
81
|
}
|
82
|
if(max!=null && (maxTotal==null || max>maxTotal)){
|
83
|
maxTotal = max;
|
84
|
}
|
85
|
}
|
86
|
}
|
87
|
String summaryString = MatrixUtility.getQuantitativeLabel(minTotal, maxTotal);
|
88
|
return summaryString;
|
89
|
}
|
90
|
|
91
|
}
|
92
|
|
93
|
private class CategoricalSummaryProvider implements ISummaryProvider {
|
94
|
@Override
|
95
|
public Object summarize(int columnIndex) {
|
96
|
int rowCount = AggregationConfiguration.this.dataProvider.getRowCount();
|
97
|
Set<State> states = new HashSet<>();
|
98
|
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
|
99
|
Object dataValue = AggregationConfiguration.this.dataProvider.getDataValue(columnIndex,
|
100
|
rowIndex);
|
101
|
if(HibernateProxyHelper.isInstanceOf(dataValue, CategoricalData.class)){
|
102
|
CategoricalData categoricalData = HibernateProxyHelper.deproxy(dataValue, CategoricalData.class);
|
103
|
states.addAll(categoricalData.getStatesOnly());
|
104
|
}
|
105
|
}
|
106
|
return StringUtils.join(states, ", ");
|
107
|
}
|
108
|
}
|
109
|
}
|