Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » grid visibility using deapi
grid visibility using deapi [message #645375] Thu, 16 December 2010 19:11 Go to next message
Nils is currently offline NilsFriend
Messages: 15
Registered: August 2010
Location: Stuttgart
Junior Member
hi all Smile

I'm stuck with a problem:

I use the DEAPI to modify a rptdesign. Every now and then I need to hide a Grid based on a set of rules.

I have absolutely no idea how to do this using the api (Birt 2.6.1)

I tried grid.setProperty("visibility", someHideRule) but that keeps telling me, that someHideRule is invalid with the type "structure".

What am I doing wrong?

Any help appreciated Smile
cheers,
nils
Re: grid visibility using deapi [message #645388 is a reply to message #645375] Thu, 16 December 2010 23:10 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Attached is an example that does it on a table.

Jason

<?xml version="1.0" encoding="UTF-8"?>
<report xmlns="http://www.eclipse.org/birt/2005/design" version="3.2.21"
id="1">
<property name="createdBy">Eclipse BIRT Designer Version
2.5.2.v20100208 Build &lt;2.5.2.v20100210-0630></property>
<property name="units">in</property>
<method
name="beforeFactory">< ![CDATA[importPackage(Packages.org.eclipse.birt.report.model .api);
importPackage(Packages.org.eclipse.birt.report.model.api.ele ments);
importPackage(Packages.org.eclipse.birt.report.model.api.ele ments.structures);

var th = reportContext.getDesignHandle().findElement("mytable");

var max = th.getColumns().getCount();
var stc = params["startcolumn"].value
var enc = params["endcolumn"].value
if( enc > max-1 ){
enc=max-1;
}

for( jj=stc; jj<= enc; jj++ ){
var ch = th.getColumns().get(jj);
var hr = StructureFactory.createHighlightRule();

hr.setOperator(DesignChoiceConstants.MAP_OPERATOR_BETWEEN);
hr.setTestExpression("row.__rownum");
hr.setValue1("params[\"startrow\"].value");
hr.setValue2("params[\"endrow\"].value");
hr.setProperty(HighlightRule.BACKGROUND_COLOR_MEMBER, "green");

var ph = ch.getPropertyHandle(StyleHandle.HIGHLIGHT_RULES_PROP);
ph.addItem(hr);
}
]]></method>
<property name="iconFile">/templates/blank_report.gif</property>
<property name="bidiLayoutOrientation">ltr</property>
<property name="imageDPI">96</property>
<parameters>
<scalar-parameter name="startrow" id="43">
<property name="valueType">static</property>
<property name="dataType">integer</property>
<property name="distinct">true</property>
<simple-property-list name="defaultValue">
<value type="constant">0</value>
</simple-property-list>
<property name="paramType">simple</property>
<property name="controlType">text-box</property>
<structure name="format">
<property name="category">Unformatted</property>
</structure>
</scalar-parameter>
<scalar-parameter name="endrow" id="44">
<property name="valueType">static</property>
<property name="dataType">integer</property>
<property name="distinct">true</property>
<simple-property-list name="defaultValue">
<value type="constant">10</value>
</simple-property-list>
<property name="paramType">simple</property>
<property name="controlType">text-box</property>
<structure name="format">
<property name="category">Unformatted</property>
</structure>
</scalar-parameter>
<scalar-parameter name="startcolumn" id="45">
<property name="valueType">static</property>
<property name="dataType">integer</property>
<property name="distinct">true</property>
<simple-property-list name="defaultValue">
<value type="constant">0</value>
</simple-property-list>
<property name="paramType">simple</property>
<property name="controlType">text-box</property>
<structure name="format">
<property name="category">Unformatted</property>
</structure>
</scalar-parameter>
<scalar-parameter name="endcolumn" id="46">
<property name="valueType">static</property>
<property name="dataType">integer</property>
<property name="distinct">true</property>
<simple-property-list name="defaultValue">
<value type="constant">5</value>
</simple-property-list>
<property name="paramType">simple</property>
<property name="controlType">text-box</property>
<structure name="format">
<property name="category">Unformatted</property>
</structure>
</scalar-parameter>
</parameters>
<data-sources>
<oda-data-source
extensionID="org.eclipse.birt.report.data.oda.jdbc" name="Data Source"
id="7">
<text-property name="displayName"></text-property>
<property
name="odaDriverClass">org.eclipse.birt.report.data.oda.sampledb.Driver </property>
<property name="odaURL">jdbc:classicmodels:sampledb</property>
<property name="odaUser">ClassicModels</property>
<property name="OdaConnProfileName"></property>
</oda-data-source>
</data-sources>
<data-sets>
<oda-data-set
extensionID="org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet "
name="Data Set" id="8">
<list-property name="columnHints">
<structure>
<property name="columnName">ORDERNUMBER</property>
<text-property
name="displayName">ORDERNUMBER</text-property>
</structure>
<structure>
<property name="columnName">PRODUCTCODE</property>
<text-property
name="displayName">PRODUCTCODE</text-property>
</structure>
<structure>
<property name="columnName">QUANTITYORDERED</property>
<text-property
name="displayName">QUANTITYORDERED</text-property>
</structure>
<structure>
<property name="columnName">PRICEEACH</property>
<text-property
name="displayName">PRICEEACH</text-property>
</structure>
<structure>
<property name="columnName">ORDERLINENUMBER</property>
<text-property
name="displayName">ORDERLINENUMBER</text-property>
</structure>
</list-property>
<structure name="cachedMetaData">
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">ORDERNUMBER</property>
<property name="dataType">integer</property>
</structure>
<structure>
<property name="position">2</property>
<property name="name">PRODUCTCODE</property>
<property name="dataType">string</property>
</structure>
<structure>
<property name="position">3</property>
<property name="name">QUANTITYORDERED</property>
<property name="dataType">integer</property>
</structure>
<structure>
<property name="position">4</property>
<property name="name">PRICEEACH</property>
<property name="dataType">float</property>
</structure>
<structure>
<property name="position">5</property>
<property name="name">ORDERLINENUMBER</property>
<property name="dataType">integer</property>
</structure>
</list-property>
</structure>
<property name="dataSource">Data Source</property>
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">ORDERNUMBER</property>
<property name="nativeName">ORDERNUMBER</property>
<property name="dataType">integer</property>
<property name="nativeDataType">4</property>
</structure>
<structure>
<property name="position">2</property>
<property name="name">PRODUCTCODE</property>
<property name="nativeName">PRODUCTCODE</property>
<property name="dataType">string</property>
<property name="nativeDataType">12</property>
</structure>
<structure>
<property name="position">3</property>
<property name="name">QUANTITYORDERED</property>
<property name="nativeName">QUANTITYORDERED</property>
<property name="dataType">integer</property>
<property name="nativeDataType">4</property>
</structure>
<structure>
<property name="position">4</property>
<property name="name">PRICEEACH</property>
<property name="nativeName">PRICEEACH</property>
<property name="dataType">float</property>
<property name="nativeDataType">8</property>
</structure>
<structure>
<property name="position">5</property>
<property name="name">ORDERLINENUMBER</property>
<property name="nativeName">ORDERLINENUMBER</property>
<property name="dataType">integer</property>
<property name="nativeDataType">5</property>
</structure>
</list-property>
<xml-property name="queryText"><![CDATA[select *
from orderdetails
where ordernumber = 10104
]]></xml-property>
<xml-property name="designerValues"><![CDATA[<?xml
version="1.0" encoding="UTF-8"?>
<model:DesignValues
xmlns:design="http://www.eclipse.org/datatools/connectivity/oda/design"
xmlns:model="http://www.eclipse.org/birt/report/model/adapter/odaModel">
<Version>1.0</Version>
<design:ResultSets derivedMetaData="true">
<design:resultSetDefinitions>
<design:resultSetColumns>
<design:resultColumnDefinitions>
<design:attributes>
<design:name>ORDERNUMBER</design:name>
<design:position>1</design:position>
<design:nativeDataTypeCode>4</design:nativeDataTypeCode>
<design:precision>10</design:precision>
<design:scale>0</design:scale>
<design:nullability>Nullable</design:nullability>
<design:uiHints>
<design:displayName>ORDERNUMBER</design:displayName>
</design:uiHints>
</design:attributes>
<design:usageHints>
<design:label>ORDERNUMBER</design:label>
<design:formattingHints>
<design:displaySize>11</design:displaySize>
</design:formattingHints>
</design:usageHints>
</design:resultColumnDefinitions>
<design:resultColumnDefinitions>
<design:attributes>
<design:name>PRODUCTCODE</design:name>
<design:position>2</design:position>
<design:nativeDataTypeCode>12</design:nativeDataTypeCode>
<design:precision>15</design:precision>
<design:scale>0</design:scale>
<design:nullability>Nullable</design:nullability>
<design:uiHints>
<design:displayName>PRODUCTCODE</design:displayName>
</design:uiHints>
</design:attributes>
<design:usageHints>
<design:label>PRODUCTCODE</design:label>
<design:formattingHints>
<design:displaySize>15</design:displaySize>
</design:formattingHints>
</design:usageHints>
</design:resultColumnDefinitions>
<design:resultColumnDefinitions>
<design:attributes>
<design:name>QUANTITYORDERED</design:name>
<design:position>3</design:position>
<design:nativeDataTypeCode>4</design:nativeDataTypeCode>
<design:precision>10</design:precision>
<design:scale>0</design:scale>
<design:nullability>Nullable</design:nullability>
<design:uiHints>
<design:displayName>QUANTITYORDERED</design:displayName>
</design:uiHints>
</design:attributes>
<design:usageHints>
<design:label>QUANTITYORDERED</design:label>
<design:formattingHints>
<design:displaySize>11</design:displaySize>
</design:formattingHints>
</design:usageHints>
</design:resultColumnDefinitions>
<design:resultColumnDefinitions>
<design:attributes>
<design:name>PRICEEACH</design:name>
<design:position>4</design:position>
<design:nativeDataTypeCode>8</design:nativeDataTypeCode>
<design:precision>15</design:precision>
<design:scale>0</design:scale>
<design:nullability>Nullable</design:nullability>
<design:uiHints>
<design:displayName>PRICEEACH</design:displayName>
</design:uiHints>
</design:attributes>
<design:usageHints>
<design:label>PRICEEACH</design:label>
<design:formattingHints>
<design:displaySize>22</design:displaySize>
</design:formattingHints>
</design:usageHints>
</design:resultColumnDefinitions>
<design:resultColumnDefinitions>
<design:attributes>
<design:name>ORDERLINENUMBER</design:name>
<design:position>5</design:position>
<design:nativeDataTypeCode>5</design:nativeDataTypeCode>
<design:precision>5</design:precision>
<design:scale>0</design:scale>
<design:nullability>Nullable</design:nullability>
<design:uiHints>
<design:displayName>ORDERLINENUMBER</design:displayName>
</design:uiHints>
</design:attributes>
<design:usageHints>
<design:label>ORDERLINENUMBER</design:label>
<design:formattingHints>
<design:displaySize>6</design:displaySize>
</design:formattingHints>
</design:usageHints>
</design:resultColumnDefinitions>
</design:resultSetColumns>
<design:criteria/>
</design:resultSetDefinitions>
</design:ResultSets>
</model:DesignValues>
]]></xml-property>
</oda-data-set>
</data-sets>
<styles>
<style name="report" id="4">
<property name="fontFamily">sans-serif</property>
<property name="fontSize">10pt</property>
</style>
<style name="crosstab-cell" id="5">
<property name="borderBottomColor">#CCCCCC</property>
<property name="borderBottomStyle">solid</property>
<property name="borderBottomWidth">1pt</property>
<property name="borderLeftColor">#CCCCCC</property>
<property name="borderLeftStyle">solid</property>
<property name="borderLeftWidth">1pt</property>
<property name="borderRightColor">#CCCCCC</property>
<property name="borderRightStyle">solid</property>
<property name="borderRightWidth">1pt</property>
<property name="borderTopColor">#CCCCCC</property>
<property name="borderTopStyle">solid</property>
<property name="borderTopWidth">1pt</property>
</style>
<style name="crosstab" id="6">
<property name="borderBottomColor">#CCCCCC</property>
<property name="borderBottomStyle">solid</property>
<property name="borderBottomWidth">1pt</property>
<property name="borderLeftColor">#CCCCCC</property>
<property name="borderLeftStyle">solid</property>
<property name="borderLeftWidth">1pt</property>
<property name="borderRightColor">#CCCCCC</property>
<property name="borderRightStyle">solid</property>
<property name="borderRightWidth">1pt</property>
<property name="borderTopColor">#CCCCCC</property>
<property name="borderTopStyle">solid</property>
<property name="borderTopWidth">1pt</property>
</style>
</styles>
<page-setup>
<simple-master-page name="Simple MasterPage" id="2">
<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>
<body>
<table name="mytable" id="9">
<property name="dataSet">Data Set</property>
<list-property name="boundDataColumns">
<structure>
<property name="name">ORDERNUMBER</property>
<text-property
name="displayName">ORDERNUMBER</text-property>
<expression name="expression"
type="javascript">dataSetRow["ORDERNUMBER"]</expression >
<property name="dataType">integer</property>
</structure>
<structure>
<property name="name">PRODUCTCODE</property>
<text-property
name="displayName">PRODUCTCODE</text-property>
<expression name="expression"
type="javascript">dataSetRow["PRODUCTCODE"]</expression >
<property name="dataType">string</property>
</structure>
<structure>
<property name="name">QUANTITYORDERED</property>
<text-property
name="displayName">QUANTITYORDERED</text-property>
<expression name="expression"
type="javascript">dataSetRow["QUANTITYORDERED"]</expression >
<property name="dataType">integer</property>
</structure>
<structure>
<property name="name">PRICEEACH</property>
<text-property
name="displayName">PRICEEACH</text-property>
<expression name="expression"
type="javascript">dataSetRow["PRICEEACH"]</expression>
<property name="dataType">float</property>
</structure>
<structure>
<property name="name">ORDERLINENUMBER</property>
<text-property
name="displayName">ORDERLINENUMBER</text-property>
<expression name="expression"
type="javascript">dataSetRow["ORDERLINENUMBER"]</expression >
<property name="dataType">integer</property>
</structure>
</list-property>
<column id="38"/>
<column id="39"/>
<column id="40"/>
<column id="41"/>
<column id="42"/>
<header>
<row id="10">
<cell id="11">
<label id="12">
<text-property
name="text">ORDERNUMBER</text-property>
</label>
</cell>
<cell id="13">
<label id="14">
<text-property
name="text">PRODUCTCODE</text-property>
</label>
</cell>
<cell id="15">
<label id="16">
<text-property
name="text">QUANTITYORDERED</text-property>
</label>
</cell>
<cell id="17">
<label id="18">
<text-property
name="text">PRICEEACH</text-property>
</label>
</cell>
<cell id="19">
<label id="20">
<text-property
name="text">ORDERLINENUMBER</text-property>
</label>
</cell>
</row>
</header>
<detail>
<row id="21">
<cell id="22">
<data id="23">
<property
name="resultSetColumn">ORDERNUMBER</property>
</data>
</cell>
<cell id="24">
<data id="25">
<property
name="resultSetColumn">PRODUCTCODE</property>
</data>
</cell>
<cell id="26">
<data id="27">
<property
name="resultSetColumn">QUANTITYORDERED</property>
</data>
</cell>
<cell id="28">
<data id="29">
<property
name="resultSetColumn">PRICEEACH</property>
</data>
</cell>
<cell id="30">
<data id="31">
<property
name="resultSetColumn">ORDERLINENUMBER</property>
</data>
</cell>
</row>
</detail>
<footer>
<row id="32">
<cell id="33"/>
<cell id="34"/>
<cell id="35"/>
<cell id="36"/>
<cell id="37"/>
</row>
</footer>
</table>
</body>
</report>


On 12/16/2010 2:11 PM, Nils wrote:
> hi all :)
>
> I'm stuck with a problem:
>
> I use the DEAPI to modify a rptdesign. Every now and then I need to hide
> a Grid based on a set of rules.
>
> I have absolutely no idea how to do this using the api (Birt 2.6.1)
>
> I tried grid.setProperty("visibility", someHideRule) but that keeps
> telling me, that someHideRule is invalid with the type "structure".
> What am I doing wrong?
>
> Any help appreciated :)
> cheers,
> nils
Re: grid visibility using deapi [message #645476 is a reply to message #645388] Fri, 17 December 2010 11:20 Go to previous messageGo to next message
Nils is currently offline NilsFriend
Messages: 15
Registered: August 2010
Location: Stuttgart
Junior Member
hi jason,

thanks Smile

but... I don't get it??
I don't see any reference to javacode using the designengine-api to make a gridelement appear or disappear?

I'm creating a report using the api and I want to change the visibility of an element based on set of rules...

cheers,
nils
Re: grid visibility using deapi [message #645513 is a reply to message #645476] Fri, 17 December 2010 14:59 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Nils,

I misunderstood what you needed. I put the code in the beforeFactory
script. I am attaching a demo java class that shows how to do a bunch
of different stuff with the DE API. Visibility is in the example.

Jason

package DEAPI;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;


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.ImageHandle;
import org.eclipse.birt.report.model.api.ActionHandle;
import org.eclipse.birt.report.model.api.ReportElementHandle;
import org.eclipse.birt.report.model.api.ScalarParameterHandle;
import org.eclipse.birt.report.model.api.ScriptLibHandle;
import org.eclipse.birt.report.model.elements.JointDataSet;

import org.eclipse.birt.report.model.api.OdaDataSetHandle;
import org.eclipse.birt.report.model.api.JointDataSetHandle;
import org.eclipse.birt.report.model.api.JoinConditionHandle;



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.structures.Comput edColumn;
import org.eclipse.birt.report.model.api.PropertyHandle;
import org.eclipse.birt.report.model.elements.ReportItem;

import org.eclipse.birt.report.model.api.elements.structures.Embedd edImage;

import org.eclipse.birt.report.model.elements.Style;
import org.eclipse.birt.report.model.elements.ReportDesign;

import org.eclipse.birt.report.model.api.StyleHandle;

import
org.eclipse.birt.report.model.api.elements.structures.Aggreg ationArgument;
import
org.eclipse.birt.report.model.api.elements.structures.DateTi meFormatValue;
import org.eclipse.birt.report.model.api.elements.structures.Format Value;
import org.eclipse.birt.report.model.api.elements.structures.MapRul e;
import org.eclipse.birt.report.model.api.elements.structures.HideRu le;
import
org.eclipse.birt.report.model.api.elements.structures.Proper tyBinding;
import org.eclipse.birt.report.model.api.elements.structures.TOC;
import org.eclipse.birt.report.model.api.elements.structures.JoinCo ndition;
import org.eclipse.birt.report.model.api.elements.structures.ParamB inding;


import org.eclipse.birt.report.model.api.elements.DesignChoiceConst ants;

import org.eclipse.birt.report.model.api.elements.structures.Highli ghtRule;
import org.eclipse.birt.report.model.elements.interfaces.IJointData SetModel;

import org.eclipse.birt.report.model.api.elements.structures.SortKe y;
import org.eclipse.birt.report.model.api.SortKeyHandle;

import
org.eclipse.birt.report.model.api.elements.structures.Filter Condition;
import org.eclipse.birt.report.model.api.elements.structures.Action ;
import org.eclipse.birt.report.model.api.elements.structures.Includ eScript;
import java.util.Iterator;


import com.ibm.icu.util.ULocale;

/**
* Simple BIRT Design Engine API (DEAPI) demo.
*/

public class StructFactoryTest
{
ReportDesignHandle designHandle = null;
ElementFactory designFactory = null;
StructureFactory structFactory = null;

public static void main( String[] args )
{
try
{
StructFactoryTest de = new StructFactoryTest();
de.buildReport();
}
catch ( IOException e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch ( SemanticException e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}

void buildDataSource( ) 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", "" );

PropertyBinding pb = new PropertyBinding();

designHandle.getDataSources( ).add( dsHandle );
long currid = dsHandle.getID();
//pb.setName("odaUser");
//pb.setID(currid);
//pb.setValue("params[\"NewParameter\"].value");
//PropertyHandle ph = designHandle.getPropertyHandle("propertyBindings");
//ph.addItem(pb);

}

void buildDataSet( ) throws SemanticException
{

OdaDataSetHandle dsHandle = designFactory.newOdaDataSet( "ds",
"org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
dsHandle.setDataSource( "Data Source" );
String qry = "Select * from customers";

dsHandle.setQueryText( qry );

addFilterCondition( dsHandle );

designHandle.getDataSets( ).add( dsHandle );



}
void buildDataSet2( ) throws SemanticException
{

OdaDataSetHandle dsHandle = designFactory.newOdaDataSet( "ds2",
"org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
dsHandle.setDataSource( "Data Source" );
String qry = "Select * from orderdetails where ordernumber = ?";

dsHandle.setQueryText( qry );

addFilterCondition( dsHandle );

designHandle.getDataSets( ).add( dsHandle );



}

void buildJointDataSet( ) throws SemanticException
{
OdaDataSetHandle dsHandle1 = designFactory.newOdaDataSet( "ds1",
"org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
dsHandle1.setDataSource( "Data Source" );
String qry1 = "Select * from customers";

dsHandle1.setQueryText( qry1 );


OdaDataSetHandle dsHandle2 = designFactory.newOdaDataSet( "ds2",
"org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
dsHandle2.setDataSource( "Data Source" );
String qry2 = "Select * from orders";

dsHandle2.setQueryText( qry2 );

JointDataSetHandle jds = designFactory.newJointDataSet("test");

designHandle.getDataSets( ).add( dsHandle1 );
designHandle.getDataSets( ).add( dsHandle2 );

jds.addDataSet("ds1");
jds.addDataSet("ds2");

String leftExpression = "dataSetRow[\"CUSTOMERNUMBER\"]";
String rightExpression = "dataSetRow[\"CUSTOMERNUMBER\"]";
JoinCondition condition = StructureFactory.createJoinCondition( );
condition.setJoinType( DesignChoiceConstants.JOIN_TYPE_LEFT_OUT );
condition.setOperator( DesignChoiceConstants.JOIN_OPERATOR_EQALS );
condition.setLeftDataSet( "ds1" ); //$NON-NLS-1$
condition.setRightDataSet( "ds2" ); //$NON-NLS-1$
condition.setLeftExpression( leftExpression ); //$NON-NLS-1$
condition.setRightExpression( rightExpression ); //$NON-NLS-1$

PropertyHandle conditionHandle = jds
.getPropertyHandle( JointDataSet.JOIN_CONDITONS_PROP );
conditionHandle.addItem( condition );

designHandle.getDataSets( ).add( jds );


}

void addMapRule(TableHandle th){
try{


MapRule mr = structFactory.createMapRule();
mr.setTestExpression("row[\"CustomerCreditLimit\"]");
mr.setOperator(DesignChoiceConstants.MAP_OPERATOR_EQ);
mr.setValue1("0");
mr.setDisplay("N/A");

PropertyHandle ph = th.getPropertyHandle(StyleHandle.MAP_RULES_PROP);
ph.addItem(mr);
}catch (Exception e){
e.printStackTrace();
}
}

void addVisRule(ReportElementHandle rh){
try{
HideRule hr = structFactory.createHideRule();
hr.setFormat("pdf");
hr.setExpression("true");

PropertyHandle ph = rh.getPropertyHandle(ReportItem.VISIBILITY_PROP);
ph.addItem(hr);
}catch (Exception e){
e.printStackTrace();
}
}
void addBottomBorder(ReportElementHandle rh){
try{


rh.setProperty(StyleHandle.BORDER_BOTTOM_COLOR_PROP, "#000000");
rh.setProperty(StyleHandle.BORDER_BOTTOM_STYLE_PROP, "solid");
rh.setProperty(StyleHandle.BORDER_BOTTOM_WIDTH_PROP, "2px");

}catch (Exception e){
e.printStackTrace();
}
}
void addHighLightRule(RowHandle th){
try{
HighlightRule hr = structFactory.createHighlightRule();

hr.setOperator(DesignChoiceConstants.MAP_OPERATOR_GT);
hr.setTestExpression("row[\"CustomerCreditLimit\"]");
hr.setValue1("100000");
hr.setProperty(HighlightRule.BACKGROUND_COLOR_MEMBER, "blue");

PropertyHandle ph =
th.getPropertyHandle(StyleHandle.HIGHLIGHT_RULES_PROP);

ph.addItem(hr);
}catch (Exception e){
e.printStackTrace();
}
}

void addSortKey(TableHandle th){
try{
SortKey sk = structFactory.createSortKey();
//sk.setKey("row[\"CustomerName\"]");
sk.setDirection(DesignChoiceConstants.SORT_DIRECTION_ASC);
sk.setKey("if( params[\"srt\"].value){ if( params[\"srt\"].value ==
'a' ){ row[\"CustomerName\"]; }else{ row[\"CustomerCity\"];}}");


PropertyHandle ph = th.getPropertyHandle(TableHandle.SORT_PROP);
ph.addItem(sk);
}catch (Exception e){
e.printStackTrace();
}
}

void modSortKey(TableHandle th){
try{
SortKeyHandle sk;
PropertyHandle ph = th.getPropertyHandle(TableHandle.SORT_PROP);
//get number or iterate
sk = (SortKeyHandle)ph.get(0);
sk.setDirection(DesignChoiceConstants.SORT_DIRECTION_DESC);
}catch (Exception e){
e.printStackTrace();
}
}

void addFilterCondition(OdaDataSetHandle dh){
try{
FilterCondition fc = structFactory.createFilterCond();
fc.setExpr("row[\"COUNTRY\"]");
fc.setOperator(DesignChoiceConstants.MAP_OPERATOR_EQ);
fc.setValue1("'USA'");

dh.addFilter(fc);

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

void addFilterCondition(TableHandle th){
try{

FilterCondition fc = structFactory.createFilterCond();
fc.setExpr("row[\"CustomerCountry\"]");
fc.setOperator(DesignChoiceConstants.MAP_OPERATOR_EQ);
fc.setValue1("'USA'");

PropertyHandle ph = th.getPropertyHandle(TableHandle.FILTER_PROP);

ph.addItem(fc);
}catch (Exception e){
e.printStackTrace();
}
}
void addHyperlink(LabelHandle lh){
try{
Action ac = structFactory.createAction();

ActionHandle actionHandle = lh.setAction( ac );
//actionHandle.setURI("'http://www.google.com'");

actionHandle.setLinkType(DesignChoiceConstants.ACTION_LINK_T YPE_DRILL_THROUGH);
actionHandle.setReportName("c:/test/xyz.rptdesign");
actionHandle.setTargetFileType("report-design");
actionHandle.setTargetWindow("_blank");
actionHandle.getMember("paramBindings");
ParamBinding pb = structFactory.createParamBinding();
pb.setParamName("order");
pb.setExpression("row[\"ORDERNUMBER\"]");
actionHandle.addParamBinding(pb);
/*
<structure name="action">
<property name="linkType">drill-through</property>
<property name="reportName">detail.rptdesign</property>
<property name="targetWindow">_blank</property>
<property name="targetFileType">report-design</property>
<list-property name="paramBindings">
<structure>
<property name="paramName">order</property>
<expression
name="expression">row["ORDERNUMBER"]</expression>
</structure>
</list-property>
</structure>
*/




}catch (Exception e){
e.printStackTrace();
}
}
void addToc(DataItemHandle dh){
try{
TOC myToc = structFactory.createTOC("row[\"CustomerName\"]");

dh.addTOC(myToc);
}catch (Exception e){
e.printStackTrace();
}
}


void addImage(){
try{
EmbeddedImage image = structFactory.createEmbeddedImage( );
image.setType( DesignChoiceConstants.IMAGE_TYPE_IMAGE_JPEG );
image.setData( load( "logo3.jpg" ) );
image.setName( "mylogo" );

designHandle.addImage( image );
}catch (Exception e){
e.printStackTrace();
}
}

public byte[] load( String fileName ) throws IOException
{
InputStream is = null;

is = new BufferedInputStream( this.getClass( ).getResourceAsStream(
fileName ) );
byte data[] = null;
if ( is != null )
{
try
{
data = new byte[is.available( )];
is.read( data );
}
catch ( IOException e1 )
{
throw e1;
}
}
return data;
}
void addScript(ReportDesignHandle rh){
try{
IncludeScript is = structFactory.createIncludeScript();
is.setFileName("test.js");
//PropertyHandle ph =
rh.getPropertyHandle(ReportDesign.INCLUDE_SCRIPTS_PROP);
//ph.addItem(is);


}catch (Exception e){
e.printStackTrace();
}
}
void buildReport() throws IOException, SemanticException
{

DesignConfig config = new DesignConfig( );

config.setBIRTHome("C:/birt/birt-runtime-2_5_1/birt-runtime-2_5_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();
}


SessionHandle session = engine.newSessionHandle( ULocale.ENGLISH ) ;

ReportDesignHandle design = null;



try{
//open a design or a template
designHandle = session.createDesign();
addScript( designHandle);
designFactory = designHandle.getElementFactory( );
//designHandle.findScriptLib("name").setName("test2");
//Iterator iter = designHandle.scriptLibsIterator( );
//((ScriptLibHandle) iter.next()).drop() ;

//designHandle.dropScriptLib( lib );

buildDataSource();
buildDataSet();
buildJointDataSet();

TableHandle table = designFactory.newTableItem( "table", 3 );
table.setWidth( "100%" );
table.setDataSet( designHandle.findDataSet( "ds" ) );


//StructureFactory.createIncludedCssStyleSheet()


PropertyHandle computedSet = table.getColumnBindings( );
ComputedColumn cs1, cs2, cs3, cs4, cs5;


cs1 = StructureFactory.createComputedColumn();
cs1.setName("CustomerName");
cs1.setExpression("dataSetRow[\"CUSTOMERNAME\"]");
computedSet.addItem(cs1);
cs2 = StructureFactory.createComputedColumn();
cs2.setName("CustomerCity");
cs2.setExpression("dataSetRow[\"CITY\"]");
//cs2.setDataType(dataType)
computedSet.addItem(cs2);
cs3 = StructureFactory.createComputedColumn();
cs3.setName("CustomerCountry");
cs3.setExpression("dataSetRow[\"COUNTRY\"]");
computedSet.addItem(cs3);
cs4 = StructureFactory.createComputedColumn();
cs4.setName("CustomerCreditLimit");
cs4.setExpression("dataSetRow[\"CREDITLIMIT\"]");
computedSet.addItem(cs4);

cs5 = StructureFactory.createComputedColumn();
cs5.setName("CustomerCreditLimitSum");
cs5.setExpression("dataSetRow[\"CREDITLIMIT\"]");
cs5.setAggregateFunction("sum");
//cs5.setFilterExpression(expression)
//All or group name
//cs5.setAggregateOn(aggregateOn)
computedSet.addItem(cs5);




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

ColumnHandle ch = (ColumnHandle)table.getColumns().get(0);
ch.setProperty("width", "50%");


ColumnHandle ch2 = (ColumnHandle)table.getColumns().get(1);
ch2.setSuppressDuplicates(true);

LabelHandle label1 = designFactory.newLabel("Label1" );
label1.setOnRender("var x = 3;");
addBottomBorder(label1);
label1.setText("Customer");
CellHandle cell = (CellHandle) tableheader.getCells( ).get( 0 );

cell.getContent( ).add( label1 );
LabelHandle label2 = designFactory.newLabel("Label2" );
label2.setText("City");
cell = (CellHandle) tableheader.getCells( ).get( 1 );
cell.getContent( ).add( label2 );
LabelHandle label3 = designFactory.newLabel("Label3" );
label3.setText("Credit Limit");
cell = (CellHandle) tableheader.getCells( ).get( 2 );

cell.getContent( ).add( label3 );


// table detail
RowHandle tabledetail = (RowHandle) table.getDetail( ).get( 0 );


cell = (CellHandle) tabledetail.getCells( ).get( 0 );
DataItemHandle data = designFactory.newDataItem( "data1" );
data.setResultSetColumn("CustomerName");

addToc( data );


cell.getContent( ).add( data );
cell = (CellHandle) tabledetail.getCells( ).get( 1 );
data = designFactory.newDataItem( "data2" );
data.setResultSetColumn("CustomerCity");
cell.getContent( ).add( data );
cell = (CellHandle) tabledetail.getCells( ).get( 2 );
data = designFactory.newDataItem( "data3" );
data.setResultSetColumn("CustomerCreditLimit");
cell.getContent( ).add( data );

addHyperlink(label1);
addMapRule(table);
addHighLightRule(tabledetail);
addSortKey(table);
modSortKey(table);
addFilterCondition(table);
addImage();

RowHandle tablefooter = (RowHandle) table.getFooter().get( 0 );
cell = (CellHandle) tablefooter.getCells( ).get( 0 );

ImageHandle image1 = designFactory.newImage( "mylogo" );
image1.setImageName( "mylogo" );
//image1.sets
//addVisRule( image1 );
//cell.getContent( ).add( image1 );

cell = (CellHandle) tablefooter.getCells( ).get( 2 );
data = designFactory.newDataItem( "datasum" );
//FormatValue formatValueToSet = new DateTimeFormatValue( );
//formatValueToSet.setPattern( "dd/mm/yy" );
//formatValueToSet.setCategory("Custom");
//data.setProperty( StyleHandle.DATE_TIME_FORMAT_PROP,
// formatValueToSet );
//has to have a style data.getStyle().setDateTimeFormat("dd/mm/yy");
data.setResultSetColumn("CustomerCreditLimitSum");
cell.getContent( ).add( data );

ScalarParameterHandle sph = designFactory.newScalarParameter("srt");
sph.setIsRequired(false);
//sph.setAllowNull(true);
//sph.setAllowBlank(true);
sph.setValueType(DesignChoiceConstants.PARAM_VALUE_TYPE_STAT IC);
sph.setDataType(DesignChoiceConstants.PARAM_TYPE_STRING);
designHandle.getParameters().add(sph);

designHandle.getBody( ).add( table );


// Save the design and close it.

designHandle.saveAs("output/desample/structfactorytest.rptdesign " );
designHandle.close( );
Platform.shutdown();
System.out.println("Finished");
}catch (Exception e){
e.printStackTrace();
}

}
}



On 12/17/2010 6:20 AM, Nils wrote:
> hi jason,
>
> thanks :)
>
> but... I don't get it??
> I don't see any reference to javacode using the designengine-api to make
> a gridelement appear or disappear?
>
> I'm creating a report using the api and I want to change the visibility
> of an element based on set of rules...
>
> cheers,
> nils
Re: grid visibility using deapi [message #645728 is a reply to message #645375] Mon, 20 December 2010 09:48 Go to previous messageGo to next message
Nils is currently offline NilsFriend
Messages: 15
Registered: August 2010
Location: Stuttgart
Junior Member
great!
exactly what I was looking for Smile

thanx a lot, merry xmas and a happy new year, jason!

nils
Re: grid visibility using deapi [message #645805 is a reply to message #645728] Mon, 20 December 2010 16:20 Go to previous message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Merry Christmas and happy new year to you as well.

On 12/20/2010 4:48 AM, Nils wrote:
> great!
> exactly what I was looking for :)
>
> thanx a lot, merry xmas and a happy new year, jason!
>
> nils
Previous Topic:Cascading parameter issue
Next Topic:Insufficient data for an image
Goto Forum:
  


Current Time: Sun Dec 21 14:40:55 GMT 2014

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

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