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.Feature;
|
21
|
import eu.etaxonomy.cdm.model.description.QuantitativeData;
|
22
|
|
23
|
/**
|
24
|
* @author pplitzner
|
25
|
* @since Jan 4, 2018
|
26
|
*
|
27
|
*/
|
28
|
public class AggregationConfiguration extends DefaultSummaryRowConfiguration {
|
29
|
|
30
|
private final IDataProvider dataProvider;
|
31
|
private Feature feature;
|
32
|
|
33
|
public AggregationConfiguration(IDataProvider dataProvider, Feature feature) {
|
34
|
this.dataProvider = dataProvider;
|
35
|
this.feature = feature;
|
36
|
this.summaryRowBgColor = GUIHelper.COLOR_BLUE;
|
37
|
this.summaryRowFgColor = GUIHelper.COLOR_WHITE;
|
38
|
}
|
39
|
|
40
|
@Override
|
41
|
public void addSummaryProviderConfig(IConfigRegistry configRegistry) {
|
42
|
if(feature.isSupportsQuantitativeData()){
|
43
|
configRegistry.registerConfigAttribute(
|
44
|
SummaryRowConfigAttributes.SUMMARY_PROVIDER,
|
45
|
new QuantitativeSummaryProvider(),
|
46
|
DisplayMode.NORMAL,
|
47
|
SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX+MatrixUtility.getProperty(feature));
|
48
|
}
|
49
|
}
|
50
|
|
51
|
class QuantitativeSummaryProvider implements ISummaryProvider {
|
52
|
@Override
|
53
|
public Object summarize(int columnIndex) {
|
54
|
Float minTotal = null;
|
55
|
Float maxTotal = null;
|
56
|
int rowCount = AggregationConfiguration.this.dataProvider.getRowCount();
|
57
|
|
58
|
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
|
59
|
Object dataValue = AggregationConfiguration.this.dataProvider.getDataValue(columnIndex,
|
60
|
rowIndex);
|
61
|
if(dataValue instanceof QuantitativeData){
|
62
|
QuantitativeData quantitativeData = (QuantitativeData)dataValue;
|
63
|
Float min = quantitativeData.getMin();
|
64
|
Float max = quantitativeData.getMax();
|
65
|
if(minTotal==null || min<minTotal){
|
66
|
minTotal = min;
|
67
|
}
|
68
|
if(maxTotal==null || max>maxTotal){
|
69
|
maxTotal = max;
|
70
|
}
|
71
|
}
|
72
|
}
|
73
|
String summaryString = "";
|
74
|
if(minTotal!=null){
|
75
|
summaryString += "from "+minTotal;
|
76
|
}
|
77
|
if(maxTotal!=null){
|
78
|
summaryString += " up to "+maxTotal;
|
79
|
}
|
80
|
return summaryString;
|
81
|
}
|
82
|
}
|
83
|
|
84
|
}
|