One of the most important concepts in Style Intelligence is the table adapter. Table adapters allow printing of table based components or data structures automatically and completely eliminate the need for an application to manually setup the table in a report. In addition to their use in displaying visual components, adapters can also be built for other objects to retrieve table contents and attributes.
There are currently two component packages that are supported officially by Style Intelligence: JFC Swing and Tea Set Widgets. This chapter covers the adapters for the Swing JTable and the Tea Set Grid/SuperGrid.
|
View a 2-minute demonstration of InetSoft's easy, agile, and robust BI software. |
Swing JTable Adapters
There are three versions of adapters for the JTable: JTableLens, JTableRendererLens and TableModelLens. The main difference among the adapters is the level of detail that the adapters capture.
The JTableLens captures the table contents as objects and also captures the table attributes such as the column width, row height, border, etc. It is appropriate for most situations when printing from an on-screen JTable component. The JTableLens has been used in our examples so far.
ReportSheet report = new StyleSheet();
StyleSheet layout = (StyleSheet)report;
...
layout.addTable(new inetsoft.report.lens.swing.JTableLens(jtable));
The Swing JTable supports cell renderers, which are classes that know how to paint a particular type of object. This can cause a problem when using the JTableLens. Because the JTableLens returns the cell contents as object values, the information on how to present the values graphically is lost.
For example, if a cell has a Boolean value, the JTable uses a checkbox component to render the value. When the JTableLens is used to add the table to a report, the cell values are returned as Boolean objects. By default, object values are printed in the way that their text representation is returned by the toString() method of the object. In this case, the Boolean values are printed as 'True' or 'False'.
To allow the most accurate capturing of a JTable component, the JTableRendererLens adapter is added. Instead of returning the table contents as object values, the JTableRendererLens returns each cell value as a painter that paints the cell value in the report, in the same way that its painted by the JTable.
layout.addTable(new inetsoft.report.lens.swing.JTableRendererLens(jtable));
The main strength of the JTableRendererLens adapter is also its biggest disadvantage. Because the table adapter controls exactly how the cells are painted, it does not work well with table styles. To accommodate this problem, we will demonstrate how to manage the painting of classes of objects through the use of Presenters, a more suitable method when using table style classes.
The Table Model Lens is a very simple adapter for the Swing table lens objects. It returns the contents of a table lens and provides default values for the attributes. It is best used with a table style to provide the visual settings.
Report Table Adapters for Different Swing Versions
The swing package has different versions. In addition to implementation differences in these versions, Swing 1.1 also introduced a new Swing package name. To cope with these differences, there are three Swing table lens packages:
- inetsoft.report.lens.swing10 This package contains table adapters for the Swing 1.0.x packages. The Swing package name in these classes is com.sun.java.swing.
- inetsoft.report.lens.swing11 This package contains table adapters for the Swing 1.1 package. The Swing package name in these classes is javax.swing.
- inetsoft.report.lens.swing This package always points to the adapters for the latest Swing version.
If your application is fixed on one version of Swing, you should choose to use the adapter package for that particular Swing version. If you intend to upgrade Swing when new versions are available, then simply use the inetsoft.report.lens.swing package. This package will always be compatible with the latest Swing version.