Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Set Theme in runtime by script?
adrianfcc
I have made two themes in the library for the reports. One colored theme for viewing the report on the screen, and one black and white theme for print out. I use Eclipse BIRT and it's integrated with our own applicatoin.
The colored theme should be the default when users run the report on screen, and I am thinking about to put a link called "Printable Version" on the top right corner of the master page, clicking it will change to b/w theme immediately so the user can print from there. Is there any way to do that? I guess I need some scripting.
Thanks!
Find more posts tagged with
Comments
CBR
Hi,
it s possible to change the theme using a script in the beforeRender eventhandler of your report. (I have done it a few times in the past but can't remember the syntax...let me have a look tomorrow)
I would suggest that you create a report parameter that can be set to a special value. Then you will be able to check the value of that parameter and in dependence of its value reset the theme.
Another option that you might prefer is using the reportContext instead of a report parameter. This option is only available if you run the report using the report engine api directly.
CBR
And a third option if you render your reports using a integrated report engine and not the webviewer might be to implement the beforeRender eventhandler at runtime after the report is loaded using the reportEngine API. Using the API you are able to add RhinoCode for any eventhandler of the report you have currently loaded into memory
CBR
So here it is. But this line of rhino script in the before Render event handler of the report:
reportContext.getReportRunnable().designHandle.getModuleHandle().setThemeName("myLibrary.themeName");
Per convention the string you put in the setThemeName method is the unique name of the theme. So it is library name + . + themename in library.
adrianfcc
Thanks CBR. I believe your script is at the point although I still haven't solved the problem yet.
The library file used by the report is called "PC.rptlibrary", and the theme called "Blue".
First I try the following "beforeRender" of the report:
reportContext.getReportRunnable().designHandle.getModuleHandle().setThemeName("PC.Blue");
I got an exception 'Caused by: org.eclipse.birt.report.model.api.command.ThemeException: The theme "PC.Blue" used by report is not found.'
And then I tried the following in "beforeRender":
t = reportContext.getReportRunnable().designHandle.getModuleHandle().findTheme("PC.Blue");
reportContext.getReportRunnable().designHandle.getModuleHandle().theme=t;
There was no exception but findTheme did not find anything so that "t" is null and the theme did not change.
And then I tried to move the following to "initialize"
t = reportContext.getReportRunnable().designHandle.getModuleHandle().findTheme("PC.Blue");
and leave the following in "beforeRender"
reportContext.getReportRunnable().designHandle.getModuleHandle().theme=t;
Now, it has found "org.eclipse.birt.report.model.api.ThemeHandle@190c6fe" for "t"! However.... the theme still not changed on screen.
** I am also worrying about if the "designHandle" property in script returns something only being used in design time instead of runtime.
Any idea?
CBR
Hi,
is it possible that you send me your library or at last a similar library containing the themes?
Then it would be possible that i send you a working example using your library btw your themes
Which version of BIRT are you using?
adrianfcc
Thanks CBR. I just emailed you the library and the report using it. I found that I am actually using Actuate 10 BIRT, based on BIRT 2.3.2. Thanks for your help!
adrianfcc
First thank CBR's help in identifying the library path problem. In the report's XML source "MyLib.rptlibrary" was actually referencing to the wrong location which should be "../MyLibs/MyLib.rptlibrary".
And then the following lines added to the "initialize" event are now able to choose the theme based on a parameter:
var t;
if (params["PrintableVersion"]){
t = reportContext.getReportRunnable().designHandle.getModuleHandle().findTheme("MyLib.BlackWhite");
}else{
t = reportContext.getReportRunnable().designHandle.getModuleHandle().findTheme("MyLib.Blue");
}
reportContext.getReportRunnable().designHandle.getModuleHandle().theme=t;
Thanks!