Class SWTHelper
java.lang.Object
com.iizix.swt.SWTHelper
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default ofEDGE_TIMEOUT_PROPERTYin iiziGo, in milliseconds, set below unless the property is set already (a launcher argument wins).static final StringThe system property SWT reads once, when its Edge implementation loads, for the time it waits for a WebView2 operation, above all the asynchronous creation of a new Edge Browser (its first operation waits for it): SWT's own default is 5000 ms, after which the Browser's first operation throws "Waiting for Edge operation to terminate timed out" and the Browser never recovers.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionstatic voidaddCapsLockWarning(Text passwordField) Adds a caps-lock warning decorator to a password field.static TableEditoraddEditableTableColumn(Table table, int column, int minimumWidth, ModifyListener modifyListener) Adds an editable column for a table.static voidaddMenuSeparator(Menu menu) Adds a menu separator.static voidaddTableColumnResizer(Table table) Adds a table column re-sizer to make the last column resize with the table and dialog box.static voidaddTableSorter(Table table, String... dataKeys) Adds a table sorter.static voidaddTreeColumnResizer(Tree tree) Adds a table column re-sizer to make the last column resize with the table and dialog box.static BrowsercreateBrowser(Composite parent, Color background) Creates a Browser instance that uses Edge under Windows if Eclipse is of version 4.21 or better and Edge is installed.static CompositecreateBrowserOrCompositeForFailure(Composite parent, Color background) Creates a Browser Composite if possible, otherwise in case of an exception, a Composite wrapped read-only multi-line entry field instead of a browser.static ImagecreateImage(int rgb, int width, int height) Create an image of a color.static ImagecreateImage(int rgb, int width, int height, boolean doFrame) Create an image of a color.static ImagecreateImage(int r, int g, int b, int width, int height) Create an image of a color.static ImagecreateImage(int r, int g, int b, int width, int height, boolean doFrame) Create an image of a color.static ImagecreateImage(Color color, int width, int height) Create an image of the specified color.static ImagecreateImage(Color color, int width, int height, boolean doFrame) Create an image of the specified color.static voidenableDialogMove(Shell shell) Enables move of a dialog box.static voidexpandAll(TreeViewer viewer) Performs the Expand all on a tree viewer, very fast.static voidfixComboMWScroll(Control combo) Fix for Combobox processing mouse wheel when not focused in Win32, eating mouse from scroll pane.static intCached value for browser supported:static org.osgi.framework.VersionAttempts to get the version of the Eclipse IDE we're running in.static intGets the edited line number of a Table Editor.static TextGets the entry field being edited, null for none.static ControlgetFocusControl(Composite composite) Gets the control in focus for a composite.static booleanReturns if Eclipse uses Microsoft Internet Explorer (11) or not for sure, or if the default browser is being used.static voidresizeColumns(Table table) Packs the tables columns and resizes the last column in a table to fit the table width.static voidresizeColumns(Tree tree) Packs the tree table columns and resizes the last column in a table to fit the table width.static voidretryBrowserOnce(Composite replacement, Color background, Consumer<Browser> onBrowser) Retries once the creation of a Browser thatcreateBrowserOrCompositeForFailure(Composite, Color)replaced by its replacement Composite, e.g.static voidsetEnabledRecursive(Control control, boolean isEnabled) Enables or disables a control/composite and all its children.static voidshowPopupMenu(IzMenu menu) Displays a drop-down menu at screen location where mouse is located.static voidshowPopupMenu(IzMenu menu, int x, int y) Displays a drop-down menu at screen location.static voidshowPopupMenu(IzMenu menu, Control control) Displays a drop-down menu below a control.static voidshowPopupMenu(IzMenu menu, Control control, int xOffset, int yOffset) Displays a drop-down menu below a control.static voidshowPopupMenu(IzMenu menu, ToolItem item) Displays a drop-down menu below a control.static voidshowPopupMenu(Menu menu) Displays a drop-down menu at screen location where mouse is located.static voidshowPopupMenu(Menu menu, int x, int y) Displays a drop-down menu at screen location.static voidshowPopupMenu(Menu menu, Control control) Displays a drop-down menu below a control.static voidshowPopupMenu(Menu menu, Control control, int xOffset, int yOffset) Displays a drop-down menu below a control.static voidshowPopupMenu(Menu menu, ToolItem item) Displays a drop-down menu below a control.
Field Details
EDGE_TIMEOUT_PROPERTY
The system property SWT reads once, when its Edge implementation loads, for the time it waits for a WebView2 operation, above all the asynchronous creation of a new Edge Browser (its first operation waits for it): SWT's own default is 5000 ms, after which the Browser's first operation throws "Waiting for Edge operation to terminate timed out" and the Browser never recovers.- See Also:
EDGE_TIMEOUT_MS
public static final int EDGE_TIMEOUT_MSThe default ofEDGE_TIMEOUT_PROPERTYin iiziGo, in milliseconds, set below unless the property is set already (a launcher argument wins). Measured on SPACY (CC-FIX-BROWSER-EDITORS-REGRESSION): a creation takes 60-800 ms on an idle machine, but under CPU load (half the processors busy beside a reactor) the third Panel Editor of a burst took 5085 ms and timed out, while nothing else was wrong; the wait pumps the UI thread's messages meanwhile. Four times that worst case gives WebView2 the time it needs on a loaded machine.- See Also:
Constructor Details
SWTHelper
public SWTHelper()
Method Details
resizeColumns
Packs the tables columns and resizes the last column in a table to fit the table width.- Parameters:
table- The table to resize the last column.
resizeColumns
Packs the tree table columns and resizes the last column in a table to fit the table width.- Parameters:
tree- The tree table to resize the last column.
addTableColumnResizer
Adds a table column re-sizer to make the last column resize with the table and dialog box.- Parameters:
table- The table to resize the last column.
addTreeColumnResizer
Adds a table column re-sizer to make the last column resize with the table and dialog box.- Parameters:
tree- The tree to resize the last column.
addTableSorter
addEditableTableColumn
public static TableEditor addEditableTableColumn(Table table, int column, int minimumWidth, ModifyListener modifyListener) Adds an editable column for a table.- Parameters:
table- The table.column- The column index.minimumWidth- The minimum pixel width of the Text editor (for layout).modifyListener- Possible listener for entry field Text modifications.- Returns:
- The table editor created.
getEditedTableLine
public static int getEditedTableLine()Gets the edited line number of a Table Editor.getEditedTableText
Gets the entry field being edited, null for none.createImage
Create an image of a color.- Parameters:
rgb- RGB value color.width- Width of image.height- Height of image.- Returns:
- The image filled with the color.
createImage
Create an image of a color.- Parameters:
rgb- RGB value color.width- Width of image.height- Height of image.doFrame- If the image should be framed.- Returns:
- The image filled with the color.
createImage
Create an image of a color.- Parameters:
r- Red color of image (0-255).g- Green color of image (0-255).b- Blue color of image (0-255).width- Width of image.height- Height of image.- Returns:
- The image filled with the color.
createImage
Create an image of a color.- Parameters:
r- Red color of image (0-255).g- Green color of image (0-255).b- Blue color of image (0-255).width- Width of image.height- Height of image.doFrame- If the image should be framed.- Returns:
- The image filled with the color.
createImage
createImage
showPopupMenu
showPopupMenu
showPopupMenu
showPopupMenu
showPopupMenu
showPopupMenu
showPopupMenu
Displays a drop-down menu at screen location.showPopupMenu
Displays a drop-down menu at screen location.showPopupMenu
Displays a drop-down menu at screen location where mouse is located.showPopupMenu
Displays a drop-down menu at screen location where mouse is located.expandAll
Performs the Expand all on a tree viewer, very fast.getFocusControl
fixComboMWScroll
Fix for Combobox processing mouse wheel when not focused in Win32, eating mouse from scroll pane.setEnabledRecursive
Enables or disables a control/composite and all its children.- Parameters:
control- The control or composite.isEnabled- Enabled flag.
addMenuSeparator
enableDialogMove
Enables move of a dialog box.- Parameters:
shell- The shell that should be movable.
addCapsLockWarning
Adds a caps-lock warning decorator to a password field. If you call this method multiple times for the same password field, nothing will happen (except for the first time).- Parameters:
passwordField- The password field.
getEclipseVersion
public static org.osgi.framework.Version getEclipseVersion()Attempts to get the version of the Eclipse IDE we're running in.- Returns:
- The version, or null if it couldn't be detected.
createBrowser
Creates a Browser instance that uses Edge under Windows if Eclipse is of version 4.21 or better and Edge is installed. If the environment variable "com.iizi.browser" is set to either "default", "edge" or "webkit", that type of browser will be used (the string value of the environment variable is case insensitive).- Parameters:
parent- The parent composite.background- The background color.- Returns:
- The browser instance.
- Throws:
SWTException- When the Browser fails its first operation, which runs here only with a background: e.g. when WebView2's creation timed out ("Waiting for Edge operation to terminate timed out"). The Browser is disposed of first, so that the parent does not keep it; any other failure of that operation is thrown the same way. Without a background no operation runs here, and such a failure surfaces at the caller's first operation on the Browser.
createBrowserOrCompositeForFailure
Creates a Browser Composite if possible, otherwise in case of an exception, a Composite wrapped read-only multi-line entry field instead of a browser.- Parameters:
parent- The parent composite.background- The background color.- Returns:
- The composite, potentially initiated with the background color. The exception is logged, the Browser of the failed creation is disposed and a replacement Composite is returned: the parent then holds the replacement only (see
retryBrowserOnce(Composite, Color, Consumer)). The returned composite can be tested usingif ( cnr instanceof Browser browser ) ...to handle failures of the browser.
retryBrowserOnce
public static void retryBrowserOnce(Composite replacement, Color background, Consumer<Browser> onBrowser) Retries once the creation of a Browser thatcreateBrowserOrCompositeForFailure(Composite, Color)replaced by its replacement Composite, e.g. after WebView2's creation timed out. The retry runs later on the UI thread (Display.asyncExec(Runnable)), once the failed operation has ended, never in the caller's stack.- When it gets a Browser, the Browser takes the replacement's place in the parent (its position among the children and its layout data), the replacement is disposed,
onBrowseris called with the Browser and the parent is laid out again. - When it fails again, the parent keeps the first replacement with its message, and nothing else.
- Nothing is done when the replacement has been disposed in between (its owner has gone, e.g. the editor was closed), or when it is a Browser.
- Parameters:
replacement- The replacement Composite returned bycreateBrowserOrCompositeForFailure(Composite, Color).background- The background color, as for the first creation, nullable.onBrowser- Called with the new Browser once it has taken the replacement's place.
- When it gets a Browser, the Browser takes the replacement's place in the parent (its position among the children and its layout data), the replacement is disposed,
isUsingMSIE
public static boolean isUsingMSIE()Returns if Eclipse uses Microsoft Internet Explorer (11) or not for sure, or if the default browser is being used. This value is always false if such a browser instance never has been created, and always false on non-Windows platforms (macOS/Linux never use MSIE).- Returns:
- true If Microsoft Internet Explorer has been used previously for WebViews and is the candidate for default WebView usage.
getBrowserType
public static int getBrowserType()Cached value for browser supported:0 = not tested yet, 1 = use default, 2 = use Microsoft Edge, 3 = use WebKit.
- Returns:
- The browser type as described above.