Example: Stoplight Reporting in a Crosstab

This example effectively produces stop light reporting for a crosstab. It formats the background colors of the cells as follows:

Value

Background Color

Above 1500

Green

500 - 1500

Yellow

Under 500

Red

This example uses three discriminator rules, and it exploits the sequence of the rules to have the colors set properly. The rules are set in the following order:

You will notice that, for example, with a value of 350, both the second and third rules will apply. Because the third rule is the last rule, the background is set to red.

Example code

The following code creates three NumberValueDiscriminator objects, three ViewStyle objects, and three DiscriminatorRule objects. It then creates the rule bundle and adds the rules in the proper order. It adds the bundle to a vector, and then sets the vector in the style manager for the crosstab.


//imports import java.util.Vector; import oracle.dss.rules.DiscriminatorRule; import oracle.dss.rules.Mergeable; import oracle.dss.rules.RuleBundle; import oracle.dss.rules.discriminator.NumberValueDiscriminator; import oracle.dss.dataView.managers.ViewStyle; import oracle.dss.gridView.GridViewDatabodyStyleManager; //Create the first DiscriminatorRule //First, create the ViewStyle, to set the color ViewStyle vs_greenCell = new ViewStyle(); vs_greenCell.setBackground(Color.green); //Then, create the NumberValueDiscriminator, to specify when to have green NumberValueDiscriminator dsc_above1500 = new NumberValueDiscriminator(1500.0, NumberValueDiscriminator.GT); //Create the rule DiscriminatorRule dr_highGreen = new DiscriminatorRule(); //Set the discriminator, to tell when the rule should apply dr_highGreen.setDiscriminator(dsc_above1500); //Set the ViewStyle (Mergeable object) to tell what formatting should //be applied dr_highGreen.setFixedMergeable(vs_greenCell); //Create the second DiscriminatorRule, in the same way ViewStyle vs_yellowCell = new ViewStyle(); vs_yellowCell.setBackground(Color.yellow); NumberValueDiscriminator dsc_1500orLess = new NumberValueDiscriminator(1500.0, NumberValueDiscriminator.LE); DiscriminatorRule dr_middleYellow = new DiscriminatorRule(); dr_middleYellow.setDiscriminator(dsc_1500orLess); dr_middleYellow.setFixedMergeable(vs_yellowCell); //Create the third DiscriminatorRule, in the same way ViewStyle vs_redCell = new ViewStyle(); vs_redCell.setBackground(Color.red); NumberValueDiscriminator dsc_below500 = new NumberValueDiscriminator(500.0, NumberValueDiscriminator.LT); DiscriminatorRule dr_lowRed = new DiscriminatorRule(); dr_lowRed.setDiscriminator(dsc_below1500); dr_lowRed.setFixedMergeable(vs_redCell); //Create the rule bundleRuleBundle rb_stopLight = new RuleBundle(); //Add the bundles, in the right order rb_stopLight.addRule(dr_highGreen); rb_stopLight.addRule(dr_middleYellow); rb_stopLight.addRule(dr_lowRed); //Create a vector for the bundle, and add the bundle Vector rbVector = new Vector(); rbVector.addElement(rb_stopLight); //Get the rules style manager for the crosstab //assumes that the crosstab you want is "myCrosstab" GridViewDatabodyRuleStyles manager = (GridViewDatabodyStyleManager)myCrosstab.getGridViewDatabodyStyleManager(); //Add our rule bundle vector to whatever the manager has rbMgrBundle = manager.getBundles(); if (rbMgrBundle == null){ manager.setBundles(myCrosstab, rbVector); } else{ rbMgrBundle.addElement(rb_stopLight); //you must set this so the manager knows to refresh manager.setBundles(myCrosstab, rbMgrBundle); }