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