Previous Next

Using Java to Write an Event Handler

Creating a Java event handler is more complex than creating a JavaScript event handler. You cannot type Java code directly in BIRT Report Designer.

To create a Java event handler class, compile the source for the Java class and make the class visible to BIRT. Creating a Java event handler for BIRT is simplified, however, by the fact that Eclipse is a robust Java development environment and supports integrating a Java project with a BIRT project.

How to create an event handler class and add it to the Java project

This section describes the process for using the Eclipse Java development environment to create an event handler class for a scriptable BIRT element. The steps assume that the Java perspective is open and that a Java project exists in the workspace.

1  
1  
In Navigator, select a Java project and choose FileProperties. In Properties, select Java Build PathLibraries. In Java Build Path, choose Add External JARs.
2  
In JAR Selection, navigate to the Eclipse /plugins directory. In a default Eclipse installation, this directory is in the following location:
<ECLIPSE_INSTALL>\eclipse\plugins
3  
Select org.eclipse.birt.core_<version>.jar. Use control-click to select org.eclipse.birt.report.engine_<version>.jar. Choose Open. Java Build Path appears, as shown in Figure 24-1. Choose OK.

Figure 24-1 The report engine JAR file in the build path

Figure 24-1  The report engine JAR file in the build path
2  
3  
1  
Navigate to the folder where you want the Java source file to reside by choosing the Browse button beside Source Folder.
2  
3  
4  
5  
*
*
In Superclass Selection, in Choose a type, type the name of the event adapter class for the ROM element. For example, for a label element, type LabelEventAdapter, as shown in Figure 24-2.

Figure 24-2 Selecting a Superclass

Figure 24-2  Selecting a Superclass
*
4  
In New Java Class, select Generate comments. New Java Class appears similar to the one shown in Figure 24-3.

Figure 24-3 New Java Class final properties

Figure 24-3  New Java Class final properties
5  

Figure 24-4 The new class in the Java editor

Figure 24-4  The new class in the Java editor
6  
Add the event handler method for the event handler class. Import all required classes. Figure 24-5 shows the addition of an onPrepare( ) method that sets the background color of a label to red.

Figure 24-5 The onPrepare( ) method in the Java editor

Figure 24-5  The onPrepare( ) method in the Java editor
7  
Choose FileSave.

How to associate a Java class with a report element

The steps in this procedure make the following assumptions:

*
*
*
1  

Figure 24-6 Selecting a report element

Figure 24-6  Selecting a report element
2  

Figure 24-7 Event handler properties

Figure 24-7  Event handler properties
3  
4  

Figure 24-8 Selecting the event handler class

Figure 24-8  Selecting the event handler class
The fully qualified name of the event handler class appears in Property Editor, as shown in Figure 24-9.

Figure 24-9 The event handler class name

Figure 24-9  The event handler class name
5  

 


(c) Copyright Actuate Corporation 2012