4. Customizing Crosstab Properties

Exercise Objectives

The objective of this exercise is to introduce the basic techniques for customizing a table or crosstab using the BI Beans API.

Exercise Description

Just as users want to display graphs that are user-friendly, they also want to display crosstabs and tables that are user-friendly. Previously, in these tutorials, you changed the default look-and-feel of a crosstab. Now, you will see how to define rules manually for displaying cells based on data values. This technique helps application users to identify exception data values easily.

Exercise Tasks

Add a conditional cell image

  1. Previously, you defined cell-level formatting using the Presentation Editor. Now you will add an image to data cells where the data value is less than 50,000.
  2. In the System-Navigator pane, right-click simpleJSP.jsp and choose Code Editor from the popup menu.
To import Java classes
  1. In the Code Editor, import classes into the page directive by adding the following classes within the <%@page ... "> tag import attribute:

    oracle.dss.dataView.managers.ViewStyle
    oracle.dss.thin.beans.crosstab.ThinCrosstab
    oracle.dss.rules.discriminator.NumberValueDiscriminator
    oracle.dss.rules.DiscriminatorRule
    oracle.dss.rules.RuleBundle
    oracle.dss.gridView.GridViewDatabodyStyleManager
    java.util.Vector
    java.awt.Color

    so that the code appears similar to the following line:

    <%@ page contentType="text/html;charset=WINDOWS-1252" import="oracle.dss.thin.beans.graph.ThinGraph,oracle.dss.thin.beans.graph.ImagemapAction,oracle.dss.dataView.managers.ViewStyle,oracle.dss.thin.beans.crosstab.ThinCrosstab,oracle.dss.rules.discriminator.NumberValueDiscriminator,oracle.dss.rules.DiscriminatorRule,oracle.dss.rules.RuleBundle,oracle.dss.gridView.GridViewDatabodyStyleManager,java.util.Vector,java.awt.Color" %>

    These classes will be used in the subsequent Java code.
To apply data-driven formatting by adding custom Java code
  1. Read through the following code excerpt to understand what it does. Then, in the Code Editor, copy and paste the code above the line that contains the </orabi:BIThinSession> tag:

    <%
    // Define a new crosstab cell-viewing style
    ViewStyle vsWarningCell = new ViewStyle();
    // Define the background to be red
    vsWarningCell.setBackground(Color.red);
    // Set an image to the cell
    vsWarningCell.setGraphicImageIndex(0);
    // Define the image
    ((ThinCrosstab)simpleCrosstab).setGraphicImagePath(0,"warning.gif");
    // Define a new rule that applies when the data value is below 50,000
    NumberValueDiscriminator dscLow = new NumberValueDiscriminator(50000.0, NumberValueDiscriminator.LT);
    DiscriminatorRule drLow = new DiscriminatorRule();
    // Set the new rule
    drLow.setDiscriminator(dscLow);
    drLow.setFixedMergeable(vsWarningCell);
    // Define a cell data bundle
    RuleBundle rbLow = new RuleBundle();
    // Add the new rule to the bundle
    rbLow.addRule(drLow);
    // Use the GridViewDatabodyStyleManager to apply the new bundle with
    the new rule to the data cells
    GridViewDatabodyStyleManager gvsm = ((ThinCrosstab)simpleCrosstab).getGridViewDatabodyStyleManager();
    Vector rbMgrBundle = gvsm.getBundles();
    // if no bundle exists, add the new bundle
    if (rbMgrBundle==null) {
    Vector rbVector = new Vector();
    rbVector.addElement(rbLow);
    gvsm.setBundles(simpleCrosstab, rbVector); }
    // otherwise, append the new bundle
    else {
    rbMgrBundle.addElement(rbLow);
    gvsm.setBundles(simpleCrosstab, rbMgrBundle); }
    %>

  2. From the File menu, choose Save All to save the JSP application.

Run the application

You added custom formatting to a simple crosstab. Now, run the application to see the difference that results from this formatting.

  1. In the System-Navigator pane, right-click simpleJSP.jsp and choose Run simpleJSP.jsp from the popup menu.
    A new browser window opens and displays the graph and the crosstab.
  2. As you can see, the highlighting of an important data value allows a user to quickly identify "interesting areas" for further analysis. Here, cells with sales below 50,000 contain a warning sign.
  3. Return to JDeveloper.
  4. From the Run menu, choose Terminate then Embedded OC4J Server to stop the application.

Exercise Summary

You added data-dependent cell-level formatting rules to a crosstab. With this additional functionality, users can easily identify exception data for more detailed analysis.

3. Customizing Graph Properties | Overview | 5. Building a BI Beans Catalog Browser