> #### 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 | Add org.eclipse.birt.report.engine_<version>.jar to a Java project, as described in the following steps:

> 1 | In Navigator, select a Java project and choose File→Properties. In Properties, select Java Build Path→Libraries. 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 23-1. Choose OK.

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

> 2 | Select the Java project and choose File→New→Class.

> 3 | To set up the Java class properties, perform the following steps in New Java Class:

> 1 | Navigate to the folder where you want the Java source file to reside by choosing the Browse button beside Source Folder.

> 2 | If the new Java class is a part of a package, type the fully qualified package name in Package.

> 3 | In Name, type a name for the class.

> 4 | In Modifiers, select Public.

> 5 | Select the ROM element event adapter class to extend:

> | Choose the Browse button beside Superclass.

> | 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 23-2.

> Figure 23-2 Selecting a Superclass

> | Choose OK.

> 4 | In New Java Class, select Generate comments. New Java Class appears similar to the one shown in Figure 23-3.

> Figure 23-3 New Java Class final properties

> 5 | Choose Finish. The Java editor appears, similar to the one shown in Figure 23-4.

> Figure 23-4 The new class in the Java editor

> 6 | Add the event handler method for the event handler class. Import all required classes. Figure 23-5 shows the addition of an onPrepare( ) method that sets the background color of a label to red.

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

> 7 | Choose File→Save.

(c) Copyright Actuate Corporation 2013