Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Table inside Table
melad_ezza
hi all
im new to birt and im trying to create table inside another table using java code only (not the designer)
and the inner table should take parameter from outer table to retrieve data from the database
can anyone help me
thanks
Find more posts tagged with
Comments
mwilliams
Where are you stuck at? Can you show me the code you have so far? Or are you just starting?
melad_ezza
Thanx for your care
now i can generate one table inside another
but the business requirements escalated so that now i need to perform this operation over and over
for example
if the user select 3 group by criteria i he should have three nested tables
and each of them take parameter from immediate outer table
my code which perform two inner tables
import java.io.IOException;
import java.util.ArrayList;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.model.api.CellHandle;
import org.eclipse.birt.report.model.api.DataItemHandle;
import org.eclipse.birt.report.model.api.DesignConfig;
import org.eclipse.birt.report.model.api.ElementFactory;
import org.eclipse.birt.report.model.api.IDesignEngine;
import org.eclipse.birt.report.model.api.IDesignEngineFactory;
import org.eclipse.birt.report.model.api.LabelHandle;
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.RowHandle;
import org.eclipse.birt.report.model.api.SessionHandle;
import org.eclipse.birt.report.model.api.StructureFactory;
import org.eclipse.birt.report.model.api.TableHandle;
import org.eclipse.birt.report.model.api.activity.SemanticException;
import org.eclipse.birt.report.model.api.elements.DesignChoiceConstants;
import org.eclipse.birt.report.model.api.elements.structures.ComputedColumn;
import org.eclipse.birt.report.model.api.elements.structures.OdaDataSetParameter;
import org.eclipse.birt.report.model.api.elements.structures.ParamBinding;
import com.ibm.icu.util.ULocale;
/**
* Simple BIRT Design Engine API (DEAPI) demo.
*/
public class stock2
{
ReportDesignHandle designHandle = null;
ElementFactory designFactory = null;
StructureFactory structFactory = null;
public static void main( String[] args )
{
try
{
stock2 de = new stock2();
ArrayList al = new ArrayList();
al.add("DELETED");
al.add("ACTIVE");
al.add("DBID");
al.add("NAME");
de.buildReport(al, "From dd" );
}
catch ( IOException e )
{
e.printStackTrace();
}
catch ( SemanticException e )
{
e.printStackTrace();
}
}
void buildDataSource( ) throws SemanticException
{
OdaDataSourceHandle dsHandle = designFactory.newOdaDataSource("Data Source", "org.eclipse.birt.report.data.oda.jdbc" );
dsHandle.setProperty( "odaDriverClass","com.mysql.jdbc.Driver" );
dsHandle.setProperty( "odaURL", "jdbc:mysql://1.1.1.189:3306/otmsall2" );
dsHandle.setProperty( "odaUser", "root" );
dsHandle.setProperty( "odaPassword", "root" );
designHandle.getDataSources( ).add( dsHandle );
}
void buildDataSet(ArrayList cols, String fromClause ) throws SemanticException
{
OdaDataSetHandle dsHandle = designFactory.newOdaDataSet( "ds","org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
dsHandle.setDataSource( "Data Source" );
String qry = "Select deleted from dd group by deleted";
dsHandle.setQueryText( qry );
designHandle.getDataSets( ).add( dsHandle );
}
void buildinnerDataSet(ArrayList cols, String fromClause) throws SemanticException
{
OdaDataSetHandle dsHandle = designFactory.newOdaDataSet( "innerDs","org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
dsHandle.setDataSource( "Data Source" );
String qry = "Select ACTIVE,DBID,NAME from dd where deleted=?";
dsHandle.setQueryText( qry );
OdaDataSetParameter odaDataSetParameter=StructureFactory.createOdaDataSetParameter();
odaDataSetParameter.setName("param_SSS");
odaDataSetParameter.setDataType(DesignChoiceConstants.PARAM_TYPE_STRING);
odaDataSetParameter.setNativeDataType(1);
odaDataSetParameter.setPosition(1);
odaDataSetParameter.setIsOptional(false);
odaDataSetParameter.setAllowNull(true);
odaDataSetParameter.setIsInput(true);
odaDataSetParameter.setIsOutput(false);
odaDataSetParameter.setDefaultValue("1");
PropertyHandle odaDataSetParameterProp = dsHandle.getPropertyHandle(OdaDataSetHandle.PARAMETERS_PROP);
odaDataSetParameterProp.insertItem(odaDataSetParameter, 0);
designHandle.getDataSets( ).add( dsHandle );
}
void buildReport(ArrayList cols, String fromClause ) throws IOException, SemanticException
{
DesignConfig config = new DesignConfig( );
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();
}
SessionHandle session = engine.newSessionHandle( ULocale.ENGLISH ) ;
designHandle = session.createDesign();
designFactory = designHandle.getElementFactory( );
try{
//open a design or a template
designHandle = session.createDesign();
designFactory = designHandle.getElementFactory( );
buildDataSource();
buildDataSet(cols, fromClause);
buildinnerDataSet(cols, fromClause);
//**********************************************************************************
TableHandle table = designFactory.newTableItem( "table", cols.size() );
table.setWidth( "100%" );
table.setDataSet( designHandle.findDataSet( "innerDs" ) );
//ActionHandle actionHandle
ParamBinding pb= StructureFactory.createParamBinding();
pb.setParamName("param_SSS");
pb.setExpression("row[\"DELETED\"]");
table.getPropertyHandle( TableHandle.PARAM_BINDINGS_PROP ).addItem( pb );
PropertyHandle computedSet = table.getColumnBindings( );
ComputedColumn cs1 = null;
for( int j=1; j < cols.size(); j++){
cs1 = StructureFactory.createComputedColumn();
cs1.setName((String)cols.get(j));
cs1.setExpression("dataSetRow[\"" + (String)cols.get(j) + "\"]");
computedSet.addItem(cs1);
}
// table header
RowHandle tableheader = (RowHandle) table.getHeader( ).get( 0 );
for( int j=1; j < cols.size(); j++){
LabelHandle label1 = designFactory.newLabel( (String)cols.get(j)+j );
label1.setText((String)cols.get(j));
CellHandle cell = (CellHandle) tableheader.getCells( ).get( j );
cell.getContent( ).add( label1 );
}
// table detail
RowHandle tabledetail = (RowHandle) table.getDetail( ).get( 0 );
for( int j=1; j < cols.size(); j++){
CellHandle cell = (CellHandle) tabledetail.getCells( ).get( j );
DataItemHandle data = designFactory.newDataItem( "data_"+(String)cols.get(j)+j );
data.setResultSetColumn( (String)cols.get(j));
cell.getContent( ).add( data );
}
//**********************************************************************************
TableHandle table1 = designFactory.newTableItem( "table1", 2 );
table1.setWidth( "100%" );
table1.setDataSet( designHandle.findDataSet( "ds" ) );
PropertyHandle computedSet1 = table1.getColumnBindings( );
ComputedColumn cs11 = null;
for( int i=0; i < 1; i++){
cs11 = StructureFactory.createComputedColumn();
cs11.setName((String)cols.get(i));
cs11.setExpression("dataSetRow[\"" + (String)cols.get(i) + "\"]");
computedSet1.addItem(cs11);
}
// table header
RowHandle tableheader1 = (RowHandle) table1.getHeader( ).get( 0 );
for( int i=0; i < 1; i++){
LabelHandle label11 = designFactory.newLabel( (String)cols.get(i) );
label11.setText((String)cols.get(i));
CellHandle cell1 = (CellHandle) tableheader1.getCells( ).get( i );
cell1.getContent( ).add( label11 );
}
// table detail
RowHandle tabledetail1 = (RowHandle) table1.getDetail( ).get( 0 );
for( int i=0; i < 2; i++){
CellHandle cell1 = (CellHandle) tabledetail1.getCells( ).get( i );
DataItemHandle data1= designFactory.newDataItem( "data_"+(String)cols.get(i) );
data1.setResultSetColumn( (String)cols.get(i));
if (i==1)
{
cell1.getContent( ).add( table );
}
else
{
cell1.getContent( ).add( data1 );
}
}
designHandle.getBody( ).add( table1 );
// Save the design and close it.
designHandle.saveAs( "c:/dynamic.rptdesign" ); //$NON-NLS-1$
designHandle.close( );
Platform.shutdown();
System.out.println("Finished");
}catch (Exception e){
e.printStackTrace();
}
}
}
mwilliams
Sorry for the delay. So, this is currently working code? Or are you getting errors from it? What are your current errors if getting errors?