Home » Archived » BIRT » Combo missing, dynamic list box is empty
|
Re: Combo missing, dynamic list box is empty [message #631470 is a reply to message #631332] |
Thu, 07 October 2010 15:20 |
|
This should work. Can you try this code:
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.IGetParameterDefinitionTa sk;
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.CascadingParameterGroupHan dle;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.ScalarParameterHandle;
public class ReportParameters {
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\\ReportEngi ne ");
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/parameters.rptdesign");
IReportRunnable design =
engine.openReportDesign("reports/combobox.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( ) );
// 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;
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;
}
/**
* @param args
*/
public static void main(String[] args) {
try
{
executeReport( );
}
catch ( Exception e )
{
e.printStackTrace();
}
}
}
Jason
On 10/7/2010 2:42 AM, Dave wrote:
> Hello,
>
> 1. Combox can be selected in eclipse design, but it is not defined in
> report parameter API.
>
> 2. List Box, dynamic using data set. IGetParameterDefinitionTask task=..
> task.getSelectionList(parameterName) returns empty list.
>
> It worked in eclipse preview.
> Do I need to explicitly retrieve the selection list from data set?
>
> Thanks,
> Dave
>
|
|
| |
Re: Combo missing, dynamic list box is empty [message #714697 is a reply to message #714679] |
Thu, 11 August 2011 09:49 |
Johannes.Koshy Messages: 30 Registered: July 2011 |
Member |
|
|
Hokay, i did a mistake ^^, but another question,
how would i Set this Parameter again?
IRunAndRenderTasks setParameterValue(name, value)
does Overwrite the hole List of Options, so when i run the report again, the above clause
would only contain value(The one which was Selected in my Application);
I would assume, that i have to pass the whole options again, but how do i tell Birt
wich ones/one has been selected?
|
|
|
Re: Combo missing, dynamic list box is empty [message #714869 is a reply to message #714697] |
Thu, 11 August 2011 15:07 |
|
The IGetParameterDefinitionTask is used to build your own parameter
selection interface. It does not set values for a run or runandrender
task. For that you need task.setParameterValue or
task.setParameterValues. If you are setting a multi-select value
parameter you can do it like the following. Suppose I have a Integer
parameter and the user has selected three values
Integer parmvals[] = new Integer[3];
parmvals[0]=10104;
parmvals[0]=10105;
parmvals[1]=10106;
task.setParameterValue("param1", parmvals);
Jason
On 8/11/2011 5:49 AM, Johannes.Koshy wrote:
> Hokay, i did a mistake ^^, but another question,
> how would i Set this Parameter again?
> IRunAndRenderTasks setParameterValue(name, value)
> does Overwrite the hole List of Options, so when i run the report again,
> the above clause
> would only contain value(The one which was Selected in my Application);
> I would assume, that i have to pass the whole options again, but how do
> i tell Birt
> wich ones/one has been selected?
>
|
|
|
Re: Combo missing, dynamic list box is empty [message #715017 is a reply to message #714869] |
Fri, 12 August 2011 05:30 |
Johannes.Koshy Messages: 30 Registered: July 2011 |
Member |
|
|
Thats exactly what iam doing :/
the Problem is, when i retrieve the Parameters again
like i did before to get and show all possible values,
the selected ones are the ones i get back, not all as before.
In code:
I Get all Possibilites from the Report via.
IGetParameterDefinitionTask pTask=...
....
if(controlType==ScalarParameterDefn.LIST_BOX){
Collection<IParameterSelectionChoice > col = pTask.getSelectionList(ipd.getName());
val=new Object[col.size()+1];
int i=1;
((Object[])val)[0]=ipd.getDefaultValue();
for(IParameterSelectionChoice object:col){
((Object[])val)[i]=object.getValue();
i++;
}
parameters.put(
new String[] { "" + 99, ipd.getName(),
ipd.getHelpText() },(Object[]) val);
Now this is how i set the Parameter:
private boolean setParameters(IRunAndRenderTask task) {
for (Entry<String[], Object[]> entry : this.parameters.entrySet()) {
Object[] entryVal=entry.getValue();
if(Integer.parseInt(entry.getKey()[0])==SupportetParameterTypes.MULTIPLE_SELECTION_STRING_LIST){
task.setParameterValue(entry.getKey()[1], entryVal);
}else{
Object value = entryVal[0];
task.setParameterValue(entry.getKey()[1], value);
}
}
return false;
}
Where as the Value is the Selected Value, an Object[] when Multiple Selections are allowed, or just the selected Object.
But when i now repeat the first part, and retrieve the Parameters Again, be it a Multi Selection List or single,
i only returns the Selected Values, as Possibilities.
Is this Intended and i shouldnt retrieve them again, but hold on to them?
|
|
|
Re: Combo missing, dynamic list box is empty [message #715174 is a reply to message #715017] |
Fri, 12 August 2011 15:27 |
|
Can you try to close pTask and and create new task to retrieve them again?
Jason
On 8/12/2011 1:30 AM, Johannes.Koshy wrote:
> Thats exactly what iam doing :/
> the Problem is, when i retrieve the Parameters again
> like i did before to get and show all possible values, the selected ones
> are the ones i get back, not all as before.
> In code:
> I Get all Possibilites from the Report via.
> IGetParameterDefinitionTask pTask=...
> ....
> if(controlType==ScalarParameterDefn.LIST_BOX){
>
> Collection<IParameterSelectionChoice > col =
> pTask.getSelectionList(ipd.getName());
>
> val=new Object[col.size()+1];
> int i=1;
> ((Object[])val)[0]=ipd.getDefaultValue();
> for(IParameterSelectionChoice object:col){
> ((Object[])val)[i]=object.getValue();
> i++;
> }
> parameters.put(
> new String[] { "" + 99, ipd.getName(),
> ipd.getHelpText() },(Object[]) val);
>
> Now this is how i set the Parameter:
> private boolean setParameters(IRunAndRenderTask task) {
> for (Entry<String[], Object[]> entry : this.parameters.entrySet()) {
> Object[] entryVal=entry.getValue();
> if(Integer.parseInt(entry.getKey()[0])==SupportetParameterTypes.MULTIPLE_SELECTION_STRING_LIST){
>
> task.setParameterValue(entry.getKey()[1], entryVal);
> }else{
> Object value = entryVal[0];
> task.setParameterValue(entry.getKey()[1], value);
>
> }
>
> }
> return false;
> }
> Where as the Value is the Selected Value, an Object[] when Multiple
> Selections are allowed, or just the selected Object.
>
> But when i now repeat the first part, and retrieve the Parameters Again,
> be it a Multi Selection List or single,
> i only returns the Selected Values, as Possibilities.
>
> Is this Intended and i shouldnt retrieve them again, but hold on to them?
>
>
|
|
| |
Re: Combo missing, dynamic list box is empty [message #715806 is a reply to message #715677] |
Mon, 15 August 2011 15:37 |
|
Are you closing the task? I can reproduce the issue. I tried creating
two task off the same design and got the complete list both times. Can
you write a simple command line class that shows the issue?
Jason
On 8/15/2011 3:11 AM, Johannes.Koshy wrote:
> I already do create a new pTask everytime i retrieve the parameters:
> private void getParameters() {
> parameters = new HashMap<String[], Object[]>();
> hasRequiredAndUnsetParameter = false;
>
> IGetParameterDefinitionTask pTask = engine
> .createGetParameterDefinitionTask(design);
> Collection<?> params = pTask.getParameterDefns(false);
> ...
> Sry for not replying earlier, but i didnt want my work to intrude my
> weekend ^^, thank you
|
|
|
Re: Combo missing, dynamic list box is empty [message #715947 is a reply to message #715806] |
Tue, 16 August 2011 05:16 |
Johannes.Koshy Messages: 30 Registered: July 2011 |
Member |
|
|
This is the Class Controling the Report, i hope this does suffice.
if not i will try to reproduce the issue in an minimalistic version.
protected EngineConfig config = new EngineConfig();
protected RootSection view;
protected IReportRunnable design = null;
protected IReportEngine engine = null;
private boolean hasRequiredAndUnsetParameter;
private boolean hasParams;
protected HashMap<String[], Object[]> parameters;
private String reportPath;
/**
* Report Specific Logic
*/
private ReportStrategy reportStrategy;
/**
* Constructor for the BirtReportControler.
* @param view Gets initialized in the View, hence its passing.
*/
public BirtReportControler(RootSection view) {
super();
this.view = view;
this.view.setBrcExportSelected(new ReportExportListener());
this.view.setBrcParameterChanged(new ParameterSetListener());
this.view.setBrcReportSelected(new ReportPathListener());
}
/**
* Exports the currently loaded Report Design to a specified format and
* path.
*
* @param format
* Format the Report should be exported to. For now "pdf", "html"
* and "ppt" are supported.
* @param path
* Path/File the the Report should be exported to.
* @return was the Export successful.
*/
public boolean export(String format, String path) {
if (engine == null || design == null) {
return false;
}
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
IRenderOption option = null;
if (format.equalsIgnoreCase("ppt")) {
option = new RenderOption();
} else if (format.equalsIgnoreCase("pdf")) {
option = new PDFRenderOption();
} else if (format.equalsIgnoreCase("html")) {
option = new HTMLRenderOption();
((HTMLRenderOption) option).setEnableAgentStyleEngine(true);
} else {
task.close();
return false;
}
option.setOutputFormat(format);
option.setOutputFileName(path);
task.setRenderOption(option);
try {
task.run();
} catch (EngineException e) {
// TODO Auto-generated catch block
e.printStackTrace();
task.close();
return false;
}
task.close();
return true;
}
/**
* Initializes the Report Engine, opens the Report Design and
* creates the Reports Strategy by its name.
* @see IReportRunnable
* @see IReportEngine
*/
private void init() throws ExtendedElementException {
IReportEngineFactory factory = (IReportEngineFactory) org.eclipse.birt.core.framework.Platform
.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
engine = factory.createReportEngine(config);
try {
design = engine.openReportDesign(reportPath);
if (design.getProperty(design.TITLE) != null
&& design.getProperty(design.TITLE).equals("Monitor")) {
reportStrategy = new MonitoringReportStrategy(view, config);
System.out.println("MonitoringReportStrategy");
}else if(design.getProperty(design.TITLE) != null
&& design.getProperty(design.TITLE).equals("PieResources")){
reportStrategy= new PieChartMonitoringStrategy(view, config);
System.out.println("PieChartStrategy");
}else {
reportStrategy = new DefaultReportStrategy();
System.out.println("DefaultStrategy");
}
} catch (EngineException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* Extracts the Parameters of the report and determines whether the Report
* has Required but unset parameters.
*/
private void getParameters() {
parameters = new HashMap<String[], Object[]>();
hasRequiredAndUnsetParameter = false;
IGetParameterDefinitionTask pTask = engine
.createGetParameterDefinitionTask(design);
Collection<?> params = pTask.getParameterDefns(false);
hasParams = !params.isEmpty();
if (hasParams) {
Iterator<?> iter = params.iterator();
while (iter.hasNext()) {
ScalarParameterDefn ipd = (ScalarParameterDefn) iter.next();
// To Set Hidden Parameters will be the responsibility of the
// Strategy
if (!ipd.isHidden()) {
int type = ipd.getDataType();
int controlType = ipd.getControlType();
Object val = null;
if (controlType == ScalarParameterDefn.LIST_BOX) {
@SuppressWarnings("unchecked")
Collection<IParameterSelectionChoice> col = pTask
.getSelectionList(ipd.getName());
val = new Object[col.size() + 1];
int i = 1;
((Object[]) val)[0] = ipd.getDefaultValue();
for (IParameterSelectionChoice object : col) {
((Object[]) val)[i] = object.getValue();
i++;
}
parameters.put(new String[] { "" + 99, ipd.getName(),
ipd.getHelpText() }, (Object[]) val);
} else {
val = pTask.getDefaultValue(ipd);
parameters.put(new String[] { "" + type, ipd.getName(),
ipd.getHelpText() }, new Object[] { val });
}
boolean isRequired = ipd.isRequired() && val == null;
hasRequiredAndUnsetParameter = hasRequiredAndUnsetParameter
|| isRequired;
}
}
}
pTask.close();
}
/**
* Sets the Report Parameters for the current IRundAndRenderTask.
* @param task IRunAndRenderTask the Parameter should be set for.
*/
private void setParameters(IRunAndRenderTask task) {
for (Entry<String[], Object[]> entry : this.parameters.entrySet()) {
Object[] entryVal = entry.getValue();
if (Integer.parseInt(entry.getKey()[0]) == SupportetParameterTypes.MULTIPLE_SELECTION_STRING_LIST) {
task.setParameterValue(entry.getKey()[1], entryVal);
} else {
Object value = entryVal[0];
task.setParameterValue(entry.getKey()[1], value);
}
}
}
/**
* Runs and Renders the Report, after setting the Parameters to the saved values,
* to html and passes it to the view.
*/
private void compileReport() {
try {
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
if (hasParams)
setParameters(task);
HTMLRenderOption options = new HTMLRenderOption();
options.setSupportedImageFormats("JPG;PNG;BMP");
options.setEnableAgentStyleEngine(true);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
options.setOutputStream(bos);
options.setOutputFormat("html");
task.setRenderOption(options);
task.run();
task.close();
String html = bos.toString();
// Appending of an Function Definition and a Function Call of
// dispatchToJava to the header, for the BrowserFunction to work
// properly.
String[] splitted = html.split("</head>");
String command = "<script language=\"JavaScript\">\n"
+ "function ShowEventData(arguments) {\n"
+ "try{alert(arguments);\n"
+ "dispatchToJava(arguments);\n"
+ "}catch(e){\n"
+ "alert(\"The following error occurred: \" + e.name + \" - \" + e.message);\n"
+ "return;\n}" + "}\n" + "</script>\n";
html = splitted[0].concat(command.concat("</head>"
.concat(splitted[1])));
view.showReport(html, design.getReportName());
new JavaScriptEventObserver(view.getBrowser(), "dispatchToJava");
} catch (EngineException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* Listener to the Selection Event, signaling the change of directly
* changeable Report Parameters.
*/
class ParameterSetListener implements SelectionListener {
@Override
public void widgetSelected(SelectionEvent e) {
parameters = view.getParameters();
view.showParameters(parameters, hasRequiredAndUnsetParameter);
compileReport();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
}
/**
* Listener to the selection of an Report Path.
*/
class ReportPathListener implements SelectionListener {
@Override
public void widgetSelected(SelectionEvent e) {
reportPath = view.getPath();
try {
init();
} catch (ExtendedElementException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
getParameters();
if (hasRequiredAndUnsetParameter) {
view.showParameters(parameters,
hasRequiredAndUnsetParameter);
} else {
if (hasParams)
view.showParameters(parameters,
hasRequiredAndUnsetParameter);
else
view.showReportWithoutParameters();
// Has None or are set with default values;
compileReport();
}
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
}
/**
* Listens to the selection of the option to export the report.
*
*/
class ReportExportListener implements SelectionListener {
@Override
public void widgetSelected(SelectionEvent e) {
export(view.getExportFormat(), view.getExportPath());
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
}
/**
* BrowserFunction to replace the JavaScript function call "dispatchToJava"
* a Report should call to inform Java of an Event, given by the EventID.
* The Event is then passed to the Reports Strategy to let it Handle its
* Java sided behavior.
*
* @see BrowserFunction
* @see ReportEvents
*
*/
class JavaScriptEventObserver extends BrowserFunction {
public JavaScriptEventObserver(Browser browser, String name) {
super(browser, name);
}
public Object function(Object[] arguments) {
// ShowEventData(Event ID, Report Item,...)
try {
int evt = ((Double) arguments[0]).intValue();
reportStrategy.update(evt, design, arguments);
} catch (Exception e) {
e.printStackTrace();
}
compileReport();
return true;
}
}
}
|
|
|
Re: Combo missing, dynamic list box is empty [message #716180 is a reply to message #715947] |
Tue, 16 August 2011 15:46 |
|
Johannes,
Can you try the attached class and report?
Jason
On 8/16/2011 1:16 AM, Johannes.Koshy wrote:
> protected EngineConfig config = new EngineConfig();
> protected RootSection view;
> protected IReportRunnable design = null;
> protected IReportEngine engine = null;
>
> private boolean hasRequiredAndUnsetParameter;
> private boolean hasParams;
>
> protected HashMap<String[], Object[]> parameters;
>
> private String reportPath;
>
> /**
> * Report Specific Logic
> */
> private ReportStrategy reportStrategy;
>
> /**
> * Constructor for the BirtReportControler.
> * @param view Gets initialized in the View, hence its passing.
> */
> public BirtReportControler(RootSection view) {
> super();
>
> this.view = view;
> this.view.setBrcExportSelected(new ReportExportListener());
> this.view.setBrcParameterChanged(new ParameterSetListener());
> this.view.setBrcReportSelected(new ReportPathListener());
>
> }
>
> /**
> * Exports the currently loaded Report Design to a specified format
> and
> * path.
> * * @param format
> * Format the Report should be exported to. For now
> "pdf", "html"
> * and "ppt" are supported.
> * @param path
> * Path/File the the Report should be exported to.
> * @return was the Export successful.
> */
> public boolean export(String format, String path) {
> if (engine == null || design == null) {
> return false;
> }
> IRunAndRenderTask task = engine.createRunAndRenderTask(design);
>
> IRenderOption option = null;
> if (format.equalsIgnoreCase("ppt")) {
> option = new RenderOption();
> } else if (format.equalsIgnoreCase("pdf")) {
> option = new PDFRenderOption();
> } else if (format.equalsIgnoreCase("html")) {
> option = new HTMLRenderOption();
> ((HTMLRenderOption) option).setEnableAgentStyleEngine(true);
> } else {
> task.close();
> return false;
> }
> option.setOutputFormat(format);
> option.setOutputFileName(path);
> task.setRenderOption(option);
> try {
> task.run();
> } catch (EngineException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> task.close();
> return false;
> }
> task.close();
> return true;
> }
>
> /**
> * Initializes the Report Engine, opens the Report Design and
> * creates the Reports Strategy by its name.
> * @see IReportRunnable
> * @see IReportEngine */
> private void init() throws ExtendedElementException {
> IReportEngineFactory factory = (IReportEngineFactory)
> org.eclipse.birt.core.framework.Platform
>
> .createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
> engine = factory.createReportEngine(config);
> try {
> design = engine.openReportDesign(reportPath);
> if (design.getProperty(design.TITLE) != null
> && design.getProperty(design.TITLE).equals("Monitor")) {
> reportStrategy = new MonitoringReportStrategy(view,
> config);
> System.out.println("MonitoringReportStrategy");
> }else if(design.getProperty(design.TITLE) != null
> && design.getProperty(design.TITLE).equals("PieResources")){
>
> reportStrategy= new PieChartMonitoringStrategy(view,
> config);
> System.out.println("PieChartStrategy");
> }else {
> reportStrategy = new DefaultReportStrategy();
> System.out.println("DefaultStrategy");
> }
> } catch (EngineException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
>
> }
>
> /**
> * Extracts the Parameters of the report and determines whether the
> Report
> * has Required but unset parameters.
> */
> private void getParameters() {
> parameters = new HashMap<String[], Object[]>();
> hasRequiredAndUnsetParameter = false;
>
> IGetParameterDefinitionTask pTask = engine
> .createGetParameterDefinitionTask(design);
> Collection<?> params = pTask.getParameterDefns(false);
>
> hasParams = !params.isEmpty();
> if (hasParams) {
> Iterator<?> iter = params.iterator();
> while (iter.hasNext()) {
>
> ScalarParameterDefn ipd = (ScalarParameterDefn)
> iter.next();
> // To Set Hidden Parameters will be the responsibility
> of the
> // Strategy
> if (!ipd.isHidden()) {
> int type = ipd.getDataType();
> int controlType = ipd.getControlType();
> Object val = null;
>
> if (controlType == ScalarParameterDefn.LIST_BOX) {
>
> @SuppressWarnings("unchecked")
> Collection<IParameterSelectionChoice> col = pTask
> .getSelectionList(ipd.getName());
>
> val = new Object[col.size() + 1];
> int i = 1;
> ((Object[]) val)[0] = ipd.getDefaultValue();
> for (IParameterSelectionChoice object : col) {
> ((Object[]) val)[i] = object.getValue();
> i++;
> }
> parameters.put(new String[] { "" + 99,
> ipd.getName(),
> ipd.getHelpText() }, (Object[]) val);
>
> } else {
> val = pTask.getDefaultValue(ipd);
> parameters.put(new String[] { "" + type,
> ipd.getName(),
> ipd.getHelpText() }, new Object[] { val
> });
>
> }
>
> boolean isRequired = ipd.isRequired() && val == null;
> hasRequiredAndUnsetParameter =
> hasRequiredAndUnsetParameter
> || isRequired;
>
> }
> }
>
> }
>
> pTask.close();
>
> }
> /**
> * Sets the Report Parameters for the current IRundAndRenderTask.
> * @param task IRunAndRenderTask the Parameter should be set for.
> */
> private void setParameters(IRunAndRenderTask task) {
> for (Entry<String[], Object[]> entry :
> this.parameters.entrySet()) {
> Object[] entryVal = entry.getValue();
> if (Integer.parseInt(entry.getKey()[0]) ==
> SupportetParameterTypes.MULTIPLE_SELECTION_STRING_LIST) {
> task.setParameterValue(entry.getKey()[1], entryVal);
> } else {
> Object value = entryVal[0];
> task.setParameterValue(entry.getKey()[1], value);
>
> }
>
> }
> }
>
> /**
> * Runs and Renders the Report, after setting the Parameters to the
> saved values,
> * to html and passes it to the view.
> */
> private void compileReport() {
> try {
>
> IRunAndRenderTask task =
> engine.createRunAndRenderTask(design);
> if (hasParams)
> setParameters(task);
>
> HTMLRenderOption options = new HTMLRenderOption();
> options.setSupportedImageFormats("JPG;PNG;BMP");
> options.setEnableAgentStyleEngine(true);
>
> ByteArrayOutputStream bos = new ByteArrayOutputStream();
> options.setOutputStream(bos);
> options.setOutputFormat("html");
>
> task.setRenderOption(options);
>
> task.run();
> task.close();
> String html = bos.toString();
> // Appending of an Function Definition and a Function Call of
> // dispatchToJava to the header, for the BrowserFunction to
> work
> // properly.
> String[] splitted = html.split("</head>");
> String command = "<script language=\"JavaScript\">\n"
> + "function ShowEventData(arguments) {\n"
> + "try{alert(arguments);\n"
> + "dispatchToJava(arguments);\n"
> + "}catch(e){\n"
> + "alert(\"The following error occurred: \" +
> e.name + \" - \" + e.message);\n"
> + "return;\n}" + "}\n" + "</script>\n";
>
> html = splitted[0].concat(command.concat("</head>"
> .concat(splitted[1])));
> view.showReport(html, design.getReportName());
>
> new JavaScriptEventObserver(view.getBrowser(),
> "dispatchToJava");
>
> } catch (EngineException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> }
>
> /**
> * Listener to the Selection Event, signaling the change of directly
> * changeable Report Parameters.
> */
> class ParameterSetListener implements SelectionListener {
>
> @Override
> public void widgetSelected(SelectionEvent e) {
> parameters = view.getParameters();
> view.showParameters(parameters, hasRequiredAndUnsetParameter);
> compileReport();
> }
>
> @Override
> public void widgetDefaultSelected(SelectionEvent e) {
>
> }
>
> }
>
> /**
> * Listener to the selection of an Report Path.
> */
> class ReportPathListener implements SelectionListener {
>
> @Override
> public void widgetSelected(SelectionEvent e) {
> reportPath = view.getPath();
> try {
> init();
> } catch (ExtendedElementException e1) {
> // TODO Auto-generated catch block
> e1.printStackTrace();
> }
> getParameters();
>
> if (hasRequiredAndUnsetParameter) {
> view.showParameters(parameters,
> hasRequiredAndUnsetParameter);
> } else {
> if (hasParams)
> view.showParameters(parameters,
> hasRequiredAndUnsetParameter);
> else
> view.showReportWithoutParameters();
>
> // Has None or are set with default values;
> compileReport();
> }
> }
>
> @Override
> public void widgetDefaultSelected(SelectionEvent e) {
>
> }
>
> }
>
> /**
> * Listens to the selection of the option to export the report.
> * */
> class ReportExportListener implements SelectionListener {
>
> @Override
> public void widgetSelected(SelectionEvent e) {
>
> export(view.getExportFormat(), view.getExportPath());
>
> }
>
> @Override
> public void widgetDefaultSelected(SelectionEvent e) {
>
> }
>
> }
>
> /**
> * BrowserFunction to replace the JavaScript function call
> "dispatchToJava"
> * a Report should call to inform Java of an Event, given by the
> EventID.
> * The Event is then passed to the Reports Strategy to let it
> Handle its
> * Java sided behavior.
> * * @see BrowserFunction
> * @see ReportEvents
> * */
> class JavaScriptEventObserver extends BrowserFunction {
>
> public JavaScriptEventObserver(Browser browser, String name) {
> super(browser, name);
>
> }
>
> public Object function(Object[] arguments) {
> // ShowEventData(Event ID, Report Item,...)
> try {
> int evt = ((Double) arguments[0]).intValue();
> reportStrategy.update(evt, design, arguments);
> } catch (Exception e) {
> e.printStackTrace();
> }
> compileReport();
> return true;
> }
> }
>
> }
|
|
| |
Re: Combo missing, dynamic list box is empty [message #716502 is a reply to message #716335] |
Wed, 17 August 2011 14:54 |
|
I modified the code to put a runandrender task between the two parameter
task lists. Is this similar to what you are doing?
Jason
On 8/17/2011 1:30 AM, Johannes.Koshy wrote:
> Your attached Example does work, though my Case is somewhat different:
> 1. retrieve the parameters options
>
> 2. show user the parameter options
>
> 3. set the selection of the user to the parameter.
>
> My hunch now is, that the parameter does not remember unselected
> Options, but
> instead the parameter itself is all options selected? I mean do the
> Options of the parameter have a state like selected/not selected ? Or
> are the values of the parameter all selections?
package REAPI;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
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.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.IGetParameterDefinitionTask;
import org.eclipse.birt.report.engine.api.IPDFRenderOption;
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.IRunAndRenderTask;
import org.eclipse.birt.report.engine.api.IScalarParameterDefn;
import org.eclipse.birt.report.engine.api.PDFRenderOption;
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 ReportParameters {
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.getSelectionListForCascadingGroup();
Iterator iter = params.iterator( );
while ( iter.hasNext( ) )
{
IParameterDefnBase param = (IParameterDefnBase) iter.next( );
IScalarParameterDefn scalar = (IScalarParameterDefn) param;
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( );
System.out.println( value);
}
}
}
task.close();
IRunAndRenderTask rtask = engine.createRunAndRenderTask(design);
Integer parmvals[] = new Integer[2];
parmvals[0]=10101;
parmvals[1]=10102;
rtask.setParameterValue("listparm", parmvals);;
// task.validateParameters();
HTMLRenderOption options = new HTMLRenderOption();
options.setOutputFormat("HTML");
options.setOutputFileName("output/resample/testparmlist.htm");
rtask.setRenderOption(options);
rtask.run();
rtask.close();
task = engine.createGetParameterDefinitionTask( design );
params = task.getParameterDefns( true );
//task.getSelectionListForCascadingGroup();
iter = params.iterator( );
while ( iter.hasNext( ) )
{
IParameterDefnBase param = (IParameterDefnBase) iter.next( );
IScalarParameterDefn scalar = (IScalarParameterDefn) param;
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( );
System.out.println( value);
}
}
}
task.close();
engine.destroy();
Platform.shutdown();
}
public static void main(String[] args) {
try
{
executeReport( );
System.exit(0);
}
catch ( Exception e )
{
e.printStackTrace();
}
}
}
|
|
| | |
Goto Forum:
Current Time: Sat Apr 27 16:48:36 GMT 2024
Powered by FUDForum. Page generated in 0.04512 seconds
|