/** * Method to setup Footer */ private void setUpFooter() { FooterRow mainFooter = grid.prependFooterRow(); FooterCell mainFooterCell = mainFooter.join(CATEGORY, MANUFACTURER, MODEL_NAME); mainFooterCell.setText("Total Vehicles Sold Per Quarter"); FooterRow secondaryFooter = grid.appendFooterRow(); FooterCell secondaryFooterCell = secondaryFooter.join(CATEGORY, MANUFACTURER, MODEL_NAME); secondaryFooterCell.setText("Total Vehicles Sold Per Year"); setUpFooterForDataConsolidation(mainFooter, secondaryFooter); }
/** * * Note: Variable names are not followed This is for Calculating * QuarterlyValues, naming convention was not used to make is easy for * tutorial * * @param mainFooter * @param secondaryFooter */ private void setUpFooterForDataConsolidation(FooterRow mainFooter, FooterRow secondaryFooter) { @SuppressWarnings("unchecked") BeanItemContainer<VehicleInfo> container = (BeanItemContainer<VehicleInfo>) grid .getContainerDataSource(); // String to Long Converter Converter<String, Long> convertor = new StringToLongConverter(); for (int i = 2012; i < 2015; i++) { FooterCell yearlySalesCell = secondaryFooter.join("sales" + i + ".q1", "sales" + i + ".q2", "sales" + i + ".q3", "sales" + i + ".q4"); long yearlySalesValue = 0l; // Iterating over all items and calculating values over each quarter for (int quarter = 1; quarter <= 4; quarter++) { long quarterSales = 0l; final String columnName = "sales" + i + ".q" + quarter; FooterCell sumOfQuarterlySales = mainFooter.getCell(columnName); // Iterate over each quarter and calculate for (Object itemId : container.getItemIds()) { Item item = container.getItem(itemId); Integer q1Value = (Integer) item .getItemProperty(columnName).getValue(); quarterSales += Long.valueOf(q1Value); } sumOfQuarterlySales.setText(convertor.convertToPresentation( quarterSales, String.class, grid.getLocale())); yearlySalesValue += quarterSales; } yearlySalesCell.setText(convertor.convertToPresentation( yearlySalesValue, String.class, grid.getLocale())); yearlySalesCell.setHtml("<b>" + convertor.convertToPresentation(yearlySalesValue, String.class, grid.getLocale()) + " <b>"); } }
@Override public FooterRow addRowAt(int index) { return grid.getFooterRow(index); }
@Override public FooterRow appendRow() { return grid.appendFooterRow(); }
@Override public FooterRow getRowAt(int index) { return grid.getFooterRow(index); }
@Override public FooterRow getDefaultRow() { throw new UnsupportedOperationException("Grid footer does not support a default row"); }
@Override public FooterRow prependRow() { return grid.prependFooterRow(); }
@Override public void removeRow(FooterRow row) { grid.removeFooterRow(row); }
@Override public void setDefaultRow(FooterRow row) { throw new UnsupportedOperationException("Grid footer does not support a default row"); }
/** * Build Grid footer rows. * @param footer Footer rows container */ void buildFooter(GridSection<FooterRow> footer);
/** * Updates the footer row contents. * @param listing Source listing component * @param footer Footer row reference */ void updateFooter(ItemListing<T, P> listing, GridSection<FooterRow> footer);