Class SelectedBrowser

java.lang.Object
de.aristaflow.adept2.ui.swtgui.SelectedBrowser

public class SelectedBrowser extends Object
This class selects the browser based on various criteria. The selection can be enforced using the style parameter or setting the corresponding system property.

The edge integration has some trouble, especially "evaluate" inside a BrowserFunction. Therefore BrowserFunctions should be created via this class which makes these calls asynchronous.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final org.eclipse.swt.browser.Browser
    The selected and wrapped browser.
    protected final boolean
    Whether Edge is the selected browser which requires asynchronous calls for fixing the execution of BrowserFunctions.
  • Constructor Summary

    Constructors
    Constructor
    Description
    SelectedBrowser(org.eclipse.swt.widgets.Composite parent)
    Creates a new browser with the designated Composite as parent.
    SelectedBrowser(org.eclipse.swt.widgets.Composite parent, int style)
    Creates a new browser with the designated Composite as parent and the designated style.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.eclipse.swt.browser.BrowserFunction
    Creates a new BrowserFunction for the selected browser with the designated name and executing the designated runnable.
    org.eclipse.swt.browser.BrowserFunction
    Creates a new BrowserFunction for the selected browser with the designated name and calling the designated consumer.
    org.eclipse.swt.browser.Browser
    Gets the selected and wrapped browser.
    static org.eclipse.swt.widgets.Text
    handleBrowserCreationProblem(String compName, Throwable throwable, org.eclipse.swt.widgets.Composite parent, org.eclipse.ui.forms.widgets.FormToolkit formToolkit)
    Handles the designated Throwable that occurred when creating a Browser.
    boolean
    Gets whether this browser runs on GTK/Linux.
    protected static int
    selectBrowser(int style)
    Selects the browser by adapting the style appropriately.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • browser

      protected final org.eclipse.swt.browser.Browser browser
      The selected and wrapped browser.
    • fixEdge

      protected final boolean fixEdge
      Whether Edge is the selected browser which requires asynchronous calls for fixing the execution of BrowserFunctions.
      See Also:
  • Constructor Details

    • SelectedBrowser

      public SelectedBrowser(org.eclipse.swt.widgets.Composite parent) throws org.eclipse.swt.SWTError
      Creates a new browser with the designated Composite as parent.
      Parameters:
      parent - The parent of the created browser.
      Throws:
      org.eclipse.swt.SWTError - If the browser widget cannot be created, an SWTError will be thrown.
      See Also:
    • SelectedBrowser

      public SelectedBrowser(org.eclipse.swt.widgets.Composite parent, int style) throws org.eclipse.swt.SWTError
      Creates a new browser with the designated Composite as parent and the designated style.
      Parameters:
      parent - The parent of the created browser.
      style - The style of the created browser.
      Throws:
      org.eclipse.swt.SWTError - If the browser widget cannot be created, an SWTError will be thrown.
      See Also:
  • Method Details

    • selectBrowser

      protected static int selectBrowser(int style)
      Selects the browser by adapting the style appropriately. If the designated style contains the browser or the corresponding system property is set, no adaption will take place.
      Currently Edge will be selected on Windows.
      Parameters:
      style - The style to use for the browser.
      Returns:
      The possibly adapted style containing the default browser (if not specified otherwise).
    • getBrowser

      public org.eclipse.swt.browser.Browser getBrowser()
      Gets the selected and wrapped browser.
      Returns:
      The selected and wrapped browser.
    • createBrowserFunction

      public org.eclipse.swt.browser.BrowserFunction createBrowserFunction(String name, Consumer<Object[]> function)
      Creates a new BrowserFunction for the selected browser with the designated name and calling the designated consumer. Due to problems with Edge, only asynchronous calls are possible, i. e. only functions without return value. However, other browsers will execute the function synchronously.
      Parameters:
      name - The name of the browser function.
      function - The function (Consumer) to be called (asynchronously).
      Returns:
      The created BrowserFunction.
    • createBrowserFunction

      public org.eclipse.swt.browser.BrowserFunction createBrowserFunction(String name, Runnable function)
      Creates a new BrowserFunction for the selected browser with the designated name and executing the designated runnable. Due to problems with Edge, the runnable will be executed asynchronously with Edge (but not with other browsers.
      Parameters:
      name - The name of the browser function.
      function - The function (Runnable) to be called (asynchronously).
      Returns:
      The created BrowserFunction.
    • runsOnGtk

      public boolean runsOnGtk()
      Gets whether this browser runs on GTK/Linux.
      Returns:
      Whether this browser runs on GTK/Linux.
    • handleBrowserCreationProblem

      public static org.eclipse.swt.widgets.Text handleBrowserCreationProblem(String compName, Throwable throwable, org.eclipse.swt.widgets.Composite parent, org.eclipse.ui.forms.widgets.FormToolkit formToolkit)
      Handles the designated Throwable that occurred when creating a Browser. A Text will be created that contains the problem and possibly a more detailed description. For instance this allows to refer to the WebView2 download in case the Edge browser requires this to open. The normal exception message is not that helpful.
      The created Text will be returned and can act as a replacement for the browser. Just append the text (or the URL) for which the browser should be created to this Text.
      Parameters:
      compName - The name of the component that tried to create a browser. This is used within the message.
      throwable - The throwable that occurred when creating the browser.
      parent - The parent composite of the created Text which is usually also the parent of the browser of which creation failed.
      formToolkit - The form-toolkit to use for the UI-elements.
      Returns:
      A Text describing the problem causing the designated throwable with the designated parent. This can be used instead of the browser of which creation failed.