Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » Inserting a chart in between report elements(Is this possible?)
Inserting a chart in between report elements [message #671691] Wed, 18 May 2011 17:21 Go to next message
Olly   is currently offline Olly Friend
Messages: 61
Registered: June 2010
Location: Florida
Member
Is it possible to insert a chart in the report in between a current chart and the table? I'd like to add charts on the fly, possibly 1, 2 or 3 in between the first chart and the table. Any help is greatly appreciated. I am running birt 2.6.2. I've modified the ExecuteModifiedReport.java code but I'm getting the error:
Exception in thread "main" java.lang.NoSuchMethodError: org.eclipse.birt.report.engine.api.HTMLRenderContext.setRenderOption(Lorg/eclipse/birt/report/engine/api/IRenderOption;)V

My source code is here:
public void runReport() throws EngineException
	{

		IReportEngine engine=null;
		EngineConfig config = null;
	
		try{

		
			//Configure the Engine and start the Platform
			config = new EngineConfig( );
			config.setEngineHome( BIRT_LOCATION );
			config.setLogConfig(null, Level.FINE);

			Platform.startup( config );
			IReportEngineFactory factory = (IReportEngineFactory) Platform
			.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
			engine = factory.createReportEngine( config );
			engine.changeLogLevel( Level.WARNING );

		}catch( Exception ex){
			ex.printStackTrace();
		}

		IReportRunnable theRunnableDesign = null;

		try
		{
			//Open the report design
			theRunnableDesign = engine.openReportDesign(DESIGN_FILE);
		}
		catch(EngineException ex)
		{
			ex.printStackTrace();
		}
		 


		ReportDesignHandle theReportDesignHandle = 
			(ReportDesignHandle) theRunnableDesign.getDesignHandle( );
		buildReport( theReportDesignHandle ); 

		//Create task to run and render the report,
		IRunAndRenderTask task = engine.createRunAndRenderTask(theRunnableDesign); 
		task.getAppContext().put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY, 
				ExecuteModifiedReport.class.getClassLoader());
		
		IRenderOption theIRenderOption = new RenderOption();
		theIRenderOption.setOutputFormat(OUTPUT_FORMAT);
		theIRenderOption.setOutputFileName(GENERATED_REPORT);
		
		// set the html render option
		HTMLRenderOption theHTMLOptions = 
			new HTMLRenderOption(theIRenderOption);

		theHTMLOptions.setImageDirectory(IMAGE_DIRECTORY);
		theHTMLOptions.setHtmlPagination(false);
		theHTMLOptions.setEmbeddable(true);
		theHTMLOptions.setBaseURL(IMAGE_DIRECTORY);
		
		task.setRenderOption(theHTMLOptions);

		//run the report and destroy the engine
		//Note - If the program stays resident do not shutdown the Platform or the Engine
		task.run();
		task.close();
		engine.shutdown();
		Platform.shutdown();
		System.out.println("Finished generating report"); 
	}	

	public void buildReport(ReportDesignHandle theReportDesignHandle){

	
		try{
		ElementFactory designFactory = theReportDesignHandle.getElementFactory( );

		buildDataSource(designFactory, theReportDesignHandle);
		
		// Get the label that represents the title label
		LabelHandle theTitleLabelHandle = 			
			(LabelHandle) theReportDesignHandle.getElementByID(59);
			/*(LabelHandle)theReportDesignHandle.findElement("theReportTitle");*/
		
		if(theTitleLabelHandle != null)
		{
			// set the label's title to report title
			theTitleLabelHandle.setText("My New Report");
		}
 		
		ArrayList cols = new ArrayList();
		cols.add("OFFICECODE");
 		cols.add("CITY");
 		cols.add("COUNTRY");
  
		buildDataSet(cols, "From Offices", designFactory, theReportDesignHandle);

		TableHandle table = designFactory.newTableItem( "table", cols.size() );
		table.setWidth( "100%" );
		table.setDataSet( theReportDesignHandle.findDataSet( "ds" ) );


   		PropertyHandle computedSet = table.getColumnBindings( ); 
		ComputedColumn  cs1 = null;
 
 		for( int i=0; i < cols.size(); i++){
  			cs1 = StructureFactory.createComputedColumn();
 			cs1.setName((String)cols.get(i)); 
			cs1.setExpression("dataSetRow[\"" + (String)cols.get(i) + "\"]");
			computedSet.addItem(cs1);
		}

 
		// table header
		RowHandle tableheader = (RowHandle) table.getHeader( ).get( 0 );


		for( int i=0; i < cols.size(); i++){
			LabelHandle label1 = designFactory.newLabel( (String)cols.get(i) );	
			label1.setText((String)cols.get(i));
			CellHandle cell = (CellHandle) tableheader.getCells( ).get( i );
			cell.getContent( ).add( label1 );
		}							

		// table detail
		RowHandle tabledetail = (RowHandle) table.getDetail( ).get( 0 );
 		for( int i=0; i < cols.size(); i++){
			CellHandle cell = (CellHandle) tabledetail.getCells( ).get( i );
			DataItemHandle data = designFactory.newDataItem( "data_"+(String)cols.get(i) );
			data.setResultSetColumn( (String)cols.get(i));
			cell.getContent( ).add( data );
		}



		theReportDesignHandle.getBody( ).add( table );
		}catch(Exception e){
			e.printStackTrace();
		}

	}

	void buildDataSource( ElementFactory designFactory, ReportDesignHandle designHandle ) throws SemanticException
	{

		OdaDataSourceHandle dsHandle = designFactory.newOdaDataSource(
				"Data Source", "org.eclipse.birt.report.data.oda.jdbc" );
		dsHandle.setProperty( "odaDriverClass",
		"org.eclipse.birt.report.data.oda.sampledb.Driver" );
		dsHandle.setProperty( "odaURL", "jdbc:classicmodels:sampledb" );
		dsHandle.setProperty( "odaUser", "ClassicModels" );
		dsHandle.setProperty( "odaPassword", "" );

 		designHandle.getDataSources( ).add( dsHandle );

	}

	void buildDataSet(ArrayList cols, String fromClause, ElementFactory designFactory, ReportDesignHandle designHandle ) throws SemanticException
	{

		OdaDataSetHandle dsHandle = designFactory.newOdaDataSet( "ds",
		"org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
		dsHandle.setDataSource( "Data Source" );
		String qry = "Select ";
		for( int i=0; i < cols.size(); i++){
			qry += " " + cols.get(i);
			if( i != (cols.size() -1) ){
				qry += ",";
			}

		}
		qry += " " + fromClause;

		dsHandle.setQueryText( qry );

		designHandle.getDataSets( ).add( dsHandle );


	}

	/**
 	 * @param args
	 */
 	public static void main(String[] args) {
 		try
		{
			
			ExecuteModifiedReport ex = new ExecuteModifiedReport( );
			ex.runReport();
			
		}
		catch ( Exception e )
		{
			e.printStackTrace();
		}
	}

[Updated on: Wed, 18 May 2011 17:45]

Report message to a moderator

Re: Modifying text in existing labels and inserting a chart [message #671719 is a reply to message #671691] Wed, 18 May 2011 19:14 Go to previous message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

I was able to change the label using code similar to the following:

package DEAPI;



import java.util.HashMap;
import java.util.List;
import java.util.logging.Level;

import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineConstants;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.HTMLActionHandler;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.HTMLServerImageHandler;
import org.eclipse.birt.report.engine.api.HTMLCompleteImageHandler;
import org.eclipse.birt.report.engine.api.IReportDocument;

import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import org.eclipse.birt.report.engine.api.RenderOption;

import org.eclipse.birt.report.model.api.DataSetHandle;
import org.eclipse.birt.report.model.api.DesignElementHandle;
import org.eclipse.birt.report.model.api.ElementFactory;
import org.eclipse.birt.report.model.api.LabelHandle;
import org.eclipse.birt.report.model.api.OdaDataSetHandle;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.activity.SemanticException;
import org.eclipse.birt.report.model.api.core.IDesignElement;
import org.eclipse.birt.report.model.core.DesignElement;
import org.eclipse.birt.report.model.elements.OdaDataSet;




public class ModifyRunningReportLabel {

public void runReport() throws EngineException
{

IReportEngine engine=null;
EngineConfig config = null;

try{

config = new EngineConfig( );

config.setBIRTHome("C:/birt/birt-runtime-2_6_1/birt-runtime-2_6_1/ReportEngine");
config.setLogConfig(null, Level.FINE);

Platform.startup( config );
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject(
IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );


IReportRunnable design = null;
//Open the report design
design = engine.openReportDesign("Reports/TopNPercent.rptdesign");
ReportDesignHandle report = (ReportDesignHandle)
design.getDesignHandle( );

LabelHandle lh = (LabelHandle) report.getElementByID(178);
lh.setText("Changed Label");
report.saveAs("Reports/topnlabel.rptdesign");

//charttocopy.setName("SecondChart");
//only needed if you do not rename the copy
//report.getModule().makeUniqueName( charttocopy );
//report.getBody( ).add( charttocopy.getHandle(report.getModule()) );

//Use this if you want to resave modified example
//report.saveAs("Reports/chartcopy.rptdesign");



//Create task to run and render the report,
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
task.setParameterValue("Top Percentage", new Integer(3));
task.setParameterValue("Top Count", new Integer(5));
task.validateParameters();

HTMLRenderOption options = new HTMLRenderOption();

options.setOutputFileName("output/desample/ModifiedTopNPercentLabel.html");
options.setOutputFormat("html");
options.setImageDirectory("images");

task.setRenderOption(options);



task.run();

task.close();




engine.destroy();
Platform.shutdown();
System.out.println("Finished");


}catch( Exception ex){
ex.printStackTrace();
}


}


/**
* @param args
*/
public static void main(String[] args) {
try
{

ModifyRunningReportLabel ex = new ModifyRunningReportLabel( );
ex.runReport();

}
catch ( Exception e )
{
e.printStackTrace();
}
}


}


Also using the de api you can add any component you want. Here is an
example using the ce and de apis to create a report with a chart.

package DEAPI;

import java.io.IOException;

import org.eclipse.birt.chart.model.Chart;
import org.eclipse.birt.chart.model.ChartWithAxes;
import org.eclipse.birt.chart.model.attribute.AxisType;
import org.eclipse.birt.chart.model.attribute.IntersectionType;
import org.eclipse.birt.chart.model.attribute.LegendItemType;
import org.eclipse.birt.chart.model.attribute.Palette;
import org.eclipse.birt.chart.model.attribute.TickStyle;
import org.eclipse.birt.chart.model.attribute.impl.ColorDefinitionImpl;
import org.eclipse.birt.chart.model.attribute.impl.PaletteImpl;
import org.eclipse.birt.chart.model.component.Axis;
import org.eclipse.birt.chart.model.component.Series;
import org.eclipse.birt.chart.model.component.impl.SeriesImpl;
import org.eclipse.birt.chart.model.data.BaseSampleData;
import org.eclipse.birt.chart.model.data.DataFactory;
import org.eclipse.birt.chart.model.data.OrthogonalSampleData;
import org.eclipse.birt.chart.model.data.SampleData;
import org.eclipse.birt.chart.model.data.SeriesDefinition;
import org.eclipse.birt.chart.model.data.impl.QueryImpl;
import org.eclipse.birt.chart.model.data.impl.SeriesDefinitionImpl;
import org.eclipse.birt.chart.model.impl.ChartWithAxesImpl;
import org.eclipse.birt.chart.model.layout.Legend;
import org.eclipse.birt.chart.model.layout.Plot;
import org.eclipse.birt.chart.model.type.LineSeries;
import org.eclipse.birt.chart.model.type.impl.LineSeriesImpl;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.model.api.DataSetHandle;
import org.eclipse.birt.report.model.api.DesignConfig;
import org.eclipse.birt.report.model.api.ElementFactory;
import org.eclipse.birt.report.model.api.ExtendedItemHandle;
import org.eclipse.birt.report.model.api.IDesignEngine;
import org.eclipse.birt.report.model.api.IDesignEngineFactory;
import org.eclipse.birt.report.model.api.OdaDataSetHandle;
import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
import org.eclipse.birt.report.model.api.PropertyHandle;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.SessionHandle;
import org.eclipse.birt.report.model.api.SimpleMasterPageHandle;
import org.eclipse.birt.report.model.api.StructureFactory;
import org.eclipse.birt.report.model.api.activity.SemanticException;
import org.eclipse.birt.report.model.api.command.ContentException;
import org.eclipse.birt.report.model.api.command.NameException;
import
org.eclipse.birt.report.model.api.elements.structures.PropertyBinding;

import com.ibm.icu.util.ULocale;


public class SimpleChart

{

private ReportDesignHandle reportDesignHandle = null;

private ElementFactory elementFactory = null;

private OdaDataSourceHandle odaDataSourceHandle = null;

private String dataSourceName = "datasource";

private String dataSetName = "maindataset";
private SessionHandle sessionHandle =null;

org.eclipse.birt.report.model.api.elements.structures.ComputedColumn
cs1, cs2 = null;

public static void main(String args[])

{
try {

new SimpleChart().createReport();

} catch (Exception e) {

e.printStackTrace();

}

}


public void createReport() throws SemanticException, IOException

{
System.out.println("Start");
init();

createMasterPages();

buildDataSource();
buildDataSet();
createBody();


reportDesignHandle.saveAs("output/desample/simplechart.rptdesign");
reportDesignHandle.close( );
Platform.shutdown();
System.out.println("Finished");

}


private void init(){


DesignConfig config = new DesignConfig( );

config.setBIRTHome("C:/birt/birt-runtime-2_6_1/birt-runtime-2_6_1/ReportEngine");
IDesignEngine engine = null;

try {

Platform.startup(config);

IDesignEngineFactory factory = (IDesignEngineFactory) Platform


..createFactoryObject(IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY);

engine = factory.createDesignEngine(config);

} catch (Exception ex) {

ex.printStackTrace();

}


// we need a handle of session of design engine

sessionHandle = engine.newSessionHandle(ULocale.ENGLISH);
reportDesignHandle = sessionHandle.createDesign();
elementFactory = reportDesignHandle.getElementFactory();

}


private void createMasterPages() throws ContentException, NameException

{

SimpleMasterPageHandle simpleMasterPage =
elementFactory.newSimpleMasterPage("Master Page");

reportDesignHandle.getMasterPages().add(simpleMasterPage);

}

void buildDataSource( ) throws SemanticException
{

OdaDataSourceHandle dsHandle = elementFactory.newOdaDataSource(
"Data Source", "org.eclipse.birt.report.data.oda.jdbc" );
dsHandle.setProperty( "odaDriverClass",
"org.eclipse.birt.report.data.oda.sampledb.Driver" );
dsHandle.setProperty( "odaURL", "jdbc:classicmodels:sampledb" );
dsHandle.setProperty( "odaUser", "ClassicModels" );
dsHandle.setProperty( "odaPassword", "" );

PropertyBinding pb = new PropertyBinding();

reportDesignHandle.getDataSources( ).add( dsHandle );

}

void buildDataSet( ) throws SemanticException
{

OdaDataSetHandle dsHandle = elementFactory.newOdaDataSet( dataSetName,
"org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
dsHandle.setDataSource( "Data Source" );
String qry = "Select PRODUCTCODE, QUANTITYORDERED from orderdetails
where ordernumber = 10104";

dsHandle.setQueryText( qry );
reportDesignHandle.getDataSets( ).add( dsHandle );

PropertyHandle handle = dsHandle.getPropertyHandle(
DataSetHandle.RESULT_SET_PROP );

}

private void createBody() throws SemanticException

{
ExtendedItemHandle extendedItemHandle =
elementFactory.newExtendedItem("Simple Chart", "Chart");
extendedItemHandle.setWidth("700px");
extendedItemHandle.setHeight("500px");

extendedItemHandle.setProperty(ExtendedItemHandle.DATA_SET_PROP,
dataSetName);
extendedItemHandle.setProperty("outputFormat","PNG");



Chart c = createChart();

extendedItemHandle.getReportItem().setProperty(
"chart.instance", c );

reportDesignHandle.getBody().add(extendedItemHandle);


//PropertyHandle computedSet = extendedItemHandle.getColumnBindings( );
//computedSet.clearValue();

cs1 = StructureFactory.createComputedColumn( );
cs1.setName( "PRODUCTCODE" );
cs1.setExpression( "dataSetRow[\"PRODUCTCODE\"]");
cs1.setDataType( "string" );
cs1.setAggregateOn(null);


cs2 = StructureFactory.createComputedColumn( );
cs2.setName( "QUANTITYORDERED" );
cs2.setExpression( "dataSetRow[\"QUANTITYORDERED\"]");
cs2.setDataType( "integer" );

extendedItemHandle.addColumnBinding(cs1, true);
extendedItemHandle.addColumnBinding(cs2, true);


}

private Chart createChart() {

ChartWithAxes cwaLine = ChartWithAxesImpl.create();
cwaLine.setType( "Line Chart" ); //$NON-NLS-1$
cwaLine.setSubType( "Overlay" ); //$NON-NLS-1$
cwaLine.getBlock().getBounds().setWidth(600);
cwaLine.getBlock().getBounds().setHeight(400);


// Plot
cwaLine.getBlock().setBackground( ColorDefinitionImpl.WHITE() );
Plot p = cwaLine.getPlot();
p.getClientArea().setBackground( ColorDefinitionImpl.create(
255, 255,
225 ) );

// Title
cwaLine.getTitle().getLabel().getCaption().setValue("Overlay
test Line Chart" );
cwaLine.getTitle().setVisible(true);

// Legend
cwaLine.getLegend().setVisible( true );
Legend lg = cwaLine.getLegend();
lg.setItemType(LegendItemType.CATEGORIES_LITERAL);

// X-Axis
Axis xAxisPrimary = cwaLine.getPrimaryBaseAxes()[0];
xAxisPrimary.setType( AxisType.TEXT_LITERAL );
xAxisPrimary.getMajorGrid().setTickStyle(
TickStyle.BELOW_LITERAL );
xAxisPrimary.getOrigin().setType( IntersectionType.MIN_LITERAL );

// Y-Axis
Axis yAxisPrimary = cwaLine.getPrimaryOrthogonalAxis(
xAxisPrimary );
yAxisPrimary.setType(AxisType.LINEAR_LITERAL);
yAxisPrimary.getMajorGrid().setTickStyle(
TickStyle.RIGHT_LITERAL );
yAxisPrimary.getLabel().getCaption().setValue("TEST");
yAxisPrimary.getLabel().setVisible(true);

SampleData sd = DataFactory.eINSTANCE.createSampleData( );
BaseSampleData sdBase = DataFactory.eINSTANCE.createBaseSampleData( );
sdBase.setDataSetRepresentation( "Category-A, Category-B" );//$NON-NLS-1$
sd.getBaseSampleData( ).add( sdBase );


OrthogonalSampleData sdOrthogonal =
DataFactory.eINSTANCE.createOrthogonalSampleData( );
sdOrthogonal.setDataSetRepresentation( "4,12" );//$NON-NLS-1$
sdOrthogonal.setSeriesDefinitionIndex( 0 );
sd.getOrthogonalSampleData( ).add( sdOrthogonal );

cwaLine.setSampleData( sd );

// X-Series



Series seCategory = SeriesImpl.create( );
// seCategory.setDataSet( categoryValues );

// Set category expression.
seCategory.getDataDefinition( )
.add( QueryImpl.create( "row[\"PRODUCTCODE\"]" ) );

SeriesDefinition sdX = SeriesDefinitionImpl.create( );
Palette palx = PaletteImpl.create(10, false);
//sdY.getSeriesPalette( ).shift(1);
sdX.setSeriesPalette(palx);


//sdX.getSeriesPalette( ).shift( 1 );
//sdX.setSorting(SortOption.ASCENDING_LITERAL);
// Set default grouping.
//SeriesGrouping grouping = sdX.getGrouping( );
//grouping.getAggregateExpression();
//grouping.setEnabled( false );
//grouping.setGroupType( DataType.TEXT_LITERAL );
//grouping.setGroupingUnit( GroupingUnitType.STRING_PREFIX_LITERAL );
//grouping.setGroupingInterval( 1 );
//grouping.setAggregateExpression( "Sum" ); // Set Count aggregation.
//$NON-NLS-1$

xAxisPrimary.getSeriesDefinitions( ).add( sdX );
sdX.getSeries( ).add( seCategory );
// Y-Series
LineSeries bs1 = (LineSeries) LineSeriesImpl.create( );

bs1.getDataDefinition( ).add( QueryImpl.create(
"row[\"QUANTITYORDERED\"]" ) );
bs1.getLabel( ).setVisible( true );


SeriesDefinition sdY = SeriesDefinitionImpl.create( );
//Palette pal = PaletteImpl.create(10, false);
//sdY.getSeriesPalette( ).shift(1);
//sdY.setSeriesPalette(pal);

sdY.getGrouping().setEnabled(false);
yAxisPrimary.getSeriesDefinitions( ).add( sdY );

sdY.getSeries( ).add( bs1 );


return cwaLine;
}
}

Jason

On 5/18/2011 1:21 PM, Olly wrote:
> public void runReport() throws EngineException
> {
>
> IReportEngine engine=null;
> EngineConfig config = null;
>
> try{
>
>
> //Configure the Engine and start the Platform
> config = new EngineConfig( );
> config.setEngineHome( BIRT_LOCATION );
> config.setLogConfig(null, Level.FINE);
>
> Platform.startup( config );
> IReportEngineFactory factory = (IReportEngineFactory) Platform
> .createFactoryObject(
> IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
> engine = factory.createReportEngine( config );
> engine.changeLogLevel( Level.WARNING );
>
> }catch( Exception ex){
> ex.printStackTrace();
> }
>
> IReportRunnable theRunnableDesign = null;
>
> try
> {
> //Open the report design
> theRunnableDesign = engine.openReportDesign(DESIGN_FILE);
> }
> catch(EngineException ex)
> {
> ex.printStackTrace();
> }
>
>
> ReportDesignHandle theReportDesignHandle =
> (ReportDesignHandle) theRunnableDesign.getDesignHandle( );
> buildReport( theReportDesignHandle );
> //Create task to run and render the report,
> IRunAndRenderTask task =
> engine.createRunAndRenderTask(theRunnableDesign);
> task.getAppContext().put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY,
> ExecuteModifiedReport.class.getClassLoader());
>
> IRenderOption theIRenderOption = new RenderOption();
> theIRenderOption.setOutputFormat(OUTPUT_FORMAT);
> theIRenderOption.setOutputFileName(GENERATED_REPORT);
>
> // set the html render option
> HTMLRenderOption theHTMLOptions = new
> HTMLRenderOption(theIRenderOption);
>
> theHTMLOptions.setImageDirectory(IMAGE_DIRECTORY);
> theHTMLOptions.setHtmlPagination(false);
> theHTMLOptions.setEmbeddable(true);
> theHTMLOptions.setBaseURL(IMAGE_DIRECTORY);
>
> task.setRenderOption(theHTMLOptions);
>
> //run the report and destroy the engine
> //Note - If the program stays resident do not shutdown the
> Platform or the Engine
> task.run();
> task.close();
> engine.shutdown();
> Platform.shutdown();
> System.out.println("Finished generating report"); }
>
> public void buildReport(ReportDesignHandle theReportDesignHandle){
>
>
> try{
> ElementFactory designFactory =
> theReportDesignHandle.getElementFactory( );
>
> buildDataSource(designFactory, theReportDesignHandle);
>
> // Get the label that represents the title label
> LabelHandle theTitleLabelHandle =
> (LabelHandle) theReportDesignHandle.getElementByID(59);
>
> /*(LabelHandle)theReportDesignHandle.findElement("theReportTitle");*/
>
> if(theTitleLabelHandle != null)
> {
> // set the label's title to report title
> theTitleLabelHandle.setText("My New Report");
> }
>
> ArrayList cols = new ArrayList();
> cols.add("OFFICECODE");
> cols.add("CITY");
> cols.add("COUNTRY");
>
> buildDataSet(cols, "From Offices", designFactory,
> theReportDesignHandle);
>
> TableHandle table = designFactory.newTableItem( "table",
> cols.size() );
> table.setWidth( "100%" );
> table.setDataSet( theReportDesignHandle.findDataSet( "ds" ) );
>
>
> PropertyHandle computedSet = table.getColumnBindings( );
> ComputedColumn cs1 = null;
>
> for( int i=0; i < cols.size(); i++){
> cs1 = StructureFactory.createComputedColumn();
> cs1.setName((String)cols.get(i));
> cs1.setExpression("dataSetRow[\"" + (String)cols.get(i) + "\"]");
> computedSet.addItem(cs1);
> }
>
>
> // table header
> RowHandle tableheader = (RowHandle) table.getHeader( ).get( 0 );
>
>
> for( int i=0; i < cols.size(); i++){
> LabelHandle label1 = designFactory.newLabel(
> (String)cols.get(i) );
> label1.setText((String)cols.get(i));
> CellHandle cell = (CellHandle) tableheader.getCells( ).get(
> i );
> cell.getContent( ).add( label1 );
> }
>
> // table detail
> RowHandle tabledetail = (RowHandle) table.getDetail( ).get( 0 );
> for( int i=0; i < cols.size(); i++){
> CellHandle cell = (CellHandle) tabledetail.getCells( ).get(
> i );
> DataItemHandle data = designFactory.newDataItem(
> "data_"+(String)cols.get(i) );
> data.setResultSetColumn( (String)cols.get(i));
> cell.getContent( ).add( data );
> }
>
>
>
> theReportDesignHandle.getBody( ).add( table );
> }catch(Exception e){
> e.printStackTrace();
> }
>
> }
>
> void buildDataSource( ElementFactory designFactory,
> ReportDesignHandle designHandle ) throws SemanticException
> {
>
> OdaDataSourceHandle dsHandle = designFactory.newOdaDataSource(
> "Data Source", "org.eclipse.birt.report.data.oda.jdbc" );
> dsHandle.setProperty( "odaDriverClass",
> "org.eclipse.birt.report.data.oda.sampledb.Driver" );
> dsHandle.setProperty( "odaURL", "jdbc:classicmodels:sampledb" );
> dsHandle.setProperty( "odaUser", "ClassicModels" );
> dsHandle.setProperty( "odaPassword", "" );
>
> designHandle.getDataSources( ).add( dsHandle );
>
> }
>
> void buildDataSet(ArrayList cols, String fromClause, ElementFactory
> designFactory, ReportDesignHandle designHandle ) throws SemanticException
> {
>
> OdaDataSetHandle dsHandle = designFactory.newOdaDataSet( "ds",
> "org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
> dsHandle.setDataSource( "Data Source" );
> String qry = "Select ";
> for( int i=0; i < cols.size(); i++){
> qry += " " + cols.get(i);
> if( i != (cols.size() -1) ){
> qry += ",";
> }
>
> }
> qry += " " + fromClause;
>
> dsHandle.setQueryText( qry );
>
> designHandle.getDataSets( ).add( dsHandle );
>
>
> }
>
> /**
> * @param args
> */
> public static void main(String[] args) {
> try
> {
>
> ExecuteModifiedReport ex = new ExecuteModifiedReport( );
> ex.runReport();
>
> }
> catch ( Exception e )
> {
> e.printStackTrace();
> }
> }
Previous Topic:Does reportContext.getOutputFormat just work with runAndRenderTask?
Next Topic:"Can't load the report query" at report beforeRender event??
Goto Forum:
  


Current Time: Sun Nov 23 03:55:02 GMT 2014

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

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