2 * Copyright (C) 2018 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.editor
.descriptiveDataSet
.matrix
;
11 import java
.util
.HashSet
;
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
;
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
;
30 * Configuration for the aggregation algorithm for the columns
31 * of the character matrix
36 public class AggregationConfiguration
extends DefaultSummaryRowConfiguration
{
38 private final IDataProvider dataProvider
;
39 private Feature feature
;
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
;
49 public void addSummaryProviderConfig(IConfigRegistry configRegistry
) {
50 if(feature
.isSupportsQuantitativeData()){
51 configRegistry
.registerConfigAttribute(
52 SummaryRowConfigAttributes
.SUMMARY_PROVIDER
,
53 new QuantitativeSummaryProvider(),
55 SummaryRowLayer
.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX
+MatrixUtility
.getProperty(feature
));
57 if(feature
.isSupportsCategoricalData()){
58 configRegistry
.registerConfigAttribute(
59 SummaryRowConfigAttributes
.SUMMARY_PROVIDER
,
60 new CategoricalSummaryProvider(),
62 SummaryRowLayer
.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX
+MatrixUtility
.getProperty(feature
));
66 private class QuantitativeSummaryProvider
implements ISummaryProvider
{
68 public Object
summarize(int columnIndex
) {
69 Float minTotal
= null;
70 Float maxTotal
= null;
71 int rowCount
= AggregationConfiguration
.this.dataProvider
.getRowCount();
73 for (int rowIndex
= 0; rowIndex
< rowCount
; rowIndex
++) {
74 Object dataValue
= AggregationConfiguration
.this.dataProvider
.getDataValue(columnIndex
,
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
)){
83 if(max
!=null && (maxTotal
==null || max
>maxTotal
)){
88 String summaryString
= MatrixUtility
.getQuantitativeLabel(minTotal
, maxTotal
);
94 private class CategoricalSummaryProvider
implements ISummaryProvider
{
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
,
102 if(dataValue
instanceof CategoricalData
){
103 states
.addAll(((CategoricalData
) dataValue
).getStatesOnly());
106 return StringUtils
.join(states
, ", "); //$NON-NLS-1$