InetSoft Product Information: Using Tabular Data in a Report

This section discussed the manipulation of tabular data using Table objects. A table is the most common way to present data visually on either screen or paper. It is an important feature in Style Intelligence. Style Intelligence offers an simple API that allows the control of almost any aspect of a table. It also provides a number of convenience classes, reducing the amount of code a program needs to access the detailed API.

Abstract Table Lens

There are occasions where a table adapter is not available for the type of data source a program uses. In these cases, a table lens class must be developed to handle the data source. To make this task easier and reduce the amount of coding, InetSoft provides an AbstractTableLens class.

The AbstractTableLens, as its name implies, is an abstract table lens, providing a default implementation for most of the methods. To define a new table lens, the user only needs to define three methods:

• int getRowCount() Returns the number of rows in the table.

• int getColCount() Returns the number of columns in the table.

• Object getObject(int row, int col) Returns the value at the specified cell.

tabular report data dashboard sample

view demo icon
View a 2-minute demonstration of InetSoft's easy, agile, and robust BI software.

Two functions that often need to be overridden are the getHeaderRowCount() and getHeaderColCount(). These two functions allow the user to set one or more rows/columns as header row/column. Header rows are kept with the table if the table spans across multiple pages. The header rows are displayed on each table segment on every page. The header columns are displayed on every table segment if the table rows wrap.

Note: As of v/s 9.5 your custom code must call the 'moreRows(row)' method ('moreRows(0)'), to trigger the processing of the table lens. This should be called before any other method of the lens can be called. Failure to do so may result in a runtime exception.

Note: The table header rows/columns count is included in the total row/column count. For example, a table containing one header row and five body rows should return a row count of six from the TableLens.getRowCount(). The same is true for the header columns.

In addition to getHeaderRowCount() and getHeaderColCount(), two more functions often need to be overridden. They are getTrailerRowCount() and getTrailerColCount(). This allows a cross tab to use a table style to place the summary data in multiple rows or columns.

Attribute Table Lens

When using an AbstractTableLens to create a table lens, if the program also wants to supply the visual attributes, it has to implement the methods that return those attributes. While this is fairly simple to do, it is tedious when the only thing you need to do is set the values of a few attributes.

To make ad hoc settings of table attributes easier, the InetSoft package provides a table decorator class, AttributeTableLens. The AttributeTableLens is a wrapper that can be wrapped around other table lens objects. In addition to implementing the TableLens interface methods, it also provides methods for setting the attributes.

The AttributeTableLens is the base class for all table adapter classes, such as the Swing JTable adapter and JDBC table adapter. It is also the base class for all table style classes. Whenever you are working with any table adapters or styles you can easily override the table attributes by using the convenient API of AttributeTableLens.

The attributes returned from an AttributeTableLens may come from either the original table lens object or from the value explicitly set by users. The attribute setting methods provided by the AttributeTableLens roughly correspond to the attribute access methods defined in the TableLens interface, but with slightly different signatures.

We will not cover all methods in the AttributeTableLens since there is a large number of them. In the following code snippets, we will show some of the more commonly used methods to modify the behavior of tables.

A feature provided by the AttributeTableLens is the ability to associate a presenter or format object with a column. If we do not want to associate a presenter/format with a type in the entire report, we can set the associated presenter/format of a particular column in a table:

JTableLens table = new JTableLens(jTable1);
table.setFormat(5, NumberFormat.getCurrencyInstance());
table.setPresenter(4, new BooleanPresenter());

Default Table Lens

The is derived from the AttributeTableLens. In addition to table-related attributes, the DefaultTableLens also provides storage for storing the table data. If a user does not want to create a new class to serve as a table lens and cannot use the table adapters, the user can use the DefaultTableLens directly.

// create table with 5 rows, 6 columns
DefaultTableLens table = new DefaultTableLens(5, 6);
table.setObject(0, 0, "Company");
table.setObject(0, 1, "Address");
. . .

Previous: Executing a Report Template