Home » Archived » BIRT » WebViewer in RCP and relative path flatfile
|
Re: WebViewer in RCP and relative path flatfile [message #494233 is a reply to message #494181] |
Thu, 29 October 2009 16:44 |
|
Martin,
Can you try something like:
Bundle bundle = org.eclipse.core.runtime.Platform.getBundle("myrcpapp");
URL url = FileLocator.find(bundle, new
Path("/reports/myffreport.rptdesign"), null);
String rpt = FileLocator.toFileURL(url).getPath();
Jason
Martin Schmitz wrote:
> Hello,
>
> we have a RCP application based on eclipse. Inside the workspace the
> user have reports and the flatfiles for that reports.
>
> Normally the flatfile datasource has an absolute folder, but that
> doesn't work because of different places of the workspace.
>
> So we would like to go on with relative paths. In a webapplication that
> is not a problem, when the report-files are inside the webapplication.
> The we use the script in beforeOpen of the datasource:
>
> var rp = reportContext.getHttpServletRequest().getSession().getServle
> tContext().getRealPath( "/");
> this.setExtensionProperty("HOME", rp);
>
> But how to use that in the WebViewer? How is the best way to do that. At
> the moment we use that to view the reports:
>
> WebViewer.display(report, browser, params);
>
> Thanks
|
|
|
Re: WebViewer in RCP and relative path flatfile [message #494250 is a reply to message #494233] |
Thu, 29 October 2009 17:56 |
Martin Schmitz Messages: 23 Registered: July 2009 |
Junior Member |
|
|
Jason,
when I understand you code right, it is for finding the report-file in my application. That is not the problem, because the user double clicks the file for opening the report.
I start the WebViewer with this code:
IFileEditorInput input = (IFileEditorInput) getEditorInput();
IFile file = input.getFile();
// ==============================================
String report = file.getLocation().makeAbsolute().toOSString();
if (report.length() != 0) {
Map<String, Object> params = new HashMap<String, Object>();
params.put(WebViewer.RESOURCE_FOLDER_KEY, "C:/Temp/");
params.put(WebViewer.SERVLET_NAME_KEY, "run");
params.put(WebViewer.FORMAT_KEY, WebViewer.HTML);
WebViewer.display(report, browser, params);
}
The report is: C:/Workspace/Reports/MyLittleReport.rptdesign
The data is C:/Workspace/Reports/Data/mydata.csv
The blue path is choosen by the user and may be different. How to set the datasource via JavaScript, when I only know that it is relative to the report in the folder data. Due the report is not inside an application server I think I am not able to find out the path to the file and even to the datafile by jacascript, right?. Is there a way to pass the path of the report to the webviewer and then receiving that variable in javascript datasource.beforeopen?
Martin
|
|
|
Re: WebViewer in RCP and relative path flatfile [message #494270 is a reply to message #494250] |
Thu, 29 October 2009 21:10 |
|
Martin,
Pardon my confusion :>
You have a couple of choices:
1 - call the plugin code from script like in the beforeFactory
importPackage(Packages.org.eclipse.core.runtime);
mybundle = Platform.getBundle("org.eclipse.birt.report.viewer");
furl = FileLocator.find(mybundle, new Path("/birt/webcontent"), null);
//you may have to trim leading slash
myfolder = FileLocator.toFileURL(furl).getPath();
or
2 - Implement the appcontext extension and preload the path into the
appcontext.
In your code before calling display (Note that viewer code has not been
updated yet for new preference scheme so use deprec. call.
//new DefaultScope().getNode("").put("APPCONTEXT_EXTENSION_KEY",
"MyAppContext");
//String appContextName =
Platform.getPreferencesService().getString("org.eclipse.birt.viewer ",
"APPCONTEXT_EXTENSION_KEY", "", null);
//WebViewer has not been updated to use new preferences scheme
String appContextName = ViewerPlugin.getDefault(
).getPluginPreferences( ).getString( "APPCONTEXT_EXTENSION_KEY" );
//
ViewerPlugin.getDefault( ).getPluginPreferences(
).setValue("APPCONTEXT_EXTENSION_KEY", "MyAppContext");
example MyAppContext
package org.eclipse.birt.examples.rcpviewer;
import java.util.Map;
import org.eclipse.birt.report.viewer.api.AppContextExtension;
public class MyAppContext extends AppContextExtension{
@Override
public Map getAppContext(Map appContext) {
Map hm = super.getAppContext(appContext);
hm.put("PARENT_CLASSLOADER", PreviewBirtAction.class.getClassLoader());
return hm;
}
@Override
public String getName() {
// TODO Auto-generated method stub
return "MyAppContext";
}
}
Put anything you want in the context and then in an expression or script
call
reportContext.getAppContext().get("whateveruputin");
Jason
Martin Schmitz wrote:
> Jason,
>
> when I understand you code right, it is for finding the report-file in
> my application. That is not the problem, because the user double clicks
> the file for opening the report.
>
> I start the WebViewer with this code:
>
> IFileEditorInput input = (IFileEditorInput) getEditorInput();
> IFile file = input.getFile();
> // ==============================================
> String report = file.getLocation().makeAbsolute().toOSString();
> if (report.length() != 0) {
> Map<String, Object> params = new HashMap<String, Object>();
> params.put(WebViewer.RESOURCE_FOLDER_KEY, "C:/Temp/");
> params.put(WebViewer.SERVLET_NAME_KEY, "run");
> params.put(WebViewer.FORMAT_KEY, WebViewer.HTML);
> WebViewer.display(report, browser, params);
> }
>
> The report is: C:/Workspace/Reports/MyLittleReport.rptdesign
> The data is C:/Workspace/Reports/Data/mydata.csv
>
> The blue path is choosen by the user and may be different. How to set
> the datasource via JavaScript, when I only know that it is relative to
> the report in the folder data. Due the report is not inside an
> application server I think I am not able to find out the path to the
> file and even to the datafile by jacascript, right?. Is there a way to
> pass the path of the report to the webviewer and then receiving that
> variable in javascript datasource.beforeopen?
>
> Martin
|
|
| |
Re: WebViewer in RCP and relative path flatfile [message #494397 is a reply to message #494381] |
Fri, 30 October 2009 14:01 |
|
Martin,
That should work. I was trying to come up with an alternative to adding
a report parameter.
Jason
Martin Schmitz wrote:
> Jason,
>
> thank you for the help. I decided pro alternativ 2, but there is one
> problem. The path, I am setting if fix, once I have set it.
>
> I think, there is only one way to get the datasource folder variable. I
> will reading the report, add a parameter, that is invisible to users,
> with the path of the folder and then change "HOME" of the datasource to
> that folder and the save the report as emporaryfile.
>
> That should be the easiest way to handle that problem?
>
> Martin
>
>
|
|
|
Re: WebViewer in RCP and relative path flatfile [message #495253 is a reply to message #494397] |
Wed, 04 November 2009 11:17 |
Martin Schmitz Messages: 23 Registered: July 2009 |
Junior Member |
|
|
Here is my solution.
Starting the report from RCP
private void previewReport() {
try {
WebViewer.stopAll();
IFileEditorInput input = (IFileEditorInput) getEditorInput();
IFile file = input.getFile();
String report = "";
// ====================================================================================
DesignConfig config = new DesignConfig();
IDesignEngine engine = null;
try {
ReportDesignHandle designHandle = null;
ElementFactory designFactory = null;
Platform.startup(config);
IDesignEngineFactory factory = (IDesignEngineFactory) Platform.createFactoryObject(IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY);
engine = factory.createDesignEngine(config);
SessionHandle session = engine.newSessionHandle(ULocale.ENGLISH);
// open a design or a template
designHandle = session.openDesign(file.getLocation().makeAbsolute().toOSString());
designFactory = designHandle.getElementFactory();
ScalarParameterHandle sph = designFactory.newScalarParameter("REPORT_PATH");
List<String> defaultValue = new ArrayList<String>();
defaultValue.add(file.getParent().getLocation().makeAbsolute().toOSString());
//
sph.setDefaultValueList(defaultValue);
sph.setProperty(ScalarParameterHandle.HIDDEN_PROP, "true");
sph.setProperty(ScalarParameterHandle.VALUE_TYPE_PROP, "static");
sph.setProperty(ScalarParameterHandle.IS_REQUIRED_PROP, "false");
sph.setProperty(ScalarParameterHandle.DATA_TYPE_PROP, "string");
sph.setProperty(ScalarParameterHandle.DISTINCT_PROP, "true");
sph.setProperty(ScalarParameterHandle.PARAM_TYPE_PROP, "simple");
sph.setProperty(ScalarParameterHandle.CONTROL_TYPE_PROP, "text-box");
designHandle.getParameters().add(sph);
// ====================================================================================
report = File.createTempFile("report", ".rptdesign").getAbsolutePath();
designHandle.saveAs(report); //$NON-NLS-1$
designHandle.close();
}
catch (Exception ex) {
ex.printStackTrace();
}
if (report.length() != 0) {
Map<String, Object> params = new HashMap<String, Object>();
// ====================================================================================
params.put(WebViewer.SERVLET_NAME_KEY, "run");
// params.put(WebViewer.REPORT_DEBUT_MODE, "yes");
params.put(WebViewer.FORMAT_KEY, WebViewer.HTML);
WebViewer.display(report, browser, params);
}
}
catch (Exception e) {
PlugIn.log(e);
}
}
Here is the code in the reports beforeOpen in datasource:
if( reportContext.getHttpServletRequest() == null ){
}
else if( reportContext.getHttpServletRequest().getAttribute("attributeBean") == null ){
}
else if( reportContext.getHttpServletRequest().getAttribute("attributeBean").isDesigner() ){
}
else{
var rp =reportContext.getParameterValue( "REPORT_PATH" ) +"/DATA";
this.setExtensionProperty("HOME",rp);
}
|
|
|
Re: WebViewer in RCP and relative path flatfile [message #495320 is a reply to message #495253] |
Wed, 04 November 2009 15:06 |
|
Martin,
This looks good.
Jason
Martin Schmitz wrote:
> Here is my solution.
>
> Starting the report from RCP
>
>
> private void previewReport() {
> try {
> WebViewer.stopAll();
> IFileEditorInput input = (IFileEditorInput) getEditorInput();
> IFile file = input.getFile();
> String report = "";
> //
> ============================================================ ========================
>
> DesignConfig config = new DesignConfig();
> IDesignEngine engine = null;
> try {
> ReportDesignHandle designHandle = null;
> ElementFactory designFactory = null;
> Platform.startup(config);
> IDesignEngineFactory factory = (IDesignEngineFactory)
> Platform.createFactoryObject(IDesignEngineFactory.EXTENSION_ DESIGN_ENGINE_FACTORY);
>
> engine = factory.createDesignEngine(config);
> SessionHandle session =
> engine.newSessionHandle(ULocale.ENGLISH);
> // open a design or a template
> designHandle =
> session.openDesign(file.getLocation().makeAbsolute().toOSStr ing());
> designFactory = designHandle.getElementFactory();
> ScalarParameterHandle sph =
> designFactory.newScalarParameter("REPORT_PATH");
> List<String> defaultValue = new ArrayList<String>();
>
> defaultValue.add(file.getParent().getLocation().makeAbsolute ().toOSString());
>
> //
> sph.setDefaultValueList(defaultValue);
> sph.setProperty(ScalarParameterHandle.HIDDEN_PROP, "true");
> sph.setProperty(ScalarParameterHandle.VALUE_TYPE_PROP,
> "static");
> sph.setProperty(ScalarParameterHandle.IS_REQUIRED_PROP,
> "false");
> sph.setProperty(ScalarParameterHandle.DATA_TYPE_PROP,
> "string");
> sph.setProperty(ScalarParameterHandle.DISTINCT_PROP,
> "true");
> sph.setProperty(ScalarParameterHandle.PARAM_TYPE_PROP,
> "simple");
> sph.setProperty(ScalarParameterHandle.CONTROL_TYPE_PROP,
> "text-box");
> designHandle.getParameters().add(sph);
> //
> ============================================================ ========================
>
> report = File.createTempFile("report",
> ".rptdesign").getAbsolutePath();
> designHandle.saveAs(report); //$NON-NLS-1$
> designHandle.close();
> }
> catch (Exception ex) {
> ex.printStackTrace();
> }
> if (report.length() != 0) {
> Map<String, Object> params = new HashMap<String, Object>();
> //
> ============================================================ ========================
>
> params.put(WebViewer.SERVLET_NAME_KEY, "run");
> // params.put(WebViewer.REPORT_DEBUT_MODE, "yes");
> params.put(WebViewer.FORMAT_KEY, WebViewer.HTML);
> WebViewer.display(report, browser, params);
> }
> }
> catch (Exception e) {
> PlugIn.log(e);
> }
> }
>
>
>
> Here is the code in the reports beforeOpen in datasource:
>
> if( reportContext.getHttpServletRequest() == null ){
> }
> else if(
> reportContext.getHttpServletRequest().getAttribute("attributeBean ") ==
> null ){
> }
> else if(
> reportContext.getHttpServletRequest().getAttribute("attributeBean ").isDesigner()
> ){
> }
> else{
> var rp =reportContext.getParameterValue( "REPORT_PATH" ) +"/DATA";
> this.setExtensionProperty("HOME",rp);
> }
|
|
|
Goto Forum:
Current Time: Fri Apr 26 03:32:24 GMT 2024
Powered by FUDForum. Page generated in 0.02529 seconds
|