Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » RAP SWT Browser widget LocationListener(SWT Browser LocationListener does not work for Hyperlinks)
RAP SWT Browser widget LocationListener [message #1748578] Thu, 24 November 2016 16:49 Go to next message
Tim Oswald is currently offline Tim OswaldFriend
Messages: 3
Registered: July 2009
Junior Member
We are using the "org.eclipse.swt.browser.Browser" widget to display information data in RAP application as a replacement of the StyledText widget.
This will be done by the setText() function and the text given is HTML formatted. Now we would like to support hyperlinks. I.e. we would like to handle events if a hyperlink of the HTML text is selected.
The following code snippet works quite well in a RCP environment, but as a RAP application , the "LocationEvent" get not fired when a hyperlink is selected.
Any idea how this can be achieved? Any feedback is highly welcome Smile

Browser browser = new Browser(parent, SWT.NONE);
browser.addLocationListener(new LocationListener() {
@Override
public void changing(LocationEvent event) {
System.out.println("Event changing to "+ event.location);
}

@Override
public void changed(LocationEvent event) {
System.out.println("Event changed to "+ event.location);
}
});
browser.setText("<a href='http://www.google.co.uk'>Google</a>");
Re: RAP SWT Browser widget LocationListener [message #1748587 is a reply to message #1748578] Thu, 24 November 2016 19:40 Go to previous messageGo to next message
Chris Fairhall is currently offline Chris FairhallFriend
Messages: 197
Registered: February 2011
Senior Member
From looking at the code, it looks like those evens are only triggered when you call setText or setUrl
Re: RAP SWT Browser widget LocationListener [message #1748633 is a reply to message #1748587] Fri, 25 November 2016 13:46 Go to previous message
Tim Oswald is currently offline Tim OswaldFriend
Messages: 3
Registered: July 2009
Junior Member
That's right, against the documentation in the source code, the event is not triggered by a hyperlink Sad
But I found a working solution with JavaScript and callback function:

.....
Browser browser = new Browser(parent, SWT.NONE);
String s ="My name is " + translate2Script("Tim Oswald", "myfunction") + " and I say " + translate2Script("hello", "myfunction");
browser.setText(s);
new BrowserFunction(browser, "myfunction") { //$NON-NLS-1$
@Override
public Object function(Object[] arguments) {
System.out.println("Ret: " + Arrays.toString((Object[]) arguments[0]));
Object[] theArgs = (Object[]) arguments[0];
for(Object s : theArgs)
try {
System.out.println("Return value is:" + URLDecoder.decode(s.toString(), "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
};
};
browser.pack();
......
private String translate2Script(String text, String functionName)
{
//<a href=\"#\" onclick=\"myfunction(['hello']);return false;\"><label style=\"cursor:pointer\">Hello</label></a>
StringBuffer sb = new StringBuffer();
sb.append("<a href=\"#\" onclick=" + functionName);
sb.append("([\"");
try {
sb.append(URLEncoder.encode(text, "UTF-8").replace( "+", "%20" ));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
sb.append("\"]);return false;\"><label style=\"cursor:pointer\">");
sb.append(text);
sb.append("</label></a>");
return sb.toString();
}
Previous Topic:"invalid request counter" response when using reverse proxy
Next Topic:Problems with RAP selection Event (.open method)
Goto Forum:
  


Current Time: Mon May 28 07:54:59 GMT 2018

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

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

Back to the top