Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

RCP Example (BIRT) 2.1

< 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());
          config.setAppContext(hm); 

Setup

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.

Example.jpg

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.display(reportName, 
//                  WebViewer.HTML, 
//                  browser, 
//                  "frameset");
//option 4 display in SWT Browser
// using /run mapping.
//WebViewer.display(reportName, 
//                  WebViewer.HTML, 
//                  browser,
//                  "run");

Download Examples

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
Look at the org.eclipse.birt.examples.rcpviewer example in the download. Product Configuration file: Viewer Product Configuration File
Example of using the Report Engine in an RCP application. BIRT RCP Engine
Look at the org.eclipse.birt.examples.rcpengine example in the download.

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
//reportContext.getAppContext().get("MyObject");

/* use a class similar to the following:
package org.eclipse.birt.examples.rcpviewer;
import java.util.Map;
import org.eclipse.birt.report.viewer.api.AppContextExtension;
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
 <extension
      point="org.eclipse.birt.report.viewer.appcontext">
      <appcontext
            class="org.eclipse.birt.examples.rcpviewer.MyAppContext">
      </appcontext>
 </extension>
*/
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.startup();
//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.startup();
//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
//WebViewer.startup();
//String myurl = "http://" + WebappAccessor.getHost( ) + ":" 
//+ WebappAccessor.getPort( "viewer" )
//+ "/viewer/";
//browser.setUrl(myurl);

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. --Vdodson.actuate.com 12:36, 8 June 2007 (EDT)


Comments

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

  Cannot nest 'C:[...]/eclipse/plugins/org.eclipse.birt.report.viewer_2.3.2.r232_20090212/birt/WEB-INF/classes' inside library 
  '[...]/eclipse/plugins/org.eclipse.birt.report.viewer_2.3.2.r232_20090212'

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


Back to the top