ConditionaStyle are the combinations of a style and a CustomExpression (a subclass of it: ConditionStyleExpression)
What’s important to understand about how conditional styles works is:
- A conditional style consists of a base style, and a list of other possible style to apply (child styles), each of them bounded to a ConditionStyleExpression object to be evaluated.
- The final style applied to an element will be the merge of the base style and the 1st style whose condition returned true
- All not null properties on the child style will override the ones at the base style.
Example of usage
Suppose you need a Column that contains numerical values. If you want to use conditional styles (in order to have different colors depending on the value, for example) you can do this:
StatusLightCondition is a particular class for that purpose, you may want to implement your own ConditionStyleExpression class.
//Create some styles Style style0 = new Style(); style0.setTextColor(Color.RED); Style style1 = new Style(); style1.setTextColor(Color.GREEN); //Create some conditions StatusLightCondition status0 = new StatusLightCondition(new Double(0), new Double(5000)); StatusLightCondition status1 = new StatusLightCondition(new Double(5000), new Double(7000)); //Create the conditional styles, and add them to an Array List ArrayList conditionalStyles = new ArrayList(); conditionalStyles.add(new ConditionalStyle(status0,style0)); conditionalStyles.add(new ConditionalStyle(status1,style1)); ColumnBuilder cb = ColumnBuilder.getNew(); //Builder initialization cb.addConditionalStyles(conditionalStyles);
This code generates a report like this:
no images were found
Refer to ConditionalStylesReportTest for a working example.