# Oracle Business Intelligence Beans Sample

## Formatting Crosstabs

### Overview

The Using Rules to Format Crosstabs sample application explores the use of rules to specify custom formatting for a Crosstab. `BIRules` can setup a connection to Oracle OLAP (the source of the business data for the application) and to the BI Beans Catalog (where object definitions, like crosstabs and graphs, are saved).

The `BIRules` class extends `BIFrame`. `BIRules` provides a menu with access to a simple connection dialog, which prompts a user for security credentials. It then makes the two connections described above. After the connection is established, a new crosstab can be created using the New Crosstab file menu option or toolbar button. After a new Crosstab is created, the rules menu options and toolbar buttons are enabled. When the Crosstab is closed, these options are disabled.

The rules menu options and toolbar buttons can each be toggled on and off, so that the underlying rules can be added and removed from the Crosstab. The rules provided in the sample enable a user to:

1. Format values in the Sale Revenue measure as currency

2. Format a single databody cell with a border and font style

3. Format a metadata member with particular colors and font style

4. Format databody cells belonging to divisions in the Product layer with bold and italic font styles

5. Stoplight format Sales values greater than ten million in green

6. Stoplight format Sales values less than or equal to ten million in yellow

7. Stoplight format Sales values less than or equal to two million in red

These examples demonstrate:

1. How to create rules based on QDRs, values, and combinations of multiple criteria

2. How to create number formatting rules for the databody

3. How to create style rules for the databody and the headers

4. The relationship between the order of rules in a manager and rule precedence

### Code Highlights

The bulk of the code to manipulate the Crosstab's rules can be found in the following methods. These are the methods that are called when the user adds or removes a rule using the rules menu or toolbar buttons.

`protected void applyCurrencyFormatting(boolean bApply);
protected void applySingleCellFormatting(boolean bApply);
protected void applyHeaderFormatting(boolean bApply);
protected void applyDivisionFormatting(boolean bApply);
protected void applyGreenStoplightFormatting(boolean bApply);
protected void applyYellowStoplightFormatting(boolean bApply);
protected void applyRedStoplightFormatting(boolean bApply);
protected void applyStoplightFormatting(boolean bApply, int ruleID, ViewStyle viewStyle, NumberValueDiscriminator nvDisc);`

In addition to the above methods, there are a few helper methods that the above methods call. These helper methods facilitate maintaining order among `Rules` within `RuleBundles` and among `RuleBundles` within `Vectors`.

`protected void setDatabodyStyleRuleBundle(int id, RuleBundle bundle, Vector bundles);
protected RuleBundle getDatabodyStyleRuleBundle(String name, Vector bundles);
protected void removeDatabodyStyleRuleBundle(int id, String name, Vector bundles);
protected void addDatabodyStyleRule(int ruleID, Rule rule, int ruleBundleID, RuleBundle bundle);
protected boolean removeDatabodyStyleRule(int ruleID, int ruleBundleID, RuleBundle bundle);`

Copyright © 2004 Oracle Corporation. All Rights Reserved.