RSS

Search Engine

Sunday, August 22, 2010

Deploying in Eclipse RCP application

9.1. BIRT deploying to an RCP Application

We can use the Birtviewer also in a local RCP Application, it isn't more than an browser view which shows a HTML Page generated by an integrated Webserver.

The following assumes that you are already familiar with Eclipse RCP development. See Eclipse RCP Tutorials in case you need an introduction.

Convert "sawan.modi.birt.stocks" to a plugin project, via right mouse click -> Configure -> "Convert to plug-in project".

Create an new plugin project "sawan.modi.birt.stocks.rcp". Select the template "RCP Application with a view".

Add the following plugins as dependendies to "sawan.modi.birt.stocks.rcp".

    
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Rcp
Bundle-SymbolicName: sawan.modi.birt.stocks.rcp; singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: sawan.modi.birt.stocks.rcp.Activator
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.birt.report.viewer;bundle-version="2.5.0",
org.eclipse.birt.report.engine.emitter.html;bundle-version="2.5.0",
sawan.modi.birt.stocks;bundle-version="1.0.0",
org.eclipse.birt;bundle-version="2.5.0",
org.eclipse.birt.chart.ui;bundle-version="2.5.0",
org.eclipse.birt.chart.cshelp;bundle-version="2.5.0",
org.eclipse.birt.chart.device.extension;bundle-version="2.5.0",
org.eclipse.birt.chart.device.pdf;bundle-version="2.5.0",
org.eclipse.birt.chart.device.svg;bundle-version="2.5.0",
org.eclipse.birt.chart.device.swt;bundle-version="2.5.0",
org.eclipse.birt.chart.engine.extension;bundle-version="2.5.0",
org.eclipse.birt.chart.examples;bundle-version="2.5.0",
org.eclipse.birt.chart.reportitem;bundle-version="2.5.0",
org.eclipse.birt.chart.reportitem.ui;bundle-version="2.5.0",
org.eclipse.birt.chart.ui.extension;bundle-version="2.5.0",
org.eclipse.birt.core.script.function;bundle-version="2.5.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6

Copy your report to "stock_report_rcp.rptdesign" into this new project. Open this report and change the "open" JavaScript to the following.

    
count = 0;
/*
* load and init data reader
* import Platform from org.eclipse.core.runtime
*/
importPackage(Packages.org.eclipse.core.runtime);

/* load bundle with POJOs and data loading class */

myBundle = Platform.getBundle("sawan.modi.birt.stocks");

/* load data reader class */
readerClass = myBundle.loadClass("sawan.modi.birt.stocks.daomock.StockDaoMock");

/* create new instance of DataReader */
readerInstance = readerClass.newInstance();


/* read data */
stock = readerInstance.getStockValues("Java");



Use this code as View.java.

    
package sawan.modi.birt.stocks.rcp;

import java.net.MalformedURLException;
import java.net.URL;

import org.eclipse.birt.report.viewer.utilities.WebViewer;
import org.eclipse.core.runtime.Platform;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;
import org.osgi.framework.Bundle;

public class View extends ViewPart {
public static final String ID = "sawan.modi.birt.stocks.rcp.view";

public void createPartControl(Composite parent) {
String path = "";

try {
Bundle bundle = Platform.getBundle("sawan.modi.birt.stocks.rcp");
path = new URL(bundle.getLocation()).getPath();
path = path .substring(6); //"file:/" 0 bis 5
path = path .replace("/", "\\");
path = path + "stock_report_rcp.rptdesign";
}
catch (MalformedURLException me){
System.out.println(me.getStackTrace());
}

Browser browser = new Browser(parent, SWT.NONE);
// Use the filename of your report
WebViewer.display(path, WebViewer.HTML, browser, "frameset"); }

/**
* Passing the focus request to the viewer's control.
*/
public void setFocus() {
}
}

0 comments:

Post a Comment