RepeatingView repeating = new RepeatingView(ID_REPEATING_SUMMARY_CHARTS);
addOrReplace(repeating);
for (ObjectAssociation numberAssociation : numberAssociations) {
AbstractItem item = new AbstractItem(repeating.newChildId());
repeating.add(item);
String propertyName = numberAssociation.getName();
item.add(new Label(ID_PROPERTY_NAME, new Model<String>(propertyName)));
List<ObjectAdapter> adapters = model.getObject();
CollectionContentsAsSummary.Summary summary = new CollectionContentsAsSummary.Summary(adapters, numberAssociation);
BigDecimal min = summary.getMin();
BigDecimal max = summary.getMax();
addItem(item, ID_SUM, summary.getTotal());
addItem(item, ID_AVG, summary.getAverage());
addItem(item, ID_MIN, min);
addItem(item, ID_MAX, max);
if(model.isStandalone()) {
final BigDecimal minElseZero = min!=null?(min.compareTo(BigDecimal.ZERO)<0?min:BigDecimal.ZERO):null;
final BigDecimal maxElseZero = max!=null?(max.compareTo(BigDecimal.ZERO)<0?BigDecimal.ZERO:max):null;
final WickedChart chartValue = createChartValue(propertyName, summary.getTitles(), summary.getValuesAsNumbers(), minElseZero, maxElseZero);
final StandaloneValueAsWickedChart wickedChart = new StandaloneValueAsWickedChart(ID_CHART, asValueModel(chartValue));
item.add(wickedChart);
} else {
item.add(new Label(ID_CHART, ""));
}
}
}