Class BrowserFactory


public final class BrowserFactory extends AbstractCompositeFactory<BrowserFactory,Browser>
This class provides a convenient shorthand for creating and initializing Browser. This offers several benefits over creating Browser normal way:
  • The same factory can be used many times to create several Browser instances
  • The setters on BrowserFactory all return "this", allowing them to be chained
Example usage:
 Browser browser = BrowserFactory.newBrowser(SWT.NONE)//
                .url("http://www.eclipse.org") //
                .layoutData(gridData) //
                .create(parent);
 

The above example creates a Browser for the eclipse website. Finally the Browser is created in "parent".

 BrowserFactory browserFactory = BrowserFactory.newGroup(SWT.NONE);
 browserFactory.url("http://www.eclipse.org").create(parent);
 browserFactory.url("https://www.eclipse.org/projects/").create(parent);
 browserFactory.url("https://www.eclipse.org/donate/").create(parent);
 

The above example creates three browser using the same instance of BrowserFactory.

Since:
3.25
  • Method Details

    • newBrowser

      public static BrowserFactory newBrowser(int style)
      Creates a new BrowserFactory with the given style. Refer to Browser(Composite, int) for possible styles.
      Returns:
      a new BrowserFactory instance
    • html

      public BrowserFactory html(String html)
      Renders a string containing HTML. The rendering of the content occurs asynchronously. The rendered page will be given trusted permissions; to render the page with untrusted permissions use setText(String html, boolean trusted) instead.

      The html parameter is Unicode-encoded since it is a java String. As a result, the HTML meta tag charset should not be set. The charset is implied by the String itself.

      Parameters:
      html - the html
      Returns:
      this
      See Also:
    • html

      public BrowserFactory html(String html, boolean trusted)
      Renders a string containing HTML. The rendering of the content occurs asynchronously. The rendered page can be given either trusted or untrusted permissions.

      The html parameter is Unicode-encoded since it is a java String. As a result, the HTML meta tag charset should not be set. The charset is implied by the String itself.

      The trusted parameter affects the permissions that will be granted to the rendered page. Specifying true for trusted gives the page permissions equivalent to a page on the local file system, while specifying false for trusted gives the page permissions equivalent to a page from the internet. Page content should be specified as trusted if the invoker created it or trusts its source, since this would allow (for instance) style sheets on the local file system to be referenced. Page content should be specified as untrusted if its source is not trusted or is not known.

      Parameters:
      html - the html
      trusted - false if the rendered page should be granted restricted permissions and true otherwise
      Returns:
      this
      See Also:
    • url

      public BrowserFactory url(String url)
      Begins loading a URL. The loading of its content occurs asynchronously.
      Parameters:
      url - the URL to be loaded
      Returns:
      this
      See Also:
    • url

      public BrowserFactory url(String url, String postData, String[] headers)
      Begins loading a URL. The loading of its content occurs asynchronously.

      If the URL causes an HTTP request to be initiated then the provided postData and header arguments, if any, are sent with the request. A value in the headers argument must be a name-value pair with a colon separator in order to be sent (for example: "user-agent: custom").

      Parameters:
      url - the URL to be loaded
      postData - post data to be sent with the request, or null
      headers - header lines to be sent with the request, or null
      Returns:
      this
      See Also:
    • disableJS

      public BrowserFactory disableJS()
      Sets that javascript will not be allowed to run in pages subsequently viewed in the receiver. Note that setting this value does not affect the running of javascript in the current page.
      Returns:
      this
      See Also: