Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » How to display Browser widget link in internal browser
How to display Browser widget link in internal browser [message #671100] Mon, 16 May 2011 19:07 Go to next message
Lubos Pochman is currently offline Lubos PochmanFriend
Messages: 29
Registered: July 2009
Junior Member
Hi all,

I am using SWT Browser widget in a view to display programatically generated html.

Unfortunately, when I click a link, the link is displayed in external browser, not in the internal browser, even if in Window/Preferences/General the preferred browser is internal browser.

SWT browser doesn't support hyperlink listener so I cannot intercept the hyperlink click and display the href reference myself.

Is there any way to use some combination of browser widget (it has to be in the view) and/or listener that would display hyperlinks in internal browser?

I have tried Forms and FormText but it is not robust enough and suitable for displaying generic html (tables etc.)

Thanks, Lubos Pochman
Re: How to display Browser widget link in internal browser [message #671195 is a reply to message #671100] Tue, 17 May 2011 05:28 Go to previous messageGo to next message
Prakash G.R. is currently offline Prakash G.R.Friend
Messages: 621
Registered: July 2009
Senior Member
On 17/05/11 12:37 AM, Lubos Pochman wrote:
> SWT browser doesn't support hyperlink listener so I cannot
> intercept the hyperlink click and display the href
> reference myself.

Does Browser.addLocationListener() is not working?

--
- Prakash
Platform UI Team, IBM

www.eclipse-tips.com
Re: How to display Browser widget link in internal browser [message #671309 is a reply to message #671195] Tue, 17 May 2011 13:07 Go to previous messageGo to next message
Lubos Pochman is currently offline Lubos PochmanFriend
Messages: 29
Registered: July 2009
Junior Member
LocationListener only intercepts changes in Browser url (setText(), setUrl()), it doesn't report click on hyperlink (<a href>) in browser content.

So for I need, LocationListener is useless.
I would need HyperlinkListener but swt Browser doesn't support it.

Is there any other browser implementation that would allow hyperlink intercept?

Or a way to intercept when Eclipse tries to display hyperlink in an external browser, Eclipse browser tries to display the href url in external browser even if I set Windows/Preferences/General/Web Browser to use internal browser (looks like a bug to me).

Or at least make SWT Browser to display hyperlink href url in internal Eclipse browser?


Re: How to display Browser widget link in internal browser [message #671328 is a reply to message #671309] Tue, 17 May 2011 14:20 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2151
Registered: July 2009
Senior Member
At the SWT level, if the clicked link wants to open the targetted page in a
new browser then you need to add listeners like in
http://dev.eclipse.org/viewcvs/viewvc.cgi/org.eclipse.swt.sn ippets/src/org/eclipse/swt/snippets/Snippet173.java?view=co
if you want it to be shown in an SWT Browser. If you don't do this then to
show the page it has to either launch a stand-alone browser (IE) or do
nothing (the others).

The LocationListener.changing() callback is the closest there is to a
hyperlink listener. Assuming you're in control of the Browser then this
should be adequate when combined with an internal state flag for determining
when a link is clicked. If the LocationListener.changing() callback happens
between a setUrl()/setText() invocation and a ProgressListener.completed()
callback then it's in response to the original setUrl()/setText()
invocation. If LocationListener.changing() is received at any other time
then it's in response to a link click.

Grant


"Lubos Pochman" <forums-noreply@eclipse.org> wrote in message
news:iqtreb$j45$1@news.eclipse.org...
> LocationListener only intercepts changes in Browser url
> (setText(), setUrl()), it doesn't report click on hyperlink
> (<a href>) in browser content.
>
> So for I need, LocationListener is useless.
> I would need HyperlinkListener but swt Browser doesn't
> support it.
>
> Is there any other browser implementation that would allow
> hyperlink intercept?
>
> Or a way to intercept when Eclipse tries to display
> hyperlink in an external browser, Eclipse browser tries to
> display the href url in external browser even if I set
> Windows/Preferences/General/Web Browser to use internal
> browser (looks like a bug to me).
>
> Or at least make SWT Browser to display hyperlink href url
> in internal Eclipse browser?
>
>
>
Re: How to display Browser widget link in internal browser [message #675438 is a reply to message #671328] Tue, 31 May 2011 14:41 Go to previous message
Lubos Pochman is currently offline Lubos PochmanFriend
Messages: 29
Registered: July 2009
Junior Member
It is not straightforward to intercept hyperlinks in SWT Browser (I use it in Eclipse plugin and display the hyperlink in internal browser instead of default external browser). Here is the sample code how I did it, might be useful for somebody with similar problem (tested on Windows only, hopefully it works on all platforms Wink):
  private Browser dummyBrowser;
  ....
  dummyBrowser = new Browser(parent, SWT.EMBEDDED);
  setupBrowser(dummyBrowser);
  ....
  Browser browser = new Browser(parent, SWT.EMBEDDED);
  setupBrowser(browser);
  ....
  private void setupBrowser(Browser browser) {
	browser.addOpenWindowListener(new OpenWindowListener() {
		public void open(WindowEvent event) {
			event.browser = dummyBrowser;
			event.required = true;
		}
	});
	browser.addLocationListener(new LocationListener() {
		@Override
		public void changing(LocationEvent event) {
		}
		@Override
		public void changed(LocationEvent event) {
			String urlStr = event.location;
			if (urlStr == null || !urlStr.startsWith("http:")) return;
			try {
				IWebBrowser browser = MyPluginActivator.getDefault().getWorkbench().getBrowserSupport().createBrowser(MyPluginActivator.BROWSER_ID);
				URL url = new URL(urlStr);
				browser.openURL(url);
			} catch (Exception e) {
				MyPluginLog.logError("Failed to open browser at: " + urlStr, e);
			}
		}
	});
  }

Previous Topic:Eclipse on Mac OS X Lion
Next Topic:Helios error on (failed) startup caused by jvm
Goto Forum:
  


Current Time: Sat Dec 20 08:07:46 GMT 2014

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

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