嗨,我想将Birt报告添加到Vaadin Portlet

时间:2012-05-31 10:07:25

标签: vaadin birt

我是Vaadin Portlets的新手。我使用Vaadin开发了一些Portlet,我现在想要将Vairt报告添加到Vaadin portlet,但我不知道如何做到这一点,所以你能帮我解决这个问题,或者如果你有任何帮助文件,那么它会非常有帮助

提前致谢!

阿扎德

1 个答案:

答案 0 :(得分:0)

Vaadin几乎和Swing一样。然后我在互联网http://www.eclipse.org/forums/index.php/mv/msg/119253/721257/中找到了一个代码,并进行了一些小修改,只是为了在Vaadin窗口中运行:

package com.example.testejanelas;

import java.io.ByteArrayOutputStream;
import java.net.URL;
import java.net.URLClassLoader; 
import java.util.HashMap;

import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;

import com.vaadin.ui.Label;
import com.vaadin.ui.Window;

public class ViewParaBIRT extends Window {

private static final long serialVersionUID = 1L;

IReportEngine engine = null;
EngineConfig config = null;
Label label;

public ViewParaBIRT(){
    setSizeFull();
    startPlatform();
    System.out.println("Started");
    runReport();
    stopPlatform();
    System.out.println("Finished");
    center();
}

public void runReport() {
    try {
        IReportRunnable design = null;
        design = engine
                .openReportDesign("D:\\workspace.carlos\\TesteJanelas\\src\\com\\example\\birt\\new_report.rptdesign");
        IRunAndRenderTask task = engine.createRunAndRenderTask(design);
        HTMLRenderOption options = new HTMLRenderOption();
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        bos.toString("ISO-8859-1");
        options.setOutputStream(bos);
        options.setOutputFormat("html");
        options.setEmbeddable(true);
        task.setRenderOption(options);
        task.run();
        task.close();
        label = new Label(bos.toString(),Label.CONTENT_XHTML);
        addComponent(label);
        System.out.println("Finished Gen");
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

public void startPlatform() {
    try {
        config = new EngineConfig();
        HashMap context = new HashMap();
        URLClassLoader cl = (URLClassLoader) TestBirtViewer.class
                .getClassLoader();
        URL[] myurls = cl.getURLs();
        Class cl1 = cl.loadClass("com.mysql.jdbc.Driver");
        context.put("PARENT_CLASSLOADER", cl);
        config.setAppContext(context);
        Platform.startup(config);
        IReportEngineFactory factory = (IReportEngineFactory) Platform
                .createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
        engine = factory.createReportEngine(config);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

public void stopPlatform() {
    engine.destroy();
    Platform.shutdown();
}

}