1 / 10

The SWT Browser Widget

The SWT Browser Widget. Shawn Spiars Yazoo Consulting http://www.yazooconsulting.com. SWT Browser. Works with IE, Mozilla, and Safari New in Eclipse 3.6 Allows clients to include post data and add/override header values when initiating HTTP requests

christa
Download Presentation

The SWT Browser Widget

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The SWT Browser Widget Shawn Spiars Yazoo Consulting http://www.yazooconsulting.com

  2. SWT Browser Works with IE, Mozilla, and Safari New in Eclipse 3.6 Allows clients to include post data and add/override header values when initiating HTTP requests Browser.setURL(String url, String postData, String[] headers); Attempts to dispose the receiver, but allows the dispose to be vetoed in response to an <code>onbeforeunload</code> listener in the browsers current page Browser.close();

  3. new Browser(parent, SWT.NONE) //use default browser • new Browser(parent, SWT.MOZILLA) //explicit for Mozilla • Bundle bundle = Platform.getBundle("org.mozilla.xulrunner.win32.win32.x86"); • if (bundle != null) { • URL resourceUrl = bundle.getResource("xulrunner"); • try { • URL fileUrl = FileLocator.toFileURL(resourceUrl); • File file = new File(fileUrl.toURI()); • System.setProperty("org.eclipse.swt.browser.XULRunnerPath", file.getAbsolutePath()); • } catch (Exception e) { • logger.error(e); • } • } Default Browser or Mozilla

  4. browser = new Browser(composite, SWT.NONE); • browser.setUrl(“http://www.google.com”); • Object result = browser.evaluate(String script); • Supported mappings: JavaScript null or undefined ==> null JavaScript number ==> java.lang.Double JavaScript string ==> java.lang.String JavaScript boolean ==> java.lang.Boolean JavaScript array whose elements are all of supported types ==> java.lang.Object[] Java to JavaScript

  5. Extend Java BrowserFunction class • static class CustomFunction extends BrowserFunction { • CustomFunction (Browser browser, String name) { • super (browser, name); • } • public Object function (Object[] arguments) { • System.out.println ("theJavaFunction() called from javascriptargs:"); • ……. • return value; • } • } • new CustomFunction (browser, "theJavaFunction"); • Call Java BrowserFunction from JavaScript: • <script language="JavaScript”> • var result = theJavaFunction(12, false, null); • </script> JavaScript to Java

  6. Renders a string containing HTML • Browser.setText(String html) • Listen for page load completion • Browser.addProgressListener • Listen for link selections • Browser.addLocationListener • Browser.addOpenWindowListener • Simple authentication • Browser.addAuthenticationListener • Cookies • Browser.getCookie • Browser.setCookie • Browser.clearSessions Additional API

  7. Simple RCP application which demonstrates some functions of the SWT Browser widget (Eclipse 3.6.0) • SWT Browser embedded in Eclipse editor • Editor contributions create toolbar buttons for dialogs: • Evaluate JavaScript dialog • Show page source dialog • Set page source dialog • Activator class loads Xulrunner/Mozilla xpcom bundles • (includes bundle version 1.8.1.3) SWT Browser Example

  8. SWT Browser Example

  9. References Download SWT Browser Example application (includes source) http://www.yazooconsulting.com/downloads/SWTBrowserExample.zip Embedding Web UI Components in Eclipse by Boris Bokowski http://www.slideshare.net/bokowski/tutorial-embedding-web-ui-components-in-eclipse SWT FAQ http://www.eclipse.org/swt/faq.php#whatisbrowser SWT Snippets http://www.eclipse.org/swt/snippets/

  10. Thanks! • Shawn Spiars • sspiars@yazooconsulting.com

More Related