24
Jul
stored in: General and tagged:

When building an Eclipse facet, I found the need to pop up a new browser window. The idea was, the user would use the facet, then upon finishing the wizard, a browser would open directly to the documentation they needed to continue working. This way, they didn’t have to search around for ‘next steps’ documentation. The following code snippet pops up a URL in the default system browser, in my case at work, this is Internet Explorer (company standard).

int style = IWorkbenchBrowserSupport.AS_EDITOR | IWorkbenchBrowserSupport.LOCATION_BAR | IWorkbenchBrowserSupport.STATUS;
IWebBrowser browser = WorkbenchBrowserSupport.getInstance().createBrowser(style, "MyBrowserID", "MyBrowserName", "MyBrowser Tooltip");
browser.openURL(new URL("http://www.google.com"));

This creates a browser instance of whatever type the developer has configured for the Eclipse install. Word of caution, if you need to popup multiple browser instances, be sure to change the ‘ID’ attribute, or pass ‘null’ to have a unique ID generated each time. If you use the same ID, Eclipse will attempt to use the same browser instance.

4 Responses to “Open URL in Eclipse”

  1. Byron Foster Says:

    Thanks, this was just the example I was looking for!

  2. Mark Edgeworth Says:

    Nice one, Dave! This saved me quite a bit of hunting about in the help files, and worked straight off the page. Many thanks, Mark.

  3. Nikunj Says:

    Thank you so much. It really helped a lot

  4. Lokesh Says:

    This uses internal code.
    check the following from SWT Class..
    Program.launch(url);

Leave a Reply