Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » SWT Browser, loading a page and javascripts from file system.
SWT Browser, loading a page and javascripts from file system. [message #550251] Thu, 29 July 2010 15:37 Go to next message
Christophe Bouhier is currently offline Christophe Bouhier
Messages: 937
Registered: July 2009
Senior Member
Hi,

Like any browser, if I open a local file, I would have to set the path
to the javascripts relative to the html file.

Now, I use SWT Browser setText() to load an html formated script with
references to javascripts, however these are not loaded.

I load the html from my RCP runtime. Is there a way to make the SWT
Browser also load the scripts from the runtime bundle? (I have tried a
relative path from the bundle entry like /web/link/myscript.js).


thanks Christophe
Re: SWT Browser, loading a page and javascripts from file system. (SOLVED) [message #550382 is a reply to message #550251] Fri, 30 July 2010 07:44 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe Bouhier
Messages: 937
Registered: July 2009
Senior Member
Hi,

I found a solution. It's a bit of a hack, but it works!

Put this in the plugin Activator:

public static String getAbsoluteURL(String path){
Bundle bundle = Platform.getBundle(PLUGIN_ID);
if (!BundleUtility.isReady(bundle)) {
return null;
}
String loc = bundle.getLocation();
loc = loc.substring(loc.indexOf("file:"), loc.length()).concat(path);
return loc;
}

What it does:

1. It gets the bundle for this plugin.
2. It gets the absolute location in String format. The location has some
polutated prefix, which we strip off.
3. What you get is a nice absolute URL starting with file:/../[path to
the relative location]


Use this location in your SWT.browser setURL() and the local javascripts
will also in the SWT. (See below the relative path starting with
'lib/flot').


<script language="javascript" type="text/javascript"
src="lib/flot/jquery.js"></script>
<script language="javascript" type="text/javascript"
src="lib/flot/jquery.flot.js"></script>



The way I use this, is by transforming the contents of an EMF model
to i.e. a json file which the HTML scripts use to display in am SWT
Browser.

Cheers Christophe






Christophe Bouhier wrote:
> Hi,
>
> Like any browser, if I open a local file, I would have to set the path
> to the javascripts relative to the html file.
>
> Now, I use SWT Browser setText() to load an html formated script with
> references to javascripts, however these are not loaded.
>
> I load the html from my RCP runtime. Is there a way to make the SWT
> Browser also load the scripts from the runtime bundle? (I have tried a
> relative path from the bundle entry like /web/link/myscript.js).
>
>
> thanks Christophe
Re: SWT Browser, loading a page and javascripts from file system. (SOLVED) [message #1061523 is a reply to message #550382] Sat, 01 June 2013 21:24 Go to previous message
Roee Mising name is currently offline Roee Mising name
Messages: 1
Registered: June 2013
Junior Member
Nice solution, thanks (:
Previous Topic:SWT FileDialog on Mac not localized
Next Topic:MenuItem Tooltip bug
Goto Forum:
  


Current Time: Thu Oct 23 18:34:26 GMT 2014

Powered by FUDForum. Page generated in 0.06972 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software