Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » Get selection list from IScalarParameterDefn (get list of available options for a list or Combo box)
Get selection list from IScalarParameterDefn [message #768787] Tue, 20 December 2011 19:49 Go to next message
Alessio Pollero is currently offline Alessio PolleroFriend
Messages: 66
Registered: August 2011
Member
I want to get the list of available selection options of a list or combobox, through the runtime API, now i've already implemented a function that extract the selection options from the IScalarParameterDefn interface in this way :


IScalarParameterDefn p = anObject;
Collection selectionList = p.getSelectionList();


The problem is that the getSelectionList() method retrieve all available options only if the options is statically defined at report design time, if instead options are loaded from a dataset i don't get any value ...


Is there a way to retrieve the selection value of a list or combo box ? How ?


Thanks.
Re: Get selection list from IScalarParameterDefn [message #768838 is a reply to message #768787] Tue, 20 December 2011 22:39 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Take a look at this example:

package REAPI;




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.engine.api.ReportEngine;
import org.eclipse.birt.report.model.api.CascadingParameterGroupHandle;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.ScalarParameterHandle;

public class ReportParameterList {

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_6_1\\birt-runtime-2_6_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/parmlist.rptdesign");

IGetParameterDefinitionTask task =
engine.createGetParameterDefinitionTask( design );

Collection params = task.getParameterDefns( true );

//task.getDefaultValue(arg0);


//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( ) );
System.out.println(group.getPromptText());


// 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;
}


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

//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{
//Normal Dynamic List
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;

}

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

}


Jason

On 12/20/2011 2:49 PM, Alessio Pollero wrote:
> I want to get the list of available selection options of a list or
> combobox, through the runtime API, now i've already implemented a
> function that extract the selection options from the
> IScalarParameterDefn interface in this way :
>
> IScalarParameterDefn p = anObject;
> Collection selectionList = p.getSelectionList();
>
> The problem is that the getSelectionList() method retrieve all available
> options only if the options is statically defined at report design time,
> if instead options are loaded from a dataset i don't get any value ...
>
>
> Is there a way to retrieve the selection value of a list or combo box ?
> How ?
>
> Thanks.
Re: Get selection list from IScalarParameterDefn [message #769054 is a reply to message #768838] Wed, 21 December 2011 10:15 Go to previous message
Alessio Pollero is currently offline Alessio PolleroFriend
Messages: 66
Registered: August 2011
Member
Ok, it worked, Thank you.
Previous Topic:Somebody uses the BIRT API to generate a REport
Next Topic:Problem Printing Landscape PDF Reports
Goto Forum:
  


Current Time: Thu Dec 18 13:38:35 GMT 2014

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

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