I need Aggregation on group using API
hello all
im now using BIRT API to create report which have more than one group
im try to add the count of each group in the footer of the group which i cannot do
so please help me
and here is the code
{code}
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.ColumnHandle;
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.StyleHandle;
import org.eclipse.birt.report.model.api.TableGroupHandle;
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 org.eclipse.birt.report.model.core.Structure;
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<String> al = new ArrayList<String>();
al.add("DELETED");
al.add("BALLOON");
al.add("ACTIVE");
al.add("DBID");
al.add("NAME");
ArrayList<String> gr = new ArrayList<String>();
gr.add("DELETED");
gr.add("BALLOON");
gr.add("ACTIVE");
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( "innerDs","org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
dsHandle.setDataSource( "Data Source" );
String qry = "Select deleted,BALLOON,ACTIVE,DBID,NAME from dd ";
dsHandle.setQueryText( qry );
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);
//**********************************************************************************
TableHandle table = designFactory.newTableItem( "table", cols.size() );
table.setWidth( "100%" );
table.setDataSet( designHandle.findDataSet( "innerDs" ) );
/////////////////////////////////////////////////////////////////
TableGroupHandle group=null;
group =designFactory.newTableGroup( );
group.setKeyExpr( "row[\"DELETED\"]" );//$NON-NLS-1$
table.getGroups( ).add( group );
TableGroupHandle group1=null;
group1 =designFactory.newTableGroup( );
group1.setKeyExpr( "row[\"BALLOON\"]" );//$NON-NLS-1$
table.getGroups( ).add( group1 );
PropertyHandle computedSet = table.getColumnBindings( );
ComputedColumn cs1 = null;
for( int j=0; j < cols.size(); j++){
cs1 = StructureFactory.createComputedColumn();
cs1.setName((String)cols.get(j));
cs1.setExpression("dataSetRow[\"" + (String)cols.get(j) + "\"]");
computedSet.addItem(cs1);
if (j==0)
{
RowHandle groupHeader = designFactory.newTableRow( 5 );
CellHandle tcell = (CellHandle) groupHeader.getCells( ).get( 0 );
tcell.setDrop( DesignChoiceConstants.DROP_TYPE_DETAIL );
DataItemHandle data = designFactory.newDataItem( null );
//data.setStyleName( "Data" );//$NON-NLS-1$
data.setResultSetColumn( cs1.getName( ) );
tcell.getContent( ).add( data );
group.getHeader( ).add( groupHeader );
RowHandle groupFooter = designFactory.newTableRow( 5 );
tcell = (CellHandle) groupFooter.getCells( ).get( 0 );
tcell.setProperty( StyleHandle.BORDER_BOTTOM_COLOR_PROP, "#FF8000" );//$NON-NLS-1$
tcell.setProperty( StyleHandle.BORDER_BOTTOM_STYLE_PROP,
DesignChoiceConstants.LINE_STYLE_SOLID );
tcell.setProperty( StyleHandle.BORDER_BOTTOM_WIDTH_PROP,
DesignChoiceConstants.LINE_WIDTH_THIN );
group.getFooter( ).add( groupFooter );
}
if (j==1)
{
RowHandle groupHeader = designFactory.newTableRow( 5 );
CellHandle tcell = (CellHandle) groupHeader.getCells( ).get( 1 );
tcell.setDrop( DesignChoiceConstants.DROP_TYPE_DETAIL );
DataItemHandle data = designFactory.newDataItem( null );
//data.setStyleName( "Data" );//$NON-NLS-1$
data.setResultSetColumn( cs1.getName( ) );
tcell.getContent( ).add( data );
group1.getHeader( ).add( groupHeader );
RowHandle groupFooter = designFactory.newTableRow( 5 );
tcell = (CellHandle) groupFooter.getCells( ).get( 1 );
tcell.setProperty( StyleHandle.BORDER_BOTTOM_COLOR_PROP, "#FF8000" );//$NON-NLS-1$
tcell.setProperty( StyleHandle.BORDER_BOTTOM_STYLE_PROP,
DesignChoiceConstants.LINE_STYLE_SOLID );
tcell.setProperty( StyleHandle.BORDER_BOTTOM_WIDTH_PROP,
DesignChoiceConstants.LINE_WIDTH_THIN );
tcell = (CellHandle) groupFooter.getCells( ).get( 1 );
tcell.setProperty( StyleHandle.BORDER_BOTTOM_COLOR_PROP, "#FF8000" );//$NON-NLS-1$
tcell.setProperty( StyleHandle.BORDER_BOTTOM_STYLE_PROP,
DesignChoiceConstants.LINE_STYLE_SOLID );
tcell.setProperty( StyleHandle.BORDER_BOTTOM_WIDTH_PROP,
DesignChoiceConstants.LINE_WIDTH_THIN );
tcell = (CellHandle) groupFooter.getCells( ).get( 2 );
tcell.setProperty( StyleHandle.BORDER_BOTTOM_COLOR_PROP, "#FF8000" );//$NON-NLS-1$
tcell.setProperty( StyleHandle.BORDER_BOTTOM_STYLE_PROP,
DesignChoiceConstants.LINE_STYLE_SOLID );
tcell.setProperty( StyleHandle.BORDER_BOTTOM_WIDTH_PROP,
DesignChoiceConstants.LINE_WIDTH_THIN );
group1.getFooter( ).add( groupFooter );
}
}
// table header
RowHandle tableheader = (RowHandle) table.getHeader( ).get( 0 );
for( int j=0; 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=0; 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 );
}
designHandle.getBody( ).add( table);
// 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();
}
}
}
{code}