Package org.knime.core.ui.util
Class SWTUtilities
java.lang.Object
org.knime.core.ui.util.SWTUtilities
I did as best a search as i could to find a pre-existing class of this ilk (something that provides SWT related
helper methods and could find none.) Also, i named this
SWTUtilities instead of SWTUtil,
the latter which better obey the majority of the utility class names in this package, because there is already an
internal Eclipse class of that name. It seems plausible that there is this sort of collection of methods
elsewhere; if there isn't, consider moving the graphics-related static utility methods in
org.knime.workbench.editor2.editparts.AnnotationEditPart into this class as well.- Since:
- 3.7
- Author:
- loki der quaeler
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic org.eclipse.swt.widgets.ShellAs discovered in AP-10122, when KNIME receives an action due to mouse event passthrough (a situation possible on macOS where mouse & scroll events can pass to a desktop-visible window even though the owning application is not the application in the foreground), Display.getCurrent().getActiveShell() returns null.static org.eclipse.swt.widgets.ShellgetActiveShell(org.eclipse.swt.widgets.Display display) As discovered in AP-10122, when KNIME receives an action due to mouse event passthrough (a situation possible on macOS where mouse & scroll events can pass to a desktop-visible window even though the owning application is not the application in the foreground), Display.getCurrent().getActiveShell() returns null.static org.eclipse.swt.widgets.ShellThis method can be called after application startup has completed in order to get theShellthat is the parent of the main KAP workbench.static Optional<org.eclipse.swt.graphics.Font>loadFontFromInputStream(InputStream is, int size, int style) This loads a font via our main workbenchDisplay.static Optional<org.eclipse.swt.widgets.Shell>This method is invoked fromKNIMEApplicationWorkbenchAdvisor#postStartup().static voidremoveAllChildren(org.eclipse.swt.widgets.Composite parent) Oh com'on SWT - seriously: why isn't this a method inComposite?static voidspaceReclaimingSetVisible(org.eclipse.swt.widgets.Control widget, boolean visible) I'm not sure why the SWT authors thought implementing 'setVisible(false)' should mean we space should continue to be laid out but just not painted, like the worlds most obvious invisibility cloak...
-
Constructor Details
-
SWTUtilities
public SWTUtilities()
-
-
Method Details
-
markKNIMEShell
This method is invoked fromKNIMEApplicationWorkbenchAdvisor#postStartup(). There's a fair philosophical argument of "if in some edge cases, the shell at this point is null and then we need rely on matching its name to the product, why not always just do that search, as opposed to doing the data-marking here and searching on the data-marking later." My response would be that even if we're forced to walk the shells at this point (thank you very much, SWT) as we've just launched, the chances that some other random shell starting with the product name is also present is much lower (like zero) now than at a later time during the application's lifespan.- Returns:
- The shell identified as the KNIME shell (window)
-
getKNIMEWorkbenchShell
public static org.eclipse.swt.widgets.Shell getKNIMEWorkbenchShell()This method can be called after application startup has completed in order to get theShellthat is the parent of the main KAP workbench.- Returns:
- the
Shellcontaining the main KAP workbench, or null if we failed to mark one at start-up.
-
getActiveShell
public static org.eclipse.swt.widgets.Shell getActiveShell(org.eclipse.swt.widgets.Display display) As discovered in AP-10122, when KNIME receives an action due to mouse event passthrough (a situation possible on macOS where mouse & scroll events can pass to a desktop-visible window even though the owning application is not the application in the foreground), Display.getCurrent().getActiveShell() returns null. This method will attempt to return the applicable Shell instance, by hook or by crook. If you're considering calling this, perhaps you really want to callgetKNIMEWorkbenchShell().- Parameters:
display- an instance of Display which contains the active shell; if this is null, this method will return null- Returns:
- a Shell instance which is the active shell for the application
-
getActiveShell
public static org.eclipse.swt.widgets.Shell getActiveShell()As discovered in AP-10122, when KNIME receives an action due to mouse event passthrough (a situation possible on macOS where mouse & scroll events can pass to a desktop-visible window even though the owning application is not the application in the foreground), Display.getCurrent().getActiveShell() returns null. This method will attempt to return the applicable Shell instance, by hook or by crook.- Returns:
- a Shell instance which is the active shell for the application
-
removeAllChildren
public static void removeAllChildren(org.eclipse.swt.widgets.Composite parent) Oh com'on SWT - seriously: why isn't this a method inComposite?- Parameters:
parent- the Composite instance which will have all of its children removed.- Since:
- 4.0
-
spaceReclaimingSetVisible
public static void spaceReclaimingSetVisible(org.eclipse.swt.widgets.Control widget, boolean visible) I'm not sure why the SWT authors thought implementing 'setVisible(false)' should mean we space should continue to be laid out but just not painted, like the worlds most obvious invisibility cloak... but they did - bless'em.- Parameters:
widget- the widget to make visible or hidden; the widget's layout data must beGridDataor else this method will do nothing more than invokeControl.setVisible(boolean)visible- true to make visible, false to make hidden- Since:
- 4.0
-
loadFontFromInputStream
public static Optional<org.eclipse.swt.graphics.Font> loadFontFromInputStream(InputStream is, int size, int style) This loads a font via our main workbenchDisplay. The SWT method only takes a file path so we need write this font to a temporary file first (and we take anInputStreamas we will be getting this asset usually out of bundle.) The SWT authors swear that once loaded into a given Display, it can be fetched from that Display instance, but this is not what testing bears out; we can still create an instance ofFontreferencing the correct name. We should cache this loading in the future.- Parameters:
is- a stream for a TTF; this will be closed by this methodsize- the desired point size of the fontstyle- e.gSWT.BOLD- Returns:
- an instance of
Optional, populated with an instance ofFontif the load is successful; remember to dispose() when appropriate - Since:
- 4.0
-