Creating a Report With Eclipse BIRT Report Designer
This chapter provides a brief introduction to the Eclipse BIRT Report Designer. It is highly recommended to read dedicated BIRT literature to get an impression what BIRT has to offer. In the following chapters a BIRT report that is able to display the logbook management data is created from scratch.
Create a New Project
- Get Eclipse BIRT (http://eclipse.org/birt: new window).
- Create a new “Report Project” and follow the wizard.
- Create a new “Report” and follow the wizard (create a blank report).
Get Sample XML Data
The design process is based on a sample data source. In this case the generated XML data should be the data source. To avoid writing the XML file manually you can add following lines to the CreateBirtReport use case.
Example |
---|
GENCONT@1.1:ContentObject resultxmlobj = #GENCONT@1.1:ContentObject.ObjectCreate()[2]; resultxmlobj.content.contcontent = xmlcont; resultxmlobj.content.contextension = "txt"; resultxmlobj.objname = "Result XML " + coort.GetCurrentDateTime(cooobj); |
Now you can search for the content object in Fabasoft Folio and use the XML as data source (may also be useful for debugging purposes).
Specify a Data Source
Use the previously generated sample XML as data source.
- Create a new data source.
- Select “XML Data Source” and specify the path to the sample XML file.
Specify Data Sets
Based on the data source, data sets can be created. For the logbook management example two data sets are required:
- A logbook management can contain several logbooks.
- A logbook can contain several trips.
To put this hierarchy into relation the two data sets are used. The first data set selects the logbooks and the second data set selects the trips. The ID attribute of the logbook is used to match the trips with the corresponding logbook. This is a generic pattern when working with such hierarchies.
- Create a new data set.
- Name the data set “logbook”.
- To select all logbook XML elements, define as “Row Mapping” the XPath expression //logbook.
- In the “Column Mapping” section add the values that should be display in the report for logbooks or are used for computation (ID attribute).
To create the second data set, perform the following steps:
- Create a second data set named “logtriplog”.
- As “Row Mapping” use the XPath expression //logbook[@id="{?logbook?}"]/logtriplog. The XML attribute “id” is used to match the trip with the corresponding logbook.
Note: BIRT only allows XML attributes for filtering, not XML elements.
- In the “Column Mapping” section add the values that should be display in the report for trips.
- When finishing the creation of the data set click “OK” to let the “logbook” parameter empty.
Arranging the Report
You can arrange the parts of the report mainly with drag and drop. In this example two lists are used that have a binding to the two data sets. The second list containing the trips uses the “logbook” parameter to display the trips that belong to the corresponding logbook.
- Switch to the “Palette” tab and drag a “List” to the report.
- Select “logbook” as binding in the “Property Editor” for this list.
- Drag a second list in the “Detail” section of the first list.
- Select “logtriplog” as binding in the “Property Editor” for this list.
- To define the parameter that is used for filtering the trips that belong to the logbook, click “Data Set Parameter Binding”.
- Specify row["id"] as value for the “logbook” parameter. This way the XML attribute “id” is used for filtering.
- Switch to the “Data Explorer” tab and drag “objname” and “logdescription” in the detail section of the first list right before the second list.
- Drag “trlfrom”, “trluntil” and “trlmiles” in the detail section of the second list.
- Switch to the “Preview” tab.
Now the desired report functionality is given. BIRT offers a lot of possibilities to improve the layout and format the values of a report. When you are glad with your report put it in the resources folder of your app.ducx project, run the project again and generate a PDF report with the new design.
A report of a fully featured logbook management project may look like this: