This topic describes how rules work in BI Beans. Rules affect the formatting of numbers in crosstabs, tables, and graphs, as well as the cell formatting in tables and crosstabs. The rules work the same way in HTML-client applications and Java-client applications.
Rule objects are stored in RuleBundle
objects. If two or more mergeable objects
set the same attribute, then the order of the rules in the rule bundle determines which of the
two settings takes effect. The last rule that applies is the one that takes effect.
All of the rules in a rule bundle must operate on the same kind of mergeable object. For
example, you cannot have a rule that operates on a ViewFormat
object and a rule
that operates on a ViewStyle
object in the same rule bundle.
The rules in a rule bundle can have different kinds of discriminators. For example,
you can have a discriminator rule that uses a QDRDiscriminator
, and another
discriminator rule that uses a NumberValueDiscriminator
, in the same rule bundle.
Rule bundles are stored in vectors. If rules in different bundles set the same attribute, the order of the bundles in the vectors determines which setting takes effect. The last rule that applies is the one that takes effect.
All of the rule bundles in the vector must operate on the same kind of mergeable object. For
example, you cannot have one bundle that works on a ViewStyle
object and another
bundle that works on a ViewFormat
object.
Each data view has a RuleManager
for each kind of mergeable object. For example,
the Graph
has a GraphRuleFormatter
class, which manages the number
formatting attributes for the numbers that appear in the graph.
You set the vector of rule bundles in the appropriate manager, that is, the manager for the kind of mergeable object on which the rules in the vector operate. For example, if you are formatting the cells of a table, then you set the bundle in the style manager for the table.
As the view displays the items that need formatting, the view calls the manager to format the item. The manager executes the vector of rules, to determine how the item in the view should be displayed.
The manager in the data view calls the runRules
method of each rule bundle in
the vector of rule bundles. In addition to an initial mergeable object on which the rules will
operate, the manager passes information about the situation of the item that is being formatted.
This information is in a RuleContext
object, which the manager creates. The
RuleContext
has such information as the row number, the column number, the
dimension members that the value represents, the value being formatted, and so on.
The runRules
method calls the applies
method of each rule in a
bundle. The applies
method examines the RuleContext
and determines
whether it matches the condition that is specified in the discriminator for the rule. For
example, if a discriminator specifies that an item should be formatted when its value is
greater than 40,000, then the applies
method checks to see if the value in the
RuleContext
is greater than 40,000.
If the rule applies, then the mergeable object in the rule is merged with the mergeable object that the manager passed to the rule bundle.
Then the mergeable objects are merged, the attribute settings that are specified in the rule's mergeable object are added to the property settings in the original mergeable object.
For example, imagine that you pass a ViewStyle
object that has two properties
set. The background is set to light blue, and the text (foreground) is set to black.
The ViewStyle
in the discriminator rule sets the text to red and the border color
to green. When the rule applies, the rule's mergeable object is merged with the original
mergeable object. As a result, the original mergeable now has the following settings:
Background -- light blue
Text (foreground) -- red
Border color -- green
Creating Rules for Formatting Dataviews
Rule Concepts
Example: Specifying
a Font Color for a Company Name
Example: Stoplight Reporting
in a Crosstab
Example: Setting the
Number Format for a Measure in a Graph