You can create rules to specify formatting for
the numbers in a Dataview
or to specify the formatting of cells in a
Gridview
. This topic describes the steps that you take to create rules. The
example that this topic presents formats the cells of a crosstab. You follow the same steps to
format the numbers in a table, graph, or crosstab. You simply use a different mergeable
object.
You need classes from the following packages when you want to use rules:
oracle.dss.dataView
oracle.dss.dataView.managers
oracle.dss.rules
oracle.dss.rules.discriminator
oracle.dss.util
The package for the view that you are working with
The .manager
package for the view that you are working with
When you create a discriminator rule, you must create the following objects and then set them in the discriminator rule:
To specify when the rule should apply, a discriminator and any objects that the discriminator
requires (such as a QDR
or a ComponentInfo
)
To specify the formatting that should take effect when the rule applies, a mergeable object
The following example shows how to create a discriminator rule that specifies that
"Oracle" should appear in a red font. To format numbers, you use a
ViewFormat
mergeable instead of a ViewStyle
.
//create a ViewStyle ViewStyle vs_redFont = new ViewStyle(); //Set the font color vs_redFont.setForeground(Color.red); //Create a discriminator that specifies when to display the item in red //First, create a QDR that specifies Oracle as the vendor QDR qdr_Oracle = new QDR("XP_MEASUREDIM", "VENDOR", "ORACLE"); //Then, create the QDRDiscriminator //This discriminator specifies that, in the formatted item, the //vendor must be Oracle. QDRDiscriminator dsc_Oracle = new QDRDiscriminator(qdr_Oracle, SUPERSET); //Create a DiscriminatorRule DiscriminatorRule dr_redOracle = new DiscriminatorRule(); //Set the discriminator, to tell when the rule should apply dr_redOracle.setDiscriminator(dsc_Oracle); //Set the ViewStyle (mergeable object), to tell what formatting should be //applied dr_redOracle.setFixedMergeable(vs_redFont);
You could also set the discriminator and the ViewStyle in the constructor, as shown in the following line of code:
DiscriminatorRule dr_redOracle = new DiscriminatorRule(dsc_Oracle, vs_redfont);
After you create the rule, you create a rule bundle and add the rule to it. You then create a vector of rule bundles and add the rule bundle to the vector. The following code shows how to create rule bundles and rule bundle vectors. This example builds upon the previous example.
//Put the rule in a rule bundle RuleBundle rb_VendorStyles = new RuleBundle(); //Add the discriminator ruler b_VendorStyles.addRule(dr_redOracle); //Create a vector for the bundle, and add the bundle Vector rbVector = new Vector(); rbVector.addElement(rb_VendorStyles);
To have the rules take effect, you pass it to the manager for the kind of mergeable on which the rules operate.
You pass a ViewStyle
to one of the following managers:
GraphRuleStyles
-- retrieve by calling
Graph.getModel().getGraphStyleManager
GridViewHeaderRuleStyles
-- retrieve by calling the
getGridViewHeaderStyleManager
method of the table or crosstab
GridViewDatabodyRuleStyles
-- retrieve by calling the
getGridViewDatabodyStyleManager
method of the table or crosstab
You pass a ViewFormat
to one of the following managers:
GraphRuleFormatter
-- retrieve by calling the getGraphFormatManager
method of the graph
GridViewRuleFormatter
-- retrieve by calling the
getGridViewFormatManager
method of the table or crosstab
The vector of rule bundles is passed by reference. You should always call the
setBundles
method of the manage explicitly, so that all notification of any changes
to the rule bundles is properly triggered.
The following code shows how to set a vector of style formatting rules into the style manager
for a crosstab. This example builds on the previous example. It also assumes that there is a
crosstab named myCrosstab
.
//Get the rules style manager for the crosstab //assumes that the crosstab you want is "myCrosstab" GridViewHeaderRuleStyles manager = myCrosstab.getGridViewHeaderStyleManager(); //Add our rule bundle vector to whatever the manager has rbMgrBundle = manager.getBundles(); if (rbMgrBundle == null){ manager.setBundles(rbVector); } else{ rbMgrBundle.addElement(rb_VendorStyles); //you must set this so the manager knows to refresh manager.setBundles(rbMgrBundle); }
How Rules Work
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