Package de.aristaflow.adept2.ui.swtgui
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 thestyle
parameter or setting the corresponding system property.The edge integration has some trouble, especially "evaluate" inside a BrowserFunction. Therefore
BrowserFunction
s should be created via this class which makes these calls asynchronous.
-
-
Constructor Summary
Constructors Constructor Description SelectedBrowser(org.eclipse.swt.widgets.Composite parent)
Creates a new browser with the designatedComposite
as parent.SelectedBrowser(org.eclipse.swt.widgets.Composite parent, int style)
Creates a new browser with the designatedComposite
as parent and the designatedstyle
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description org.eclipse.swt.browser.BrowserFunction
createBrowserFunction(String name, Runnable function)
Creates a newBrowserFunction
for the selected browser with the designated name and executing the designated runnable.org.eclipse.swt.browser.BrowserFunction
createBrowserFunction(String name, Consumer<Object[]> function)
Creates a newBrowserFunction
for the selected browser with the designated name and calling the designated consumer.org.eclipse.swt.browser.Browser
getBrowser()
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 designatedThrowable
that occurred when creating aBrowser
.boolean
runsOnGtk()
Gets whether this browser runs on GTK/Linux.protected static int
selectBrowser(int style)
Selects the browser by adapting the style appropriately.
-
-
-
Field Detail
-
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 ofBrowserFunction
s.- See Also:
- "evaluate" inside a BrowserFunction
-
-
Constructor Detail
-
SelectedBrowser
public SelectedBrowser(org.eclipse.swt.widgets.Composite parent) throws org.eclipse.swt.SWTError
Creates a new browser with the designatedComposite
as parent.- Parameters:
parent
- The parent of the created browser.- Throws:
org.eclipse.swt.SWTError
- If the browser widget cannot be created, anSWTError
will be thrown.- See Also:
handleBrowserCreationProblem(String, Throwable, Composite, FormToolkit)
-
SelectedBrowser
public SelectedBrowser(org.eclipse.swt.widgets.Composite parent, int style) throws org.eclipse.swt.SWTError
Creates a new browser with the designatedComposite
as parent and the designatedstyle
.- 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, anSWTError
will be thrown.- See Also:
handleBrowserCreationProblem(String, Throwable, Composite, FormToolkit)
-
-
Method Detail
-
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 newBrowserFunction
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 newBrowserFunction
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 designatedThrowable
that occurred when creating aBrowser
. AText
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 createdText
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 thisText
.- 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 createdText
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 designatedthrowable
with the designatedparent
. This can be used instead of the browser of which creation failed.
-
-