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.descriptiveDataSet.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
|
|
29
|
/**
|
30
|
* Configuration for the aggregation algorithm for the columns
|
31
|
* of the character matrix
|
32
|
* @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
|
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
|
}
|
65
|
|
66
|
private class QuantitativeSummaryProvider implements ISummaryProvider {
|
67
|
@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
|
if(HibernateProxyHelper.isInstanceOf(dataValue, QuantitativeData.class)){
|
77
|
QuantitativeData quantitativeData = HibernateProxyHelper.deproxy(dataValue, QuantitativeData.class);
|
78
|
Float min = quantitativeData.getMin();
|
79
|
Float max = quantitativeData.getMax();
|
80
|
if(min!=null && (minTotal==null || min<minTotal)){
|
81
|
minTotal = min;
|
82
|
}
|
83
|
if(max!=null && (maxTotal==null || max>maxTotal)){
|
84
|
maxTotal = max;
|
85
|
}
|
86
|
}
|
87
|
}
|
88
|
String summaryString = MatrixUtility.getQuantitativeLabel(minTotal, maxTotal);
|
89
|
return summaryString;
|
90
|
}
|
91
|
|
92
|
}
|
93
|
|
94
|
private class CategoricalSummaryProvider implements ISummaryProvider {
|
95
|
@Override
|
96
|
public Object summarize(int columnIndex) {
|
97
|
int rowCount = AggregationConfiguration.this.dataProvider.getRowCount();
|
98
|
Set states = new HashSet<>();
|
99
|
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
|
100
|
Object dataValue = AggregationConfiguration.this.dataProvider.getDataValue(columnIndex,
|
101
|
rowIndex);
|
102
|
if(dataValue instanceof CategoricalData){
|
103
|
states.addAll(((CategoricalData) dataValue).getStatesOnly());
|
104
|
}
|
105
|
}
|
106
|
return StringUtils.join(states, ", "); //$NON-NLS-1$
|
107
|
}
|
108
|
}
|
109
|
}
|