Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » Can I get all possible values of dynamic parameter from RE?
Can I get all possible values of dynamic parameter from RE? [message #735726] Wed, 12 October 2011 15:30 Go to next message
Alexey Romanov is currently offline Alexey RomanovFriend
Messages: 263
Registered: May 2010
Senior Member
Reusable library for reloading a report sample shows how to access parameters and their values from the recordContext variable. Is it possible to get all possible values for dynamic parameters as well?
Re: Can I get all possible values of dynamic parameter from RE? [message #735773 is a reply to message #735726] Wed, 12 October 2011 16:48 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Using the RE API you can. for example:




import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
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.EngineException;
import org.eclipse.birt.report.engine.api.IGetParameterDefinitionTask;
import org.eclipse.birt.report.engine.api.IParameterDefnBase;
import org.eclipse.birt.report.engine.api.IParameterGroupDefn;
import org.eclipse.birt.report.engine.api.IParameterSelectionChoice;
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.IScalarParameterDefn;
import org.eclipse.birt.report.model.api.CascadingParameterGroupHandle;
import org.eclipse.birt.report.model.api.ScalarParameterHandle;

public class ReportCascadedParameters {

static void executeReport() throws EngineException
{
HashMap parmDetails = new HashMap();
IReportEngine engine=null;
EngineConfig config = null;
try{

config = new EngineConfig( );

config.setBIRTHome("C:\\birt\\birt-runtime-2_5_1\\birt-runtime-2_5_1\\ReportEngine");
config.setLogConfig(null, Level.OFF);
Platform.startup( config );
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject(
IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );
}catch( Exception ex){
ex.printStackTrace();
}


//Open a report design
IReportRunnable design =
engine.openReportDesign("reports/parmevents.rptdesign");

IGetParameterDefinitionTask task =
engine.createGetParameterDefinitionTask( design );
Collection params = task.getParameterDefns( true );


//task.getSelectionListForCascadingGroup();
Iterator iter = params.iterator( );
while ( iter.hasNext( ) )
{
IParameterDefnBase param = (IParameterDefnBase) iter.next( );

if ( param instanceof IParameterGroupDefn )
{
IParameterGroupDefn group = (IParameterGroupDefn) param;
System.out.println( "Parameter Group: " + group.getName( ) );


// Do something with the parameter group.
// Iterate over group contents.

Iterator i2 = group.getContents( ).iterator( );
while ( i2.hasNext( ) )
{
IScalarParameterDefn scalar = (IScalarParameterDefn) i2.next( );
//System.out.println("\t" + scalar.getName());
parmDetails.put( scalar.getName(), loadParameterDetails( task,
scalar, design, group));
}

}
else
{

IScalarParameterDefn scalar = (IScalarParameterDefn) param;

//System.out.println(param.getName());
parmDetails.put( scalar.getName(),loadParameterDetails( task,
scalar, design, null));


}
}


task.close();
engine.destroy();
}

private static HashMap loadParameterDetails(IGetParameterDefinitionTask
task, IScalarParameterDefn scalar, IReportRunnable report,
IParameterGroupDefn group){



HashMap parameter = new HashMap();

if( group == null){
parameter.put("Parameter Group", "Default");
}else{
parameter.put("Parameter Group", group.getName());
}
parameter.put("Name", scalar.getName());
parameter.put("Help Text", scalar.getHelpText());
parameter.put("Display Name", scalar.getDisplayName());
//this is a format code such as > for UPPERCASE
parameter.put("Display Format", scalar.getDisplayFormat());

if( scalar.isHidden() ){
parameter.put("Hidden", "Yes");
}else{
parameter.put("Hidden", "No");
}

if( scalar.isValueConcealed() ){
parameter.put("Conceal Entry", "Yes"); //ie passwords etc
}else{
parameter.put("Conceal Entry", "No");
}


switch (scalar.getControlType()) {
case IScalarParameterDefn.TEXT_BOX: parameter.put("Type", "Text
Box"); break;
case IScalarParameterDefn.LIST_BOX: parameter.put("Type", "List
Box"); break;
case IScalarParameterDefn.RADIO_BUTTON: parameter.put("Type", "List
Box"); break;
case IScalarParameterDefn.CHECK_BOX: parameter.put("Type", "List
Box"); break;
default: parameter.put("Type", "Text Box");break;
}

int xx = scalar.getDataType();

switch (scalar.getDataType()) {
case IScalarParameterDefn.TYPE_STRING: parameter.put("Data Type",
"String"); break;
case IScalarParameterDefn.TYPE_FLOAT: parameter.put("Data Type",
"Float"); break;
case IScalarParameterDefn.TYPE_DECIMAL: parameter.put("Data Type",
"Decimal"); break;
case IScalarParameterDefn.TYPE_DATE_TIME: parameter.put("Data Type",
"Date Time"); break;
case IScalarParameterDefn.TYPE_BOOLEAN: parameter.put("Data Type",
"Boolean"); break;
case IScalarParameterDefn.TYPE_INTEGER: parameter.put("Data Type",
"Integer"); break;

default: parameter.put("Data Type", "Any"); break;
}


ScalarParameterHandle parameterHandle = ( ScalarParameterHandle )
scalar.getHandle();

parameter.put("Default Value", scalar.getDefaultValue());
parameter.put("Prompt Text", scalar.getPromptText());
parameter.put("Data Set Expression", parameterHandle.getValueExpr());

if(scalar.getControlType() != IScalarParameterDefn.TEXT_BOX)
{
//System.out.println("dynamic parameter");

if ( parameterHandle.getContainer( ) instanceof
CascadingParameterGroupHandle ){
Collection sList = Collections.EMPTY_LIST;
if ( parameterHandle.getContainer( ) instanceof
CascadingParameterGroupHandle )
{

String groupName = parameterHandle.getContainer( ).getName( );
//used for Cascading parms see IGetParameterDefinitionTask.java
code for comments
//task.evaluateQuery( groupName );

//Need to load this for calls to get next level.
//This just gets the first level
Object [] keyValueTmp = new Object[1];
sList = task.getSelectionListForCascadingGroup( groupName,
keyValueTmp );


for ( Iterator sl = sList.iterator( ); sl.hasNext( ); )
{
IParameterSelectionChoice sI = (IParameterSelectionChoice) sl.next( );


Object value = sI.getValue( );
Object label = sI.getLabel( );
System.out.println( label + "--" + value);

}

}
}else{
Collection selectionList = task.getSelectionList( scalar.getName() );

if ( selectionList != null )
{
HashMap dynamicList = new HashMap();

for ( Iterator sliter = selectionList.iterator( ); sliter.hasNext( ); )
{
IParameterSelectionChoice selectionItem =
(IParameterSelectionChoice) sliter.next( );

Object value = selectionItem.getValue( );
String label = selectionItem.getLabel( );

//System.out.println( label + "--" + value);
//Display label unless null then display value. Value is the what
should get passed to the report.
dynamicList.put(value,label);

}
parameter.put("Selection List", dynamicList);
}
}

}



Iterator iter = parameter.keySet().iterator();
System.out.println("======================Parameter =" +
scalar.getName());
while (iter.hasNext()) {
String name = (String) iter.next();
if( name.equals("Selection List")){
HashMap selList = (HashMap)parameter.get(name);
Iterator selIter = selList.keySet().iterator();
while (selIter.hasNext()) {
Object lbl = selIter.next();
System.out.println( "Selection List Entry ===== Key = " + lbl + "
Value = " + selList.get(lbl));
}

}else{
System.out.println( name + " = " + parameter.get(name));
}
}
return parameter;

}


public static void main(String[] args) {
try
{
executeReport( );
}
catch ( Exception e )
{
e.printStackTrace();
}
}

}


Jason

On 10/12/2011 11:30 AM, Alexey Romanov wrote:
> Reusable library for reloading a report sample shows how to access
> parameters and their values from the recordContext variable. Is it
> possible to get all possible values for dynamic parameters as well?
Re: Can I get all possible values of dynamic parameter from RE? [message #735791 is a reply to message #735773] Wed, 12 October 2011 17:54 Go to previous messageGo to next message
Alexey Romanov is currently offline Alexey RomanovFriend
Messages: 263
Registered: May 2010
Senior Member
Excellent, thanks for the help again!
Re: Can I get all possible values of dynamic parameter from RE? [message #735799 is a reply to message #735791] Wed, 12 October 2011 18:18 Go to previous message
Alexey Romanov is currently offline Alexey RomanovFriend
Messages: 263
Registered: May 2010
Senior Member
And it looks like I can do it from from ReportItemPresentationBase.init, just where I'd want it for my idea (and least extra work for report writers).

@Override
public void init(IReportItemPresentationInfo info) {
  super.init(info);
  IReportRunnable design = context.getReportRunnable();
  IReportEngine engine = design.getReportEngine();
  ...
}

Now I "just" need to check that it actually works Smile
Previous Topic:Get Parameter Display Text
Next Topic:Grails and Birt - Connection Not Active
Goto Forum:
  


Current Time: Thu Nov 27 11:54:05 GMT 2014

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

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