0

我是 Vaadin Portlets 的新手。我已经使用 Vaadin 开发了几个 Portlet,我现在想将 Birt 报告添加到 Vaadin portlet,但我不知道如何执行此操作,所以请你帮我解决这个问题,或者如果你有任何帮助文档,那么它会很有帮助的

提前致谢!

阿扎德

4

1 回答 1

0

Vaadin 与 Swing 几乎相同。然后我在 Internet 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();
}

}
于 2012-06-12T00:42:09.383 回答