Add Map Rule in beforeFactory (BIRT)

From Eclipsepedia

Jump to: navigation, search

< To: Report Developer Examples (BIRT)
This example is Bugzilla ID 182030. If you would like to contribute an example see the example contribution guidelines.

Contents

Introduction

This example illustrates calling the BIRT Design Engine API from the beforeFactory Script to add a map rule to a report element.

BIRT Version Compatibility

This example was built and tested with BIRT 2.1.2.

Example Files

Example Report Zipped

Description

This example uses the DE API to locate a named report Data Element. Once located, the DE API is used to create and add a MAP rule to the report element.

The beforeFactory script is listed below.

importPackage(Packages.org.eclipse.birt.report.model.api);
importPackage(Packages.org.eclipse.birt.report.model.api.elements);

delm = reportContext.getReportRunnable().designHandle.getDesignHandle().findElement("QTYELEMENT");
mr = StructureFactory.createMapRule();
mr.setTestExpression("row[\"QUANTITYORDERED\"]");
mr.setOperator(DesignChoiceConstants.MAP_OPERATOR_GT);
mr.setValue1("40");
mr.setDisplay("A lot");

ph = delm.getPropertyHandle(StyleHandle.MAP_RULES_PROP);
ph.addItem(mr); 

The variable delm is set to the report element named QTYELEMENT. This means the data element in question must be named using the name property in the Property Editor. The mr variable is a map rule that is created using the DE API Structure Factory. The map rule is then applied to the data element using a Property Handle.

In this example the quantity field displays "A lot" when the quantity ordered is over 40.

Comments

Please enter comments below by selecting the edit icon to the right. You will need a Bugzilla account to add comments.