Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "RCP Example (BIRT) 2.1"

(RCP Example)
Line 70: Line 70:
 
Example of using the Report Engine in an RCP application.
 
Example of using the Report Engine in an RCP application.
 
[http://download.eclipse.org/birt/downloads/examples/integrating/rcp/rcpengine.zip BIRT RCP Engine]
 
[http://download.eclipse.org/birt/downloads/examples/integrating/rcp/rcpengine.zip 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
 +
//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.startup();
 +
ReloadableClassLoader rcl = (ReloadableClassLoader)WebViewer.getAppClassLoader();
 +
URL[] gg = rcl.getUrls();
 +
URL[] na = new URL[gg.length + 1];
 +
System.arraycopy(gg, 0, na, 0, gg.length);
 +
na[gg.length] = new URL("file://c:/jars/mjo.jar");
 +
rcl.setUrls(na);
 +
*/
 +
//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
  
 
== User Comments ==
 
== User Comments ==

Revision as of 18:35, 16 March 2009

< 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");

Comments

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 //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.startup(); ReloadableClassLoader rcl = (ReloadableClassLoader)WebViewer.getAppClassLoader(); URL[] gg = rcl.getUrls(); URL[] na = new URL[gg.length + 1]; System.arraycopy(gg, 0, na, 0, gg.length); na[gg.length] = new URL("file://c:/jars/mjo.jar"); rcl.setUrls(na); */ //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

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

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


Back to the top