[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.birt] Re: eclipse RCP application + BIRT 2.0.1 :Viewert

THANKS YOU!!!!!

Jason Weathersby escribió:
Ok, I modified the PreviewBirtAction class to give you 4 options.


//option 1 display with no parameters in SWT Browser uses the /run mapping
//option 2 display BIRT Viewer in sepearate Browser with parameter entry control - uses the /frameset mapping
//option 3 display with parameters encoded in the URL - Note this required adding additional functions - these are at the bottom of the code and where private in the WebViewer class
//option 4 display BIRT Viewer in SWT Browser. Note parameters have to be entered usng the parameter control If you want the parameter box to to be displayed before running do not set a default value on the parameter.


Hope this helps

Jason






package org.eclipse.birt.rcp.viewer;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import org.eclipse.birt.data.oda.util.manifest.DtpManifestExplorer;
import org.eclipse.birt.report.viewer.ViewerPlugin;
import org.eclipse.birt.report.viewer.utilities.WebViewer;
import org.eclipse.birt.report.viewer.utilities.WebappAccessor;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.browser.Browser;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;

public class PreviewBirtAction implements IWorkbenchWindowActionDelegate {

//static Logger logger = Logger.getLogger(PreviewBirtAction.class.getName());

 private IWorkbenchWindow window;
 private String reportName;
 private Browser browser;
 /**
  * The constructor.
  */
 public PreviewBirtAction() {
 }

public void setReportName(String report)
{
reportName = report;
}
public void setBrowser(Browser brw)
{
browser = brw;
}
public void run(IAction action) {
try {
System.setProperty( "RUN_UNDER_ECLIPSE", "true" );
DtpManifestExplorer.getInstance( ).getExtensionManifests( );
WebViewer.display(reportName , WebViewer.HTML, browser);
//WebViewer.display("C:/IANA/2005/Birt/RCP/testBirt/testSampleDB.rptdesign", WebViewer.HTML,false);
} catch (Exception e) {
//logger.error(e);
e.printStackTrace();
}


 }
 public void run() {
  try {
   System.setProperty( "RUN_UNDER_ECLIPSE", "true" );
   DtpManifestExplorer.getInstance( ).getExtensionManifests( );

//option 1 display with no parameters in SWT Browser uses the /run mapping
//WebViewer.display(reportName , WebViewer.HTML, browser);


//option 2 display BIRT Viewer in sepearate Browser with parameter entry control
//WebViewer.display(reportName , WebViewer.HTML, true);


//option 3 display with parameters encoded in the URL - Note this required adding additional functions
//WebViewer.startup(null);
//String format = "html";
//String preParameters = createURL( "run", reportName, format );
//Make sure to encode your parameters
//String parmNameString = URLEncoder.encode( "Parm", "utf-8" );
//String parmValueString = URLEncoder.encode( "MyTest Parameter", "utf-8" );
//String finalUrl = preParameters + "&" + parmNameString + "=" + parmValueString;
//browser.setUrl( finalUrl );


//option 4 display BIRT Viewer in SWT Browser. Note parameter have to be entered usng the parameter control
WebViewer.startup(null);
String format = "html";
String finalURL = createURL( "frameset", reportName, format );
browser.setUrl( finalURL );


  } catch (Exception e) {
   //logger.error(e);
   e.printStackTrace();
  }




} /** * Selection in the workbench has been changed. We * can change the state of the 'real' action here * if we want, but this can only happen after * the delegate has been created. * @see IWorkbenchWindowActionDelegate#selectionChanged */ public void selectionChanged(IAction action, ISelection selection) { }

 /**
  * We can use this method to dispose of any system
  * resources we previously allocated.
  * @see IWorkbenchWindowActionDelegate#dispose
  */
 public void dispose() {
 }

/**
* We will cache window object in order to
* be able to provide parent shell for the message dialog.
* @see IWorkbenchWindowActionDelegate#init
*/
public void init(IWorkbenchWindow window) {
this.window = window;
}
private static String createURL( String servletName, String report, String format )
{
String encodedReportName = null;
String encodedDocumentName = null;


  try
  {
   encodedReportName = URLEncoder.encode( report, "utf-8" ); //$NON-NLS-1$
  }
  catch ( UnsupportedEncodingException e )
  {
   // Do nothing
  }

if ( encodedReportName != null && encodedReportName.length( ) > 0 )
{
encodedDocumentName = encodedReportName.substring( 0, encodedReportName.lastIndexOf( "." ) ) + ".rptdocument"; //$NON-NLS-1$
}


String locale = ViewerPlugin.getDefault( ).getPluginPreferences( ).getString( WebViewer.USER_LOCALE );

String svgFlag = ViewerPlugin.getDefault( ).getPluginPreferences( ).getString( WebViewer.SVG_FLAG );
boolean bSVGFlag = false;
if ( "true".equalsIgnoreCase( svgFlag ) ) //$NON-NLS-1$
{
bSVGFlag = true;
}


String masterPageContent = ViewerPlugin.getDefault( ).getPluginPreferences( ).getString( WebViewer.MASTER_PAGE_CONTENT );
boolean bMasterPageContent = true;
if ( "false".equalsIgnoreCase( masterPageContent ) ) //$NON-NLS-1$
{
bMasterPageContent = false;
}


// So far, only report name is encoded as utf-8 format
return getBaseURL( )
+ servletName + "?" //$NON-NLS-1$
+ "__report=" + encodedReportName //$NON-NLS-1$
+ ( "run".equalsIgnoreCase( servletName )? "" : "&__document=" + encodedDocumentName ) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ "&__format=" + format //$NON-NLS-1$
+ "&__svg=" + String.valueOf( bSVGFlag ) //$NON-NLS-1$
+ ( WebViewer.LocaleTable.containsKey( locale )? "&__locale=" + WebViewer.LocaleTable.get( locale ) : "" ) //$NON-NLS-1$ //$NON-NLS-2$
+ "&__designer=true" //$NON-NLS-1$
+ "&__masterpage=" + String.valueOf( bMasterPageContent ); //$NON-NLS-1$


}
private static String getBaseURL( )
{
return "http://"; + WebappAccessor.getHost( ) + ":" //$NON-NLS-1$ //$NON-NLS-2$
+ WebappAccessor.getPort( ) + "/viewer/"; //$NON-NLS-1$
}
}







"nacho" <nacho@xxxxxxxxxx> wrote in message news:e1jja8$5t9$1@xxxxxxxxxxxxxxxxxxxx
Thank you so much Jason.

But, Can I use parameters with my reports?
Thanks

Nacho
Jason Weathersby escribió:
You can include the BIRT plugins and
call the following lines of code on an action

   System.setProperty( "RUN_UNDER_ECLIPSE", "true" );
   DtpManifestExplorer.getInstance( ).getExtensionManifests( );
   WebViewer.display(reportName , WebViewer.HTML, browser);

Where browser is SWT browser or

WebViewer.display(reportname, WebViewer.HTML,false);
to display in standard browser window.

Attached is an example of using BIRT in a simple RCP applicaiton.

Jason


"nacho" <nacho@xxxxxxxxxx> wrote in message news:e1bjqv$foe$1@xxxxxxxxxxxxxxxxxxxx
Hello,

 I want to develop a Eclipse RCP Application with Birt 2.0.1, and I
need a report viewer.
What I can do?

Thanks.

Nacho