| By Jason Weathersby, Tom Bondur, Jane Tatchell | Article Rating: |
|
| April 30, 2007 07:45 AM EDT | Reads: |
49,255 |
Examining a Report Item Programmatically
To
examine a report item, check the class of the report item, cast the
object to its actual class, then call methods appropriate to that
class. For example, the class of a label element handle is LabelHandle.
To get the text that the label displays, call LabelHandle.getText( ).
Some report items, such as a label or a text element, are simple items. Other items, such as a grid or a table element, are structured items. You can access properties for the whole of a structured item in the same way as for a simple item.
You can also iterate over the contents of the structured item. For example, use this technique to determine the contents of a cell in a table. To access the contents of a structured item, you call a method to retrieve the slot handle for rows or columns. For example, to access the RowHandle objects that make up a table element's footer, call TableHandle.getFooter( ). Table and list elements also have a slot for groups. Like the body slot handle, the slot handles for the contents of structured report items can contain zero, one, or multiple elements.
Accessing the Properties of a Report Item
To
provide information about report items, each class has getter methods
specific to the report item type. For example, an image element handle,
ImageHandle, has the getURI() method. This method returns the URI of an
image referenced by a URL or file path. The DesignElementHandle class
and other ancestor classes in the hierarchy also provide generic getter
methods, such as getName( ).
Some properties of a report item are simple properties, with types that are Java types or type wrapper classes. An example of this type of property is the name property, which is a String object. Some of these properties, like name, have arbitrary values.
Other simple properties have restricted values from a set of BIRT String constants. The interface, DesignChoiceConstants in the org.eclipse.birt.report.model.api.elements package, defines these constants. For example, the image source property of an image element can have only one of the values, IMAGE_REF_TYPE_EMBED, IMAGE_REF_TYPE_EXPR, IMAGE_REF_TYPE_FILE, IMAGE_REF_TYPE_NONE, or IMAGE_REF_TYPE_URL.
Other properties are complex properties and the getter method returns a handle object. For example, the DesignElementHandle.getStyle( ) method returns a StyleHandle.object and ReportItemHandle.getWidth( ) returns a DimensionHandle object.
The handle classes provide access to complex properties of a report item, as described later in this article. These classes provide getter methods for related properties. For example, StyleHandle classes provide access to font and background colors.
How To Access a Report Item by Name
The code sample in Listing 2 finds an image item by name, checks its type then examines its URI. The variable, design, is a ReportDesignHandle object.
How To Use the Report Structure To Access a Report Item
The code sample in Listing 3
finds an image item in a grid, checks its type, then examines its URI.
Use this technique for generic code to navigate a report design
structure or if you need to find an item that doesn't have a name. The
variable, design, is a ReportDesignHandle object.
Modifying a Report Item in a Report Design Programmatically
To set the simple properties of report items, each class has setter
methods specific to the report item type. For example, an image element
handle, ImageHandle, has the setURI( ) method. This method sets the URI
of an image referenced by the URL or file path. The DesignElementHandle
class and other ancestor classes in the hierarchy also provide generic
setter methods, such as setName( ). Setter methods throw exceptions,
such as NameException, SemanticException, and StyleException.
To set the attributes of a complex property, such as a style, you must call methods on a handle object, as described later in this article. These classes provide setter methods for related properties. For example, StyleHandle classes provide access to style properties, such as font and background color.
Changes that you make to items in the report design don't affect the design file until you save the design to disk or to a stream. After saving the design, get an IReportRunnable handle for the modified design to generate a report.
How To Change a Simple Property of a Report Item
The code sample in Listing 4
uses a method on LabelHandle to change the text in a label. The
variable, design, is a ReportDesignHandle object. This sample accesses
the label by name. You can also access a report item by navigating the
report structure.
Accessing and Setting Complex Properties
Complex
properties use BIRT handle objects to access data structures. For
example, a DimensionHandle object provides access to size and position
properties, such as the absolute value and the units of the width of a
report item.
Some String properties on a handle object, such as the font style and text alignment on a style handle, have restricted values defined by constants in the interface, DesignChoiceConstants in the org.eclipse.birt.report.model.api.elements package. For example, a font-style property can have only one of the values, FONT_STYLE_ITALIC, FONT_STYLE_NORMAL, and FONT_STYLE_OBLIQUE.
Using a Property Handle
To access complex
properties, you use getter methods on the report item. For example, to
access the width of a report item, call the method
ReportItemHandle.getWidth( ). This method returns a
DimensionHandle.object. To work with complex properties, you use getter
and setter methods on the handle object. For example, to get and set
the size of a dimension, you use DimensionHandle.getMeasure( ) and
DimensionHandle.setAbsolute( ), respectively.
When you set a value on a complex property, the change to the handle object affects the report item straightaway. You don't call an additional setter method on the report item itself.
Using Styles on a Report Item
The StyleHandle
class provides access to many fundamental properties of a report item,
such as margin size, text alignment, background color, borders, font,
and so on. StyleHandle provides a full set of getter methods for each
style property. For simple properties, StyleHandle provides setter
methods. To modify complex properties, you use setter methods on the
property handle object, not on the style handle itself.
A report item can use two styles: a private style and a shared style. The handle classes for these styles are PrivateStyleHandle and SharedStyleHandle, respectively. Both classes derive from StyleHandle.
A private style contains the settings that the report developer chose in the property editor when designing the report. Shared styles appear in the Outline view in BIRT Report Designer. You use shared styles to apply the same appearance to multiple items in a report design. Changes to a shared style affect all report items that use the style. Style settings in a private style override the settings in a shared style.
Published April 30, 2007 Reads 49,255
Copyright © 2007 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Jason Weathersby
Jason Weathersby is a member of the extended BIRT development team at Actuate Corporation and has backgrounds in both computer science and technical writing. He has many years experience in technical consulting, training, writing, and publishing about reporting, business intelligence tools, and database technologies.
More Stories By Tom Bondur
Tom Bondur is a member of the extended BIRT development team at Actuate Corporation and has backgrounds in both computer science and technical writing. He has many years experience in technical consulting, training, writing, and publishing about reporting, business intelligence tools, and database technologies.
More Stories By Jane Tatchell
Jane Tatchell is a content development manager in the Developer Communications group of Actuate Engineering.
- IBM Puts Systems Chief on Leave of Absence
- Amazon Web Services Database in the Cloud
- SpringSource Moving to Spring 3.0
- Virtualization Expo Call for Papers Deadline December 15
- Move Over BI, Here Comes PI - Performance Intelligence
- Qt DevDays 2009 - Munich
- Using Ext JS, Servlets, JSON, MySQL and Tomcat on Fedora
- Developing APIs for the Cloud
- Canonical Offers Free Cloudware
- New-Generation Virtualization Technologies with Ultra Low-Cost Endpoints
- The Planet Executive to Speak at Cloud Computing Conference
- Trusting the Cloud
- Oracle-Sun: IBM Reportedly Behind Delay
- The Case for Single-Purpose Services
- IBM Puts Systems Chief on Leave of Absence
- Cloud BI & Amazon VPC
- Cloud-Oriented Switch Start-up Valued at $230M
- The Curious Case of Build Release Management eBook
- Amazon Web Services Database in the Cloud
- Tips for Efficient PaaS Application Design
- Reporting Solutions Using Crystal Reports for Eclipse
- SpringSource Moving to Spring 3.0
- Virtualization Expo Call for Papers Deadline December 15
- Un-Clouding Federal Security Compliance
- Java Developer's Journal Exclusive: 2006 "JDJ Editors' Choice" Awards
- The i-Technology Right Stuff
- Creating Web Applications with the Eclipse Web Tools Project
- Eclipse Special: Remote Debugging Tomcat & JBoss Apps with Eclipse
- The Next Programming Models, RIAs and Composite Applications
- Where Are RIA Technologies Headed in 2008?
- How to Bring Eclipse 3.1, J2SE 5.0, and Tomcat 5.0 Together
- SYS-CON Webcast: Eclipse IDE for Students, Useful Eclipse Tips & Tricks
- Eclipse: The Story of Web Tools Platform 0.7
- "Eclipse 3.0 is a Great Leap Forward," Says JDJ's Dudney
- Developing an Eclipse BIRT Report Item Extension
- The Top 250 Players in the Cloud Computing Ecosystem


























