Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » Newbie: Add new Element to report(How to add an element to a report)
Newbie: Add new Element to report [message #682126] Fri, 10 June 2011 13:16 Go to next message
endiBirt  is currently offline endiBirt Friend
Messages: 13
Registered: June 2011
Junior Member
Hi all,

I am new to birt. So thank you for your patience. May be this was posted many times I didn't find it via google.

Here is the problem:

There is a webservice. I made a report with the Birt Report Designer 2.6.2 and these webservice is the scripted datasource. Via the open-Methode of the dataset I call the webservice and via the fetch-Methode the values the webservice transmitted get written to the OutputColumns.

One of the values the webservice sends is an array. The length of the array is variable. I know the length of the array in the fetch-Methode. So there is the point where I should add elements to the report in dependence of the length of the array. So I have found the Birt Programmers Reference and some code snippets via google.

Now I want to add some script to my report to dynamically add elements to my report. I searched for a global object to get to the report object with some kind of methods to add some elements.

I have found the class SessionHandle that I need for ReportDesignHandle with wich I can get the ElementFactory to create new Report-Elements. But I have difficulties with the session. I need a ReportDesignHandle that I can get from the SessionHandle but this SessionHandle I can only get via the createDesign()-Methode. But this means create a new report. And I think I don't need a new report. There is alreade a report created but I don't know how to catch him.


Please help.

Thanks for any help in advance.


Regards

Andreas
Re: Newbie: Add new Element to report [message #682216 is a reply to message #682126] Fri, 10 June 2011 16:16 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

If you want to add elements to the report in script the last place you
can do this is in the beforeFactory script which will happen before any
datasets are called. You could call your web service method using
JavaScript in the beforeFactory and then get the report design handle to
add elements though. To get the design handle just use:

reportContext.getDesignHandle();

attached is a report where the entire report is constructed in the
beforeFactory using JavaScript. If there is a specific example you want
let me know.

Jason

<?xml version="1.0" encoding="UTF-8"?>
<report xmlns="http://www.eclipse.org/birt/2005/design" version="3.2.20"
id="1">
<property name="createdBy">Eclipse BIRT Designer Version
2.5.1.v20090903 Build &lt;2.5.1.v20090917-1447></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.getDesignHandle();
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 );





mytable = elementFactory.newTableItem( null, 3, 1, 1, 1 );
mytable.setWidth( "80%" );
mytable.setProperty( "dataSet", "Data Set" );//$NON-NLS-1$



computedSet = mytable.getColumnBindings( );

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 );

cs4 = StructureFactory.createComputedColumn( );
cs4.setName( "SumAmnt" );//$NON-NLS-1$
cs4.setExpression( "row[\"Amount\"]" );//$NON-NLS-1$
cs4.setAggregateFunction("Sum");
cs4.setDataType( "integer" );//$NON-NLS-1$
computedSet.addItem( cs4 );




// Header
myheader = mytable.getHeader( ).get( 0 );

tcell = myheader.getCells( ).get( 0 );
mylabel = elementFactory.newLabel( null );
mylabel.setText( "Col1" );//$NON-NLS-1$
tcell.getContent( ).add( mylabel );



tcell = myheader.getCells( ).get( 1 );
mylabel = elementFactory.newLabel( null );
mylabel.setText( "Col2" );//$NON-NLS-1$
tcell.getContent( ).add( mylabel );


tcell = myheader.getCells( ).get( 2 );
//mylabel = elementFactory.newLabel( null );
//mylabel.setText( "Col3" );//$NON-NLS-1$
//tcell.getContent( ).add( mylabel );

mydata = elementFactory.newDataItem( null );
mydata.setResultSetColumn( "SumAmnt");
tcell.getContent( ).add( mydata );







mydetail = mytable.getDetail( ).get( 0 );
tcell = mydetail.getCells( ).get( 0 );
mydata = elementFactory.newDataItem( null );
mydata.setResultSetColumn( "Month");
tcell.getContent( ).add( mydata );

tcell = mydetail.getCells( ).get( 1 );
mydata = elementFactory.newDataItem( null );
mydata.setResultSetColumn( "Product");
tcell.getContent( ).add( mydata );

tcell = mydetail.getCells( ).get( 2 );
mydata = elementFactory.newDataItem( null );
mydata.setResultSetColumn( "Amount");
tcell.getContent( ).add( mydata );



reportDesignHandle.getBody( ).add( mytable );]]></method>
<property name="layoutPreference">auto layout</property>
<data-sources>
<script-data-source name="Data Source" id="4"/>
</data-sources>
<page-setup>
<simple-master-page name="Simple MasterPage" id="2">
<property name="topMargin">1in</property>
<property name="leftMargin">1.25in</property>
<property name="bottomMargin">1in</property>
<property name="rightMargin">1.25in</property>
<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>


On 6/10/2011 9:16 AM, forums-noreply@eclipse.org wrote:
> Hi all,
>
> I am new to birt. So thank you for your patience. May be this was posted
> many times I didn't find it via google.
> Here is the problem:
>
> There is a webservice. I made a report with the Birt Report Designer
> 2.6.2 and these webservice is the scripted datasource. Via the
> open-Methode of the dataset I call the webservice and via the
> fetch-Methode the values the webservice transmitted get written to the
> OutputColumns.
> One of the values the webservice sends is an array. The length of the
> array is variable. I know the length of the array in the fetch-Methode.
> So there is the point where I should add elements to the report in
> dependence of the length of the array. So I have found the Birt
> Programmers Reference and some code snippets via google.
> Now I want to add some script to my report to dynamically add elements
> to my report. I searched for a global object to get to the report object
> with some kind of methods to add some elements.
> I have found the class SessionHandle that I need for ReportDesignHandle
> with wich I can get the ElementFactory to create new Report-Elements.
> But I have difficulties with the session. I need a ReportDesignHandle
> that I can get from the SessionHandle but this SessionHandle I can only
> get via the createDesign()-Methode. But this means create a new report.
> And I think I don't need a new report. There is alreade a report created
> but I don't know how to catch him.
>
>
> Please help.
>
> Thanks for any help in advance.
>
>
> Regards
>
> Andreas
Re: Newbie: Add new Element to report [message #683714 is a reply to message #682216] Tue, 14 June 2011 09:39 Go to previous message
endiBirt  is currently offline endiBirt Friend
Messages: 13
Registered: June 2011
Junior Member
Hello Jason,

thank you very much for your reply. This is exactly what I was searching for.

Thanks again.


Regards

Andreas
Previous Topic:Dynamically created dataset and table report does not show detail
Next Topic:Where to put a function that is referenced in a master page?
Goto Forum:
  


Current Time: Mon Dec 22 15:41:59 GMT 2014

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

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