Footers

Top  Previous  Next

 

The Footer interface defines the place and number of FooterRows to add to a DynamicTreeTableModel via the method:

 

public int getFooterSize(TreeTableRow row);

 

Footer implementations should return the number of footers to add under the supplied TreeTableRow. An appropriate aggregator should also be used to calculate the cell values for these FooterRows.

 

DynamicTreeTableModel defines methods for creating, assigning and retrieving the footer:

 

protected Footer createDefaultFooter();

public void setFooter(Footer footer);

public Footer getFooter();

 

DynamicTreeTableModel will use the assigned footer in order to add footer rows to the tree structure. This is accomplished with the method:

 

protected void buildFooter();

 

Example: Create and install a custom footer and an accompanying aggregator that sums over the integers values of the cells.

 

//ttm is the TreeTableModel

 

//create the footer

Footer myFooter = new Footer() {

       public int getFooterSize(TreeTableRow row) {

               if (row.getLevel() == 0) return 0;

               return 1;

       }

};

 

//create the aggregator

Aggregator footerAggregator = new DefaultCellAggregator(ttm) {

       public Object getAggregateValue(AggregateRow node, int columnIndex) {

               if (columnIndex == 4 && node.isFooter()) {

                       TreeTableRow parent = (TreeTableRow) node.getParent();

 

                       int[] totalRows = model.getModelIndexesUnderRow(parent, false);

                       int sum = 0;

                       for (int i = 0; i < totalRows.length; i++) {

                               Integer iv = (Integer) model.getModel().getValueAt(totalRows[i], 4);

                               int ival = iv.intValue();

                               sum += ival;

                       }

                       return new Integer(sum);

               }

               return super.getAggregateValue(rowIndex, columnIndex);

       }

};

 

//set the footer

ttm.setFooter(myFooter);

 

//set the aggregator

ttm.setDefaultAggregator(footerAggregator);