A Scripting DataSource and Fetch() [message #47658] |
Fri, 17 June 2005 16:55 |
Eclipse User |
|
|
|
Originally posted by: user.domain.invalid
Hi,
Im trying to create scripting DataSet and it almost works. the number of
rows is OK. the locations in the grid is ok but not the contents. It
seems as if the Fetch() script onlu set the values or row once. i.e the
first row and its values are displayed on all rows.
Isnt Fetch supposed to be called at every row and 'row' variable is set
to current row in 'rows[]' variabl?
Any advice appreciated.
//------------------------------------
/****/
public void generateTest(String filename) {
SessionHandle session = DesignEngine.newSession( null );
ReportDesignHandle design = session.createDesign( );
try {
ElementFactory factory = design.getElementFactory( );
DesignElementHandle element = factory.newSimpleMasterPage(
"Page Master" ); //$NON-NLS-1$
design.getMasterPages( ).add( element );
ScriptDataSourceHandle lDS = factory.newScriptDataSource("ds");
SlotHandle lDSH = design.getDataSources();
int liS1 = lDSH.getCount();
lDSH.add(lDS);
lDSH = design.getDataSources();
int liS2 = lDSH.getCount();
ScriptDataSetHandle lDSet = factory.newScriptDataSet(null);
lDSet.setDataSource("ds");
SlotHandle lDSetH = design.getDataSets();
lDSetH.add(lDSet);
ListHandle lMain = factory.newList( null );
design.getBody( ).add( lMain );
lDSet.setOpen("count = 0;\n"
+" len = params[\"MYROWS\"].length; \n"
+" lRows = params[\"MYROWS\"];\n"
// +" lRowss = new Array('Q','L','M','N','O','P');\n"
// +" for(i = 0; i < len;i++) {lRowss[i] = lRows[i];}\n"
+"");
lDSet.setFetch(""
+"if ( count < len )"
+"{\n"
+" row.a = lRows[count].getA();\n"
+" row[\"b\"] = lRows[count].getB();\n"
+" row[\"c\"] = count;\n"
+" count = count+1;\n"
+" return true;\n"
+"}\n "
+"return false;\n");
String lsF = lDSet.getFetch();
String lsO = lDSet.getOpen();
PropertyHandle lPH =
lDSet.getPropertyHandle(DataSetHandle.RESULT_SET_PROP);
lPH.setStringValue(null);
ResultSetColumn lColA =
StructureFactory.createResultSetColumn();
lColA.setColumnName("a");
lColA.setDataType("Any");
lColA.setPosition(new Integer(0));
lPH.addItem(lColA);
ResultSetColumn lColB =
StructureFactory.createResultSetColumn();
lColB.setColumnName("b");
lColB.setDataType("Any");
lColB.setPosition(new Integer(1));
lPH.addItem(lColB);
ResultSetColumn lColC =
StructureFactory.createResultSetColumn();
lColC.setColumnName("c");
lColC.setDataType("Any");
lColC.setPosition(new Integer(2));
lPH.addItem(lColC);
Iterator it = lDSet.resultSetIterator();
Object lO = null;
while( it.hasNext()) {
lO = it.next();
ResultSetColumnHandle lRS = (ResultSetColumnHandle )lO;
}
lMain.setDataSet(lDSet);
String lsOnRow = lMain.getOnRow();
LabelHandle lHeader = factory.newLabel( null );
lMain.getHeader().add(lHeader);
lHeader.setText( "Header...." ); //$NON-NLS-1$
GridHandle grid = factory.newGridItem( null, 2 /* cols */,
2 /* row */ );
lMain.getDetail( ).add( grid );
grid.setWidth( "100%" ); //$NON-NLS-1$
RowHandle row0 = (RowHandle) grid.getRows( ).get( 0 );
LabelHandle label = factory.newLabel( null );
label.setText( "Hello, Anders!" ); //$NON-NLS-1$
CellHandle cell = (CellHandle) row0.getCells( ).get( 0 );
cell.getContent( ).add( label );
DataItemHandle lDHLA = factory.newDataItem("a");
lDHLA.setDataSet(lDSet);
lDHLA.setValueExpr("row[\"a\"]");
cell = (CellHandle) row0.getCells( ).get( 1 );
cell.getContent( ).add( lDHLA );
RowHandle row1 = (RowHandle) grid.getRows( ).get( 1 );
DataItemHandle lDHLB = factory.newDataItem("b");
lDHLB.setDataSet(lDSet);
lDHLB.setValueExpr("row[\"b\"]");
cell = (CellHandle) row1.getCells( ).get( 0 );
cell.getContent( ).add( lDHLB );
DataItemHandle lDHLC = factory.newDataItem("c");
lDHLC.setDataSet(lDSet);
lDHLC.setValueExpr("row[\"c\"]");
cell = (CellHandle) row1.getCells( ).get( 1 );
cell.getContent( ).add( lDHLC );
LabelHandle lFooter = factory.newLabel( null );
lMain.getFooter().add(lFooter);
lFooter.setText( "Footer ...." ); //$NON-NLS-1$
File lFile = new File(filename);
FileOutputStream lOUT = new FileOutputStream(lFile);
design.serialize(lOUT);
lOUT.flush();
lOUT.close();
ByteArrayOutputStream lBOUT = new ByteArrayOutputStream();
design.serialize(lBOUT);
// design.saveAs( filename ); //$NON-NLS-1$
design.close( );
} catch (NameException ex) {
ex.printStackTrace();
} catch (ContentException ex) {
ex.printStackTrace();
} catch (SemanticException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}
|
|
|
Re: A Scripting DataSource and Fetch() [message #47815 is a reply to message #47658] |
Fri, 17 June 2005 22:02 |
Gary Xue Messages: 193 Registered: July 2009 |
Senior Member |
|
|
Your script data set design looks OK. You can try using BIRT report designer
to create a static report design using the same fetch script and make sure
that it works there.
I suspect your problem has to do with the way that the report is created
using the design engine API. Try saving your dynamic report design to a
file, and compare the content to a similar design created by BIRT report
designer.
Gary Xue
<user@domain.invalid> wrote in message news:d8uvb3$991$1@news.eclipse.org...
> Hi,
>
> Im trying to create scripting DataSet and it almost works. the number of
> rows is OK. the locations in the grid is ok but not the contents. It
> seems as if the Fetch() script onlu set the values or row once. i.e the
> first row and its values are displayed on all rows.
>
> Isnt Fetch supposed to be called at every row and 'row' variable is set
> to current row in 'rows[]' variabl?
>
> Any advice appreciated.
>
>
>
> //------------------------------------
> /****/
> public void generateTest(String filename) {
> SessionHandle session = DesignEngine.newSession( null );
> ReportDesignHandle design = session.createDesign( );
> try {
> ElementFactory factory = design.getElementFactory( );
> DesignElementHandle element = factory.newSimpleMasterPage(
> "Page Master" ); //$NON-NLS-1$
> design.getMasterPages( ).add( element );
>
> ScriptDataSourceHandle lDS =
factory.newScriptDataSource("ds");
> SlotHandle lDSH = design.getDataSources();
> int liS1 = lDSH.getCount();
> lDSH.add(lDS);
> lDSH = design.getDataSources();
> int liS2 = lDSH.getCount();
>
> ScriptDataSetHandle lDSet = factory.newScriptDataSet(null);
> lDSet.setDataSource("ds");
> SlotHandle lDSetH = design.getDataSets();
> lDSetH.add(lDSet);
>
> ListHandle lMain = factory.newList( null );
> design.getBody( ).add( lMain );
>
> lDSet.setOpen("count = 0;\n"
> +" len = params[\"MYROWS\"].length; \n"
> +" lRows = params[\"MYROWS\"];\n"
> // +" lRowss = new Array('Q','L','M','N','O','P');\n"
> // +" for(i = 0; i < len;i++) {lRowss[i] =
lRows[i];}\n"
> +"");
>
> lDSet.setFetch(""
> +"if ( count < len )"
> +"{\n"
> +" row.a = lRows[count].getA();\n"
> +" row[\"b\"] = lRows[count].getB();\n"
> +" row[\"c\"] = count;\n"
> +" count = count+1;\n"
> +" return true;\n"
> +"}\n "
> +"return false;\n");
>
> String lsF = lDSet.getFetch();
> String lsO = lDSet.getOpen();
> PropertyHandle lPH =
> lDSet.getPropertyHandle(DataSetHandle.RESULT_SET_PROP);
> lPH.setStringValue(null);
> ResultSetColumn lColA =
> StructureFactory.createResultSetColumn();
> lColA.setColumnName("a");
> lColA.setDataType("Any");
> lColA.setPosition(new Integer(0));
> lPH.addItem(lColA);
>
> ResultSetColumn lColB =
> StructureFactory.createResultSetColumn();
> lColB.setColumnName("b");
> lColB.setDataType("Any");
> lColB.setPosition(new Integer(1));
> lPH.addItem(lColB);
>
> ResultSetColumn lColC =
> StructureFactory.createResultSetColumn();
> lColC.setColumnName("c");
> lColC.setDataType("Any");
> lColC.setPosition(new Integer(2));
> lPH.addItem(lColC);
>
> Iterator it = lDSet.resultSetIterator();
> Object lO = null;
> while( it.hasNext()) {
> lO = it.next();
> ResultSetColumnHandle lRS = (ResultSetColumnHandle )lO;
> }
>
> lMain.setDataSet(lDSet);
> String lsOnRow = lMain.getOnRow();
>
> LabelHandle lHeader = factory.newLabel( null );
> lMain.getHeader().add(lHeader);
> lHeader.setText( "Header...." ); //$NON-NLS-1$
>
> GridHandle grid = factory.newGridItem( null, 2 /* cols */,
> 2 /* row */ );
> lMain.getDetail( ).add( grid );
> grid.setWidth( "100%" ); //$NON-NLS-1$
>
> RowHandle row0 = (RowHandle) grid.getRows( ).get( 0 );
> LabelHandle label = factory.newLabel( null );
> label.setText( "Hello, Anders!" ); //$NON-NLS-1$
> CellHandle cell = (CellHandle) row0.getCells( ).get( 0 );
> cell.getContent( ).add( label );
>
> DataItemHandle lDHLA = factory.newDataItem("a");
> lDHLA.setDataSet(lDSet);
> lDHLA.setValueExpr("row[\"a\"]");
> cell = (CellHandle) row0.getCells( ).get( 1 );
> cell.getContent( ).add( lDHLA );
>
> RowHandle row1 = (RowHandle) grid.getRows( ).get( 1 );
> DataItemHandle lDHLB = factory.newDataItem("b");
> lDHLB.setDataSet(lDSet);
> lDHLB.setValueExpr("row[\"b\"]");
> cell = (CellHandle) row1.getCells( ).get( 0 );
> cell.getContent( ).add( lDHLB );
>
> DataItemHandle lDHLC = factory.newDataItem("c");
> lDHLC.setDataSet(lDSet);
> lDHLC.setValueExpr("row[\"c\"]");
> cell = (CellHandle) row1.getCells( ).get( 1 );
> cell.getContent( ).add( lDHLC );
>
>
> LabelHandle lFooter = factory.newLabel( null );
> lMain.getFooter().add(lFooter);
> lFooter.setText( "Footer ...." ); //$NON-NLS-1$
>
>
>
> File lFile = new File(filename);
> FileOutputStream lOUT = new FileOutputStream(lFile);
> design.serialize(lOUT);
> lOUT.flush();
> lOUT.close();
> ByteArrayOutputStream lBOUT = new ByteArrayOutputStream();
> design.serialize(lBOUT);
>
> // design.saveAs( filename ); //$NON-NLS-1$
> design.close( );
> } catch (NameException ex) {
> ex.printStackTrace();
> } catch (ContentException ex) {
> ex.printStackTrace();
> } catch (SemanticException ex) {
> ex.printStackTrace();
> } catch (IOException ex) {
> ex.printStackTrace();
> }
> }
|
|
|
Re: A Scripting DataSource and Fetch() [message #48117 is a reply to message #47815] |
Mon, 20 June 2005 10:23 |
Eclipse User |
|
|
|
Originally posted by: user.domain.invalid
Hi Gary ,
I solved it by moving the DataSet binding from DataItemHandle to List
instead.
thanks
/anders
Gary Xue wrote:
> Your script data set design looks OK. You can try using BIRT report designer
> to create a static report design using the same fetch script and make sure
> that it works there.
>
> I suspect your problem has to do with the way that the report is created
> using the design engine API. Try saving your dynamic report design to a
> file, and compare the content to a similar design created by BIRT report
> designer.
>
> Gary Xue
>
> <user@domain.invalid> wrote in message news:d8uvb3$991$1@news.eclipse.org...
>
>>Hi,
>>
>>Im trying to create scripting DataSet and it almost works. the number of
>> rows is OK. the locations in the grid is ok but not the contents. It
>>seems as if the Fetch() script onlu set the values or row once. i.e the
>>first row and its values are displayed on all rows.
>>
>>Isnt Fetch supposed to be called at every row and 'row' variable is set
>>to current row in 'rows[]' variabl?
>>
>>Any advice appreciated.
>>
>>
>>
>>//------------------------------------
>> /****/
>> public void generateTest(String filename) {
>> SessionHandle session = DesignEngine.newSession( null );
>> ReportDesignHandle design = session.createDesign( );
>> try {
>> ElementFactory factory = design.getElementFactory( );
>> DesignElementHandle element = factory.newSimpleMasterPage(
>>"Page Master" ); //$NON-NLS-1$
>> design.getMasterPages( ).add( element );
>>
>> ScriptDataSourceHandle lDS =
>
> factory.newScriptDataSource("ds");
>
>> SlotHandle lDSH = design.getDataSources();
>> int liS1 = lDSH.getCount();
>> lDSH.add(lDS);
>> lDSH = design.getDataSources();
>> int liS2 = lDSH.getCount();
>>
>> ScriptDataSetHandle lDSet = factory.newScriptDataSet(null);
>> lDSet.setDataSource("ds");
>> SlotHandle lDSetH = design.getDataSets();
>> lDSetH.add(lDSet);
>>
>> ListHandle lMain = factory.newList( null );
>> design.getBody( ).add( lMain );
>>
>> lDSet.setOpen("count = 0;\n"
>> +" len = params[\"MYROWS\"].length; \n"
>> +" lRows = params[\"MYROWS\"];\n"
>>// +" lRowss = new Array('Q','L','M','N','O','P');\n"
>>// +" for(i = 0; i < len;i++) {lRowss[i] =
>
> lRows[i];}\n"
>
>> +"");
>>
>> lDSet.setFetch(""
>> +"if ( count < len )"
>> +"{\n"
>> +" row.a = lRows[count].getA();\n"
>> +" row[\"b\"] = lRows[count].getB();\n"
>> +" row[\"c\"] = count;\n"
>> +" count = count+1;\n"
>> +" return true;\n"
>> +"}\n "
>> +"return false;\n");
>>
>> String lsF = lDSet.getFetch();
>> String lsO = lDSet.getOpen();
>> PropertyHandle lPH =
>>lDSet.getPropertyHandle(DataSetHandle.RESULT_SET_PROP);
>> lPH.setStringValue(null);
>> ResultSetColumn lColA =
>>StructureFactory.createResultSetColumn();
>> lColA.setColumnName("a");
>> lColA.setDataType("Any");
>> lColA.setPosition(new Integer(0));
>> lPH.addItem(lColA);
>>
>> ResultSetColumn lColB =
>>StructureFactory.createResultSetColumn();
>> lColB.setColumnName("b");
>> lColB.setDataType("Any");
>> lColB.setPosition(new Integer(1));
>> lPH.addItem(lColB);
>>
>> ResultSetColumn lColC =
>>StructureFactory.createResultSetColumn();
>> lColC.setColumnName("c");
>> lColC.setDataType("Any");
>> lColC.setPosition(new Integer(2));
>> lPH.addItem(lColC);
>>
>> Iterator it = lDSet.resultSetIterator();
>> Object lO = null;
>> while( it.hasNext()) {
>> lO = it.next();
>> ResultSetColumnHandle lRS = (ResultSetColumnHandle )lO;
>> }
>>
>> lMain.setDataSet(lDSet);
>> String lsOnRow = lMain.getOnRow();
>>
>> LabelHandle lHeader = factory.newLabel( null );
>> lMain.getHeader().add(lHeader);
>> lHeader.setText( "Header...." ); //$NON-NLS-1$
>>
>> GridHandle grid = factory.newGridItem( null, 2 /* cols */,
>>2 /* row */ );
>> lMain.getDetail( ).add( grid );
>> grid.setWidth( "100%" ); //$NON-NLS-1$
>>
>> RowHandle row0 = (RowHandle) grid.getRows( ).get( 0 );
>> LabelHandle label = factory.newLabel( null );
>> label.setText( "Hello, Anders!" ); //$NON-NLS-1$
>> CellHandle cell = (CellHandle) row0.getCells( ).get( 0 );
>> cell.getContent( ).add( label );
>>
>> DataItemHandle lDHLA = factory.newDataItem("a");
>> lDHLA.setDataSet(lDSet);
>> lDHLA.setValueExpr("row[\"a\"]");
>> cell = (CellHandle) row0.getCells( ).get( 1 );
>> cell.getContent( ).add( lDHLA );
>>
>> RowHandle row1 = (RowHandle) grid.getRows( ).get( 1 );
>> DataItemHandle lDHLB = factory.newDataItem("b");
>> lDHLB.setDataSet(lDSet);
>> lDHLB.setValueExpr("row[\"b\"]");
>> cell = (CellHandle) row1.getCells( ).get( 0 );
>> cell.getContent( ).add( lDHLB );
>>
>> DataItemHandle lDHLC = factory.newDataItem("c");
>> lDHLC.setDataSet(lDSet);
>> lDHLC.setValueExpr("row[\"c\"]");
>> cell = (CellHandle) row1.getCells( ).get( 1 );
>> cell.getContent( ).add( lDHLC );
>>
>>
>> LabelHandle lFooter = factory.newLabel( null );
>> lMain.getFooter().add(lFooter);
>> lFooter.setText( "Footer ...." ); //$NON-NLS-1$
>>
>>
>>
>> File lFile = new File(filename);
>> FileOutputStream lOUT = new FileOutputStream(lFile);
>> design.serialize(lOUT);
>> lOUT.flush();
>> lOUT.close();
>> ByteArrayOutputStream lBOUT = new ByteArrayOutputStream();
>> design.serialize(lBOUT);
>>
>>// design.saveAs( filename ); //$NON-NLS-1$
>> design.close( );
>> } catch (NameException ex) {
>> ex.printStackTrace();
>> } catch (ContentException ex) {
>> ex.printStackTrace();
>> } catch (SemanticException ex) {
>> ex.printStackTrace();
>> } catch (IOException ex) {
>> ex.printStackTrace();
>> }
>> }
>
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.02684 seconds