Skip to main content



      Home
Home » Archived » BIRT » Scripted Data Set 'describe' event
Scripted Data Set 'describe' event [message #206628] Fri, 15 December 2006 09:03 Go to next message
Eclipse UserFriend
Originally posted by: phil.issler.dataflux.com

Has anyone successfully written script for the 'describe' event of a
Scripted Data Set? The only documentation about this I can find is in
the ROM documentation. I need to dynamically create the columns in the
dataset at runtime.

When I try to create a ResultSetColumn object in Javascript, BIRT
complains that the class is not found. I tried importing the BIRT
package org.eclipse.birt.report.model.api.elements.structures to use the
Java version of the class, but it has different member names from what
is described in the ROM, and it explodes when I try to run the report or
preview the data set.

The new "Integrating and Extending BIRT" book fails to mention this
event as well. Can anyone send me some example code?
Re: Scripted Data Set 'describe' event [message #206703 is a reply to message #206628] Fri, 15 December 2006 12:06 Go to previous message
Eclipse UserFriend
The describe event is currently not implemented.
In order to add columns dynmaically you will need to use the DE API.
This can be done in Java. Look at
http://wiki.eclipse.org/index.php/BIRT_Design_Engine_API
Specifically the Dynamic Report Servlet.

Another option (although prbly not optimal) is to call the DE API from
script.
Attached is a report that is blank with one scripted data source. In the
before factory event
I call the DE API to modify the currently running report to add columns to
the scripted data set and
add a table that uses it to the report.

Jason


<?xml version="1.0" encoding="UTF-8"?>

<!-- Written by Eclipse BIRT 2.0 -->

<report xmlns="http://www.eclipse.org/birt/2005/design" version="3.2.6"
id="1">

<property name="createdBy">Eclipse BIRT Designer Version
2.1.1.v20060922-1058 Build &lt;20060926-0959></property>

<property name="units">in</property>

<property name="comments">Copyright (c) 2006 &lt;&lt;Your Company Name
here>></property>

<method name="beforeFactory"><![CDATA[importPackage(
Packages.org.eclipse.birt.report.model.api );


reportDesignHandle =
reportContext.getReportRunnable().designHandle.getDesignHand le();

elementFactory = reportDesignHandle.getElementFactory()

dataSetHandle = elementFactory.newScriptDataSet( "Data Set" );

dataSetHandle.setDataSource( "Data Source" );


dataSetHandle.setOpen( "i=0;" );


dataSetHandle.setFetch( "if ( i < 4 ){"

+ "row[\"Month\"] = 1;"

+ "row[\"Product\"] = 'My Product';"

+ "row[\"Amount\"] = i;"

+ "i++;"

+ "return true;}" + "else return false;" );


// Set computed columns

cs1 = StructureFactory.createComputedColumn( );

cs1.setName( "Month" );//$NON-NLS-1$

cs1.setExpression( "row[\"Month\"]" );//$NON-NLS-1$

cs1.setDataType( "integer" );//$NON-NLS-1$


cs2 = StructureFactory.createComputedColumn( );

cs2.setName( "Product" );//$NON-NLS-1$

cs2.setExpression( "row[\"Product\"]" );//$NON-NLS-1$

cs2.setDataType( "string" );//$NON-NLS-1$


cs3 = StructureFactory.createComputedColumn( );

cs3.setName( "Amount" );//$NON-NLS-1$

cs3.setExpression( "row[\"Amount\"]" );//$NON-NLS-1$

cs3.setDataType( "integer" );//$NON-NLS-1$


computedSet = dataSetHandle.getPropertyHandle( "computedColumns" );

computedSet.addItem( cs1 );

computedSet.addItem( cs2 );

computedSet.addItem( cs3 );


reportDesignHandle.getDataSets( ).add( dataSetHandle );









table = elementFactory.newTableItem( null, 3, 1, 1, 1 );

table.setWidth( "80%" );

table.setProperty( "dataSet", "Data Set" );//$NON-NLS-1$










// Header

header = table.getHeader( ).get( 0 );


tcell = header.getCells( ).get( 0 );

label = elementFactory.newLabel( null );

label.setText( "Col1" );//$NON-NLS-1$

tcell.getContent( ).add( label );






tcell = header.getCells( ).get( 1 );

label = elementFactory.newLabel( null );

label.setText( "Col2" );//$NON-NLS-1$

tcell.getContent( ).add( label );




tcell = header.getCells( ).get( 2 );

label = elementFactory.newLabel( null );

label.setText( "Col3" );//$NON-NLS-1$

tcell.getContent( ).add( label );






















computedSet = table.getColumnBindings( );

cs1 = StructureFactory.createComputedColumn( );

cs2 = StructureFactory.createComputedColumn( );

cs3 = StructureFactory.createComputedColumn( );

cs1.setName("Month");

cs1.setExpression( "dataSetRow[\"Month\"]" );

computedSet.addItem( cs1 );

cs2.setName("Product");

cs2.setExpression( "dataSetRow[\"Product\"]" );

computedSet.addItem( cs2 );

cs3.setName("Amount");

cs3.setExpression( "dataSetRow[\"Amount\"]" );

computedSet.addItem( cs3 );


















detail = table.getDetail( ).get( 0 );

tcell = detail.getCells( ).get( 0 );

data = elementFactory.newDataItem( null );

data.setResultSetColumn( "Month");

tcell.getContent( ).add( data );


tcell = detail.getCells( ).get( 1 );

data = elementFactory.newDataItem( null );

data.setResultSetColumn( "Product");

tcell.getContent( ).add( data );


tcell = detail.getCells( ).get( 2 );

data = elementFactory.newDataItem( null );

data.setResultSetColumn( "Amount");

tcell.getContent( ).add( data );






reportDesignHandle.getBody( ).add( table );]]></method>

<data-sources>

<script-data-source name="Data Source" id="4"/>

</data-sources>

<page-setup>

<simple-master-page name="Simple MasterPage" id="2">

<page-footer>

<text id="3">

<property name="contentType">html</property>

<text-property name="content"><![CDATA[<value-of>new
Date()</value-of>]]></text-property>

</text>

</page-footer>

</simple-master-page>

</page-setup>

</report>



"Phil Issler" <phil.issler@dataflux.com> wrote in message
news:elu9vn$at0$1@utils.eclipse.org...
> Has anyone successfully written script for the 'describe' event of a
> Scripted Data Set? The only documentation about this I can find is in the
> ROM documentation. I need to dynamically create the columns in the
> dataset at runtime.
>
> When I try to create a ResultSetColumn object in Javascript, BIRT
> complains that the class is not found. I tried importing the BIRT package
> org.eclipse.birt.report.model.api.elements.structures to use the Java
> version of the class, but it has different member names from what is
> described in the ROM, and it explodes when I try to run the report or
> preview the data set.
>
> The new "Integrating and Extending BIRT" book fails to mention this event
> as well. Can anyone send me some example code?
Previous Topic:Problems in installing BIRT source code
Next Topic:Connecting to db in designer is VERY slow
Goto Forum:
  


Current Time: Mon May 12 03:21:17 EDT 2025

Powered by FUDForum. Page generated in 0.03138 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top