2012-05-31 30 views
0

我是Vaadin Portlets的新手。我已經開發了幾個使用Vaadin的Portlets,現在我想將Birt報告添加到Vaadin portlet,但我不知道如何做到這一點,所以你可以幫助我,或者如果你有任何幫助文檔,將真正有幫助您好我想添加Birt報告給Vaadin Portlet

在此先感謝!

Azad

回答

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(); 
} 

} 
+0

什麼是TestBirtViewer.class? – Pere