Creating Themes for a Report using BIRT

Exclusive offer: get 50% off this eBook here
BIRT 2.6 Data Analysis and Reporting

BIRT 2.6 Data Analysis and Reporting — Save 50%

Create, Design, Format, and Deploy Reports with the world's most popular Eclipse-based Business Intelligence and Reporting Tool

£16.99    £8.50
by John Ward | July 2010 | Java Open Source

BIRT is an open source business intelligence and reporting tool built on top of the Eclipse Framework. BIRT is used by developers for building reports that can best represent data and tell a story of that data that is easy to follow. In addition, BIRT can be integrated into a product to allow that product to provide reporting capabilities.

In this article by John Ward,author of BIRT 2.6 Data Analysis and Reporting we will learn how Themes provide a simple mechanism to apply a wide range of styles to an entire report design without the need to manually apply them.

Creating themes

Using the power of stylesheets and libraries, one has the ability to apply general formatting to an entire report design using themes and reuse these among different reports. Themes provide a simple mechanism to apply a wide range of styles to an entire report design without the need to manually apply them.

The following example will move the styles that we have created in our library and will show how to apply them to our report using a theme.

  1. For each of the styles we have created, select them under the Outline tab and choose Export to Library….

    Creating Themes for a Report using BIRT

  2. Choose the ClassicCarsLibrary.rptLibrary file.
  3. All of the styles will reside under the defaultTheme themes section, so select this from the drop-down list that appears next to the Theme option.

  4. Repeat these steps for all styles we have created in Customer Orders.rptDesign.
  5. Delete all of the styles stored in the Customer Orders.rptDesign file. You will notice all the styles disappear from the report designer.
  6. In the Outline tab, under the Customer Orders.rptDesign file, select the root element titled Customer Orders.rptDesign. Right-click the element and select Refresh Library.

  7. The library should already be shared since we built the report using the library's data source and datasets. If it is not, open the Resource Explorer, choose ClassicCarsLibrary.rptLibrary, right-click and choose Use Library.
  8. Under the Property Editor, change the Themes drop down to ClassicCarsLibrarydefaultTheme.
    Creating Themes for a Report using BIRT
  9. When we apply the theme, we will see the detail table header automatically apply the style for table-header.
  10. Apply the remaining custom styles to the two columns in the customer information section and the order detail row.

Now, we know that we can create several different themes by grouping styles together in libraries. So, when developing reports, you can create several different looks that can be applied to reports, simply by applying themes to reports with the help of libraries.

Using external CSS stylesheets

Another stylesheet feature is the ability to use external stylesheets and simply link to them. This works out very well when report documents are embedded into existing web portals by using the portals stylesheets to keep a consistent look and feel. This creates a sense of uniformity in the overall site.

Imagine that our graphics designer gives us a CSS file and asks us to design our reports around it. There are two ways one can use CSS files in BIRT:

  • Importing CSS files
  • Using CSS as a resource

In the following examples we are going to illustrate both scenarios. I have a CSS file containing six styles—five styles that are for predefined elements in reports and one style that is a custom style.

The following is the CSS stylesheet for the given report:

.page {
background-color: #FFFFFF;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
line-height: 24px;
color: #336699;
}

.table-group-footer-1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
line-height: 24px;
color: #333333;
background-color: #FFFFCC;
}

.title {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 24px;
line-height: 40px;
background-color: #99CC00;
color: #003333;
font-weight: bolder;
}

.table-header {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 20px;
background-color: #669900;
color: #FFFF33;
}

.table-footer {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
font-weight: bold;
line-height: 22px;
color: #333333;
background-color: #CCFF99;
}

BIRT 2.6 Data Analysis and Reporting Create, Design, Format, and Deploy Reports with the world's most popular Eclipse-based Business Intelligence and Reporting Tool
Published: July 2010
eBook Price: £16.99
Book Price: £27.99
See more
Select your format and quantity:

Importing CSS files

I will import this style for use in a new BIRT report called Top Employees that will display the employees based on associated customer sales. In this example, we will show how to import an external CSS file into a BIRT report project.

  1. Create a new report titled Top Employees, under the Classic Cars – with Library project.
  2. Import the dsClassicCars data source from ClassicCarsLibrary.rptLibrary.
  3. Create a new dataset called topEmployees using the following query:

    select
    EMPLOYEES.EMPLOYEENUMBER,
    EMPLOYEES.LASTNAME,
    EMPLOYEES.FIRSTNAME,
    ORDERDETAILS.PRICEEACH
    from
    EMPLOYEES,
    CUSTOMERS,
    ORDERS,
    ORDERDETAILS
    where
    CUSTOMERS.CUSTOMERNUMBER = ORDERS.CUSTOMERNUMBER
    and CUSTOMERS.SALESREPEMPLOYEENUMBER = EMPLOYEES.
    EMPLOYEENUMBER
    and ORDERDETAILS.ORDERNUMBER = ORDERS.ORDERNUMBER
    and ORDERS.ORDERDATE between ? and ?

  4. Create two date parameters, startDate and endDate, and link them to the two dataset parameters in topEmployees.

    Creating Themes for a Report using BIRT

  5. Insert the topEmployees dataset into the report design.

    Creating Themes for a Report using BIRT

  6. Create a grouping on the EmployeeNumber field in the table and call it employeeNumberGrouping.
  7. The following screenshot shows the table after the grouping has been created:
    Creating Themes for a Report using BIRT
  8. In the Outline tab, delete the row under the Groups header.

    Creating Themes for a Report using BIRT

  9. Drag-and-drop all of the data elements from the Tables Detail row cells into the Table Group Footers cells.

    Creating Themes for a Report using BIRT

  10. Delete the Detail Row| from the Table.

    Creating Themes for a Report using BIRT

  11. Delete the PRICEEACH data report item.
  12. Right-click on the cell where PRICEEACH was located and select Insert Aggregation|.
    Creating Themes for a Report using BIRT
  13. Fill in the following information:

    Creating Themes for a Report using BIRT

  14. Select the last column in the Table Footers row, right-click on it and select Insert Aggregation|.

    Creating Themes for a Report using BIRT

  15. Set the aggregation name to totalSales, type to SUM, value to the PRICEEACH column, and the group level to Table.

    Creating Themes for a Report using BIRT

  16. Click on the Table header row and change the text alignment to left.
  17. Click on the header label for PRICEACH and change it to EMPLOYEE SALES.

    Creating Themes for a Report using BIRT

  18. Click on the last column and change the text alignment to right. Because this is a currency field, we want this to be right justified, which is normal for accounting-related reporting.
    Creating Themes for a Report using BIRT
  19. In the data elements for totalEmployeeSales and totalSales, change the Format Number Format| as value to Currency.
    Creating Themes for a Report using BIRT
  20. Select the Master Page tab in the Report Designer.

    Creating Themes for a Report using BIRT

  21. Drag a label over to the header and enter Top Employees.

    Creating Themes for a Report using BIRT

  22. Now we need to import the stylesheet. I have it saved as topEmployees.css.In the Outline tab, right-click on Styles and select Import CSS Style….

    Creating Themes for a Report using BIRT

  23. From the dialog, navigate to where the CSS file is saved and select it.
  24. The dialog will show a list of styles in the CSS file. Click the Select All button next to the list of styles.

    Creating Themes for a Report using BIRT

  25. Click Finish. We will see all of the predefined styles getting applied automatically.
  26. TITLE, which is one of the styles defined in the CSS, is a custom style and will not automatically be defined. We need to apply it manually to the label in the Master Page. Select the label under Master Page and in the General section under the Property Editor tab, select Title from the Style listbox.

    Creating Themes for a Report using BIRT

  27. Preview the report.

    Creating Themes for a Report using BIRT

It is important to note when creating external stylesheets that as long as the style name corresponds to the BIRT Element name and is preceded by a dot, it will be applied automatically. In this earlier example, everything except TITLE was applied automatically because there is not a BIRT element called TITLE. A list of BIRT predefined style elements is available in the BIRT Style Editor, under the Pre-Defined drop-down list. If we decide to use predefined styles, the style will apply to all elements in a report unless explicitly overridden.

Using CSS as a resource

Another option is to import the CSS style as a report project resource and use the file in our resources folder.

  1. Delete the styles in the Top Employees report.

    Creating Themes for a Report using BIRT

  2. Open the Resource Explorer.
  3. Right-click on either the Shared Resources section or one of our project subfolders, and choose Add Resource.

    Creating Themes for a Report using BIRT

  4. Navigate to where the topEmployees.css file is located and click Finish.

    Creating Themes for a Report using BIRT

  5. The CSS file is now part of your project resources. In the Outline tab, right-click on Styles and select Use CSS File….

    If Use CSS… is chosen from the Resource Explorer, step 6 can be skipped.

    Creating Themes for a Report using BIRT

  6. From the Use CSS… dialog, click on the Browse button to select file.
  7. We will see two tree view nodes, with the Shared Resources folder available to be expanded. Expand the Shared Resources folder and select the topEmployees.css file.

    Creating Themes for a Report using BIRT

  8. A list of styles will show up under the Available styles… box. Just click OK as there is no option to select individual styles.

    Creating Themes for a Report using BIRT

  9. The styles that are predefined BIRT element names get automatically applied. Go ahead and apply the custom style of title to the master page header section.We might notice that the Styles section in the Outline tab is a little different. Rather than displaying the styles themselves, when using a resource, it shows the CSS filename, and when we right-click on the filename, we have the option to reload. This allows users to make changes to the external CSS file and reload them into the BIRT report without having to re-import the CSS file.

    Creating Themes for a Report using BIRT

Summary

In this article we have learned how Themes provide a simple mechanism to apply a wide range of styles to an entire report design without the need to manually apply them

BIRT 2.6 Data Analysis and Reporting Create, Design, Format, and Deploy Reports with the world's most popular Eclipse-based Business Intelligence and Reporting Tool
Published: July 2010
eBook Price: £16.99
Book Price: £27.99
See more
Select your format and quantity:

About the Author :


John Ward

John Ward is a consultant for Innovent Solutions, specializing in BIRT and e-commerce search and navigation solutions. Prior to that, John was an Assistant Vice President for Citibank, North America, managing the training MIS group and overseeing development of new technology-based training initiatives. John actively works with and tests BIRT—an open-source reporting platform built on Eclipse—including development work based on BIRT reports and the BIRT APIs.

John also maintains The Digital Voice blog at http://digiassn.blogspot.com

Books From Packt


JasperReports 3.6 Development Cookbook
JasperReports 3.6 Development Cookbook

Liferay Portal 6 Enterprise Intranets
Liferay Portal 6 Enterprise Intranets

Microsoft Dynamics NAV 2009 Application Design
Microsoft Dynamics NAV 2009 Application Design

Drupal E-commerce with Ubercart 2.x
Drupal E-commerce with Ubercart 2.x

Pentaho 3.2 Data Integration: Beginner's Guide
Pentaho 3.2 Data Integration: Beginner's Guide

IBM Cognos 8 Report Studio Cookbook
IBM Cognos 8 Report Studio Cookbook

Oracle Siebel CRM 8 Installation and Management
Oracle Siebel CRM 8 Installation and Management

Oracle SOA Suite 11g R1 Developer's Guide
Oracle SOA Suite 11g R1 Developer's Guide


Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software