Skip to main content
Jump to: navigation, search

RCP Example (BIRT) 2.1

Revision as of 05:39, 17 March 2009 by (Talk | contribs) (Comments)

< To: Integration Examples (BIRT)

RCP Example

This example explains how to deploy the BIRT Viewer within an RCP application.

Add comments at the bottom of the example.

BIRT Report Engine API Return to the BIRT Report Engine API examples

If using the Report Engine API plugin in an RCP application, add code similar to the following to set the APPCONTEXT_CLASSLOADER_KEY.

          config = new EngineConfig();
          HashMap hm = config.getAppContext();
          hm.put( EngineConstants.APPCONTEXT_CLASSLOADER_KEY, MyClass.class.getClassLoader());


1. Add the BIRT Viewer plug-in to your project dependencies. Runtime dependencies will be determined by what options your reports use. For example if you use a JDBC data source, then the JDBC plug-in will be required at runtime.


2. Call WebViewer.display from your code. Use one of the following options. Note that browser will need to be defined as an org.eclipse.swt.browser.Browser.

Code Snippet

//option 1 display with no parameters in url.  
//Parameter box will display if
//required in a seperate window.  
//This uses the /run mapping
//WebViewer.display(reportName , 
//                  WebViewer.HTML, 
//                  false);	
//option 2 display BIRT Viewer in sepearate 
//Browser with /frameset mapping
//WebViewer.display(reportName , 
//                  WebViewer.HTML, 
//                  true);
//option 3 display in SWT Browser 
//using /frameset mapping.
//                  WebViewer.HTML, 
//                  browser, 
//                  "frameset");
//option 4 display in SWT Browser
// using /run mapping.
//                  WebViewer.HTML, 
//                  browser,
//                  "run");


Please enter comments below by selecting the edit icon to the right. You will need a Bugzilla account to add comments.

Example of using the Report Viewer in an RCP application. BIRT RCP Viewer

Example of using the Report Engine in an RCP application. BIRT RCP Engine

BIRT 2.3.2 Example Using the Viewer plugin

//Most Common WebViwer Options shown below
//Use this code to set your own app context
//Which allows you to set the parent classloader and add to the classpath
//You can also add your own specific variables so reports can access the values like

/* use a class similar to the following:
package org.eclipse.birt.examples.rcpviewer;
import java.util.Map;
public class MyAppContext extends AppContextExtension{
   public Map getAppContext(Map appContext) {
      Map hm = super.getAppContext(appContext);
      hm.put("PARENT_CLASSLOADER", PreviewBirtAction.class.getClassLoader());
      hm.put("webapplication.projectclasspath", "c:/jars/mjo.jar");  
      return hm;			
   public String getName() {
             return "MyAppContext";
 Make sure to add the following to your plugin.xml
ViewerPlugin.getDefault( ).getPluginPreferences( ).setValue("APPCONTEXT_EXTENSION_KEY", "MyAppContext");
 //Use this approach to load report from bundle
 //Bundle bundle = org.eclipse.core.runtime.Platform.getBundle("testdata"); 
 //URL url = FileLocator.find(bundle, new Path("/reports/myreport.rptdesign"), null);
 //String rpt = FileLocator.toFileURL(url).getPath();
 //In all cases where a separate browser window is used the WebViewer Class checks for
 //external browser preference setting
 //boolean useExternal = ViewerPlugin.getDefault( )
 //.getPluginPreferences( )
 //.getBoolean( BrowserManager.ALWAYS_EXTERNAL_BROWSER_KEY );

//option 1 display with no parameters in url.  Parameter box will display if
//required in a seperate window.  This uses the /preview mapping
//WebViewer.display(reportName , WebViewer.PDF);	
//option 2 display BIRT Viewer in sepearate Browser with /frameset mapping
//allow page (third parameter determines if HTLM pagination is allowed)
//true use frameset else use preview mapping
//WebViewer.display(reportName , WebViewer.HTML, true);
//option 3 launch in separate browswer window
//HashMap myparms = new HashMap();
//myparms.put("SERVLET_NAME_KEY", "frameset");
//myparms.put("FORMAT_KEY", "html");
//myparms.put("RESOURCE_FOLDER_KEY", "c:/myresources");
//myparms.put("ALLOW_PAGE", false);
//myparms.put("MAX_ROWS_KEY", "500");			
//WebViewer.display("viewer", reportName , myparms);

//option 4 display in SWT Browser using /frameset mapping.
HashMap myparms = new HashMap();
myparms.put("SERVLET_NAME_KEY", "frameset");
myparms.put("FORMAT_KEY", "html");
//myparms.put("RESOURCE_FOLDER_KEY", "c:/myresources");
//myparms.put("ALLOW_PAGE", false);
//myparms.put("MAX_ROWS_KEY", "500");
WebViewer.display(reportName, browser, myparms);
//option 5 display with parameters encoded in the URL
//Check the source for the viewer plugin to add a createURL function
//Start with this and add the appropriate parameters as defined on the example J2EE Viewer page
//String myurl = "http://" + WebappAccessor.getHost( ) + ":" 
//+ WebappAccessor.getPort( "viewer" )
//+ "/viewer/";

User Comments

This is a great example but it took me a few tries to make it work.

After importing the BIRT RCP Viewer example project, I had to create a new Run Configuration, select the Plug-ins tab, and then press the Select All button. After that, the example ran perfectly. 12:36, 8 June 2007 (EDT)


Hy, I'm not able compile the project. The error log is:

  Cannot nest 'C:[...]/eclipse/plugins/' inside library '[...]/eclipse/plugins/'

Which configuration did you have (jre, eclipse, birt ...)?

Back to the top