Eclipse RCP入门(五)
集成BIRT2.2.2到RCP中
下载BIRT的ALL IN ONE地址:
http://www.eclipse.org/birt/phoenix/
由于BIRT的2.2.2的ALL IN ONE里面可能有些东西不是最新的,
所以导致了下载SVN插件下载不了,经过查询发现是下面这个DTP需要更新,
下载DTP后,就可以下载SVN插件了
Eclipse DTP下载地址:
http://www.eclipse.org/datatools/downloads.php
插件的更新地址:
http://download.eclipse.org/datatools/updates
将BIRT下面的例子test.rptdesign拷贝到我们的项目的template下面
在RCP的按钮下面的方法中加入下面这个调用,这个调用用BIRT的engine来显示报表的模板,调用方法如下:
private void previewReport() throws EngineException {
EngineConfig config = new EngineConfig();
config.setLogConfig("D:/birt/logs", Level.FINE);
// Create the report engine
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
IReportEngine engine = factory.createReportEngine( config );
IReportRunnable design = null;
try {
String report = filePathTxt.getText();
FileInputStream fs = new FileInputStream(report);
design = engine.openReportDesign(fs);
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
//加入数据
task.setParameterValue("sample", "Carl");
//IRenderOption pdfOptions;
//pdfOptions = new PDFRenderOption( );
//pdfOptions.setOutputFormat(PDFRenderOption.OUTPUT_FORMAT_PDF);
//pdfOptions.setOutputFileName("D:/birt/test.pdf");
IRenderOption htmlOptions;
htmlOptions = new HTMLRenderOption( );
ByteArrayOutputStream bos = new ByteArrayOutputStream();
htmlOptions.setOutputStream(bos);
htmlOptions.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_HTML);
task.setRenderOption(pdfOptions);
//task.setRenderOption(htmlOptions);
// run the report and destroy the engine
task.run();
task.close();
//set Browser text accordingly
browser.setText(bos.toString());
engine.destroy();
} catch (Exception e) {
e.printStackTrace();
}
}
方法里面的两个Options貌似只有最后设置的那个才能生效,目前可以选择显示PDF或者HTML中的一种,CSV的正在研究中,还不知道怎么生成。
之所以传递的参数task.setParameterValue("sample", "Carl");报表里面能收到,
报表模板里面必须得有个参数,在
Outline里面的Report Parameters里面有个sample,Data type是String
报表模板的内容里面放置了一个Date Type是Any,Expression是params["sample"]的表达式
上面的操作,就能显示一个简单的报表了,传递了一个简单的参数名字进去。
要让RCP能跑起BIRT的engine,在plugin.xml的Dependencies里面要设置一下,
加入如下包:
org.eclipse.birt.core
org.eclipse.birt.report.engine
com.lowagie.itext 导出PDF用的。嘿嘿。
在sillycatGen.product的Configuration里面要加入如下包:
com.lowagie.itext 导出PDF的
org.eclipse.birt.core
org.eclipse.birt.report.engine
org.eclipse.birt.report.engine.emitter.html
org.eclipse.birt.report.engine.emitter.pdf
最后别忘记点一下:Add Required Plug-ins按钮,应该就可以运行了
集成BIRT2.2.2到RCP中
下载BIRT的ALL IN ONE地址:
http://www.eclipse.org/birt/phoenix/
由于BIRT的2.2.2的ALL IN ONE里面可能有些东西不是最新的,
所以导致了下载SVN插件下载不了,经过查询发现是下面这个DTP需要更新,
下载DTP后,就可以下载SVN插件了
Eclipse DTP下载地址:
http://www.eclipse.org/datatools/downloads.php
插件的更新地址:
http://download.eclipse.org/datatools/updates
将BIRT下面的例子test.rptdesign拷贝到我们的项目的template下面
在RCP的按钮下面的方法中加入下面这个调用,这个调用用BIRT的engine来显示报表的模板,调用方法如下:
private void previewReport() throws EngineException {
EngineConfig config = new EngineConfig();
config.setLogConfig("D:/birt/logs", Level.FINE);
// Create the report engine
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
IReportEngine engine = factory.createReportEngine( config );
IReportRunnable design = null;
try {
String report = filePathTxt.getText();
FileInputStream fs = new FileInputStream(report);
design = engine.openReportDesign(fs);
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
//加入数据
task.setParameterValue("sample", "Carl");
//IRenderOption pdfOptions;
//pdfOptions = new PDFRenderOption( );
//pdfOptions.setOutputFormat(PDFRenderOption.OUTPUT_FORMAT_PDF);
//pdfOptions.setOutputFileName("D:/birt/test.pdf");
IRenderOption htmlOptions;
htmlOptions = new HTMLRenderOption( );
ByteArrayOutputStream bos = new ByteArrayOutputStream();
htmlOptions.setOutputStream(bos);
htmlOptions.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_HTML);
task.setRenderOption(pdfOptions);
//task.setRenderOption(htmlOptions);
// run the report and destroy the engine
task.run();
task.close();
//set Browser text accordingly
browser.setText(bos.toString());
engine.destroy();
} catch (Exception e) {
e.printStackTrace();
}
}
方法里面的两个Options貌似只有最后设置的那个才能生效,目前可以选择显示PDF或者HTML中的一种,CSV的正在研究中,还不知道怎么生成。
之所以传递的参数task.setParameterValue("sample", "Carl");报表里面能收到,
报表模板里面必须得有个参数,在
Outline里面的Report Parameters里面有个sample,Data type是String
报表模板的内容里面放置了一个Date Type是Any,Expression是params["sample"]的表达式
上面的操作,就能显示一个简单的报表了,传递了一个简单的参数名字进去。
要让RCP能跑起BIRT的engine,在plugin.xml的Dependencies里面要设置一下,
加入如下包:
org.eclipse.birt.core
org.eclipse.birt.report.engine
com.lowagie.itext 导出PDF用的。嘿嘿。
在sillycatGen.product的Configuration里面要加入如下包:
com.lowagie.itext 导出PDF的
org.eclipse.birt.core
org.eclipse.birt.report.engine
org.eclipse.birt.report.engine.emitter.html
org.eclipse.birt.report.engine.emitter.pdf
最后别忘记点一下:Add Required Plug-ins按钮,应该就可以运行了