Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » How to get a reference to a Browser
How to get a reference to a Browser [message #640562] Mon, 22 November 2010 09:00 Go to next message
Gabriel Petrovay is currently offline Gabriel Petrovay
Messages: 42
Registered: July 2009
Member
Hi,

How can I get a reference to a org.eclipse.swt.Browser from a WebBrowserEditor or from a org.eclipse.ui.IWebBrowser.

Or do you know other way to get the content of a WebBrowserEditor? (Browser would suffice since this has the getText() method)

Thanks!
Re: How to get a reference to a Browser [message #640575 is a reply to message #640562] Mon, 22 November 2010 09:15 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel Krügler
Messages: 853
Registered: July 2009
Senior Member
On 11/22/2010 15:00, Gabriel Petrovay wrote:
> Hi,
>
> How can I get a reference to a org.eclipse.swt.Browser from a
> WebBrowserEditor or from a org.eclipse.ui.IWebBrowser.
>
> Or do you know other way to get the content of a WebBrowserEditor?
> (Browser would suffice since this has the getText() method)

Have you tried this (from a Google search, untested):

IWebBrowser webBrowser = browser.createBrowser
(IWorkbenchBrowserSupport.LOCATION_BAR |
IWorkbenchBrowserSupport.AS_EDITOR |
IWorkbenchBrowserSupport.NAVIGATION_BAR |
IWorkbenchBrowserSupport.STATUS, null,"TestBrowser", "TestBrowser");

URL url = ...;

webBrowser.openURL(url);


HTH & Greetings from Bremen,

- Daniel Krügler
Re: How to get a reference to a Browser [message #640576 is a reply to message #640575] Mon, 22 November 2010 09:19 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel Krügler
Messages: 853
Registered: July 2009
Senior Member
On 11/22/2010 15:15, Daniel Krügler wrote:
> On 11/22/2010 15:00, Gabriel Petrovay wrote:
>> Hi,
>>
>> How can I get a reference to a org.eclipse.swt.Browser from a
>> WebBrowserEditor or from a org.eclipse.ui.IWebBrowser.
>>
>> Or do you know other way to get the content of a WebBrowserEditor?
>> (Browser would suffice since this has the getText() method)
>
> Have you tried this (from a Google search, untested):
>
> IWebBrowser webBrowser = browser.createBrowser
> (IWorkbenchBrowserSupport.LOCATION_BAR |
> IWorkbenchBrowserSupport.AS_EDITOR |
> IWorkbenchBrowserSupport.NAVIGATION_BAR |
> IWorkbenchBrowserSupport.STATUS, null,"TestBrowser", "TestBrowser");
>
> URL url = ...;
>
> webBrowser.openURL(url);

Here something that lloks like a helper functionality for web browsers:

http://www.koders.com/java/fid2383AEBC81C69847012A8E7408F354 8615ED13D8.aspx?s=calendar#L18

> HTH & Greetings from Bremen,
>
> - Daniel Krügler
Re: How to get a reference to a Browser [message #640582 is a reply to message #640575] Mon, 22 November 2010 09:38 Go to previous messageGo to next message
Gabriel Petrovay is currently offline Gabriel Petrovay
Messages: 42
Registered: July 2009
Member
Hi Daniel,

I already have the browser open. I want to read the contents out of it. The org.eclipse.swt.Browser object has the getText() method to read it. But I want to get a reference to such an object?

The IWorkbenchBrowserSupport gives me only the org.eclipse.ui.browser.IWebBrowser (if I had the id, assume that I have it)

So I need to get a Browser from a IWebBrowser.

I don't see a solution in the link you send either. Thanks anyway!


Any ideas?
Re: How to get a reference to a Browser [message #640619 is a reply to message #640582] Mon, 22 November 2010 10:35 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6850
Registered: July 2009
Location: Ottawa
Senior Member

There doesn't look to be a solution, at least not one with API. The
Browser is a field in org.eclipse.ui.internal.browser.BrowserViewer
which is in turn held in the
org.eclipse.ui.internal.browser.WebBrowserEditor

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: How to get a reference to a Browser [message #640659 is a reply to message #640619] Mon, 22 November 2010 12:53 Go to previous message
Gabriel Petrovay is currently offline Gabriel Petrovay
Messages: 42
Registered: July 2009
Member
This is the current hack that I do.

Control[] childs = ((Composite)editor.getWidget()).getChildren();
if (childs.length > 0 && (childs[0] instanceof Composite)) {
    Composite comp = (Composite)childs[0];
    childs = comp.getChildren();
    if (childs.length > 0 && (childs[0] instanceof BrowserViewer)) {
        text[0] = ((BrowserViewer)childs[0]).getBrowser().getText();
    }
}


I have it but I have to do it. Any other better solutions?
Previous Topic:Efficient update of workspace with new config spec
Next Topic:Preferences Not Passed Through to AntRunner in 3.6.1
Goto Forum:
  


Current Time: Wed Apr 16 00:43:46 EDT 2014

Powered by FUDForum. Page generated in 0.02046 seconds