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.style.DisplayMode;
|
17
|
import org.eclipse.nebula.widgets.nattable.summaryrow.DefaultSummaryRowConfiguration;
|
18
|
import org.eclipse.nebula.widgets.nattable.summaryrow.ISummaryProvider;
|
19
|
import org.eclipse.nebula.widgets.nattable.summaryrow.SummaryRowConfigAttributes;
|
20
|
import org.eclipse.nebula.widgets.nattable.summaryrow.SummaryRowLayer;
|
21
|
|
22
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
23
|
import eu.etaxonomy.cdm.model.description.CategoricalData;
|
24
|
import eu.etaxonomy.cdm.model.description.Feature;
|
25
|
import eu.etaxonomy.cdm.model.description.QuantitativeData;
|
26
|
|
27
|
/**
|
28
|
* Configuration for the aggregation algorithm for the columns
|
29
|
* of the character matrix
|
30
|
* @author pplitzner
|
31
|
* @since Jan 4, 2018
|
32
|
*
|
33
|
*/
|
34
|
public class AggregationConfiguration extends DefaultSummaryRowConfiguration {
|
35
|
|
36
|
private CharacterMatrix matrix;
|
37
|
|
38
|
public AggregationConfiguration(CharacterMatrix matrix) {
|
39
|
this.matrix = matrix;
|
40
|
}
|
41
|
|
42
|
@Override
|
43
|
public void addSummaryProviderConfig(IConfigRegistry configRegistry) {
|
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
|
}
|
70
|
}
|
71
|
}
|
72
|
|
73
|
private class QuantitativeSummaryProvider implements ISummaryProvider {
|
74
|
@Override
|
75
|
public Object summarize(int columnIndex) {
|
76
|
Float minTotal = null;
|
77
|
Float maxTotal = null;
|
78
|
int rowCount = AggregationConfiguration.this.matrix.getBodyDataProvider().getRowCount();
|
79
|
|
80
|
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
|
81
|
Object dataValue = AggregationConfiguration.this.matrix.getBodyDataProvider().getDataValue(columnIndex,
|
82
|
rowIndex);
|
83
|
if(HibernateProxyHelper.isInstanceOf(dataValue, QuantitativeData.class)){
|
84
|
QuantitativeData quantitativeData = HibernateProxyHelper.deproxy(dataValue, QuantitativeData.class);
|
85
|
Float min = quantitativeData.getMin();
|
86
|
Float max = quantitativeData.getMax();
|
87
|
if(min!=null && (minTotal==null || min<minTotal)){
|
88
|
minTotal = min;
|
89
|
}
|
90
|
if(max!=null && (maxTotal==null || max>maxTotal)){
|
91
|
maxTotal = max;
|
92
|
}
|
93
|
}
|
94
|
}
|
95
|
String summaryString = MatrixUtility.getQuantitativeLabel(minTotal, null, maxTotal);
|
96
|
return summaryString;
|
97
|
}
|
98
|
|
99
|
}
|
100
|
|
101
|
private class CategoricalSummaryProvider implements ISummaryProvider {
|
102
|
@Override
|
103
|
public Object summarize(int columnIndex) {
|
104
|
int rowCount = AggregationConfiguration.this.matrix.getBodyDataProvider().getRowCount();
|
105
|
Set states = new HashSet<>();
|
106
|
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
|
107
|
Object dataValue = AggregationConfiguration.this.matrix.getBodyDataProvider().getDataValue(columnIndex,
|
108
|
rowIndex);
|
109
|
if(dataValue instanceof CategoricalData){
|
110
|
states.addAll(((CategoricalData) dataValue).getStatesOnly());
|
111
|
}
|
112
|
}
|
113
|
return StringUtils.join(states, ", "); //$NON-NLS-1$
|
114
|
}
|
115
|
}
|
116
|
}
|