public interface ControlWrapper
Control
to encapsulate its API.
The traditional way to make a custom class is this: class CustomControl extends
Composite
This has three main problems:
Composite
interface.Composite
interface.Widget.addListener
to intercept them is a very dangerous plan.ControlWrapper fixes this by providing an low-overhead skeleton which encapsulates the SWT Control that you're using as the base of your custom control, which allows you to only expose the APIs that are appropriate.
Modifier and Type | Interface and Description |
---|---|
static class |
ControlWrapper.AroundControl<T extends Control>
Default implementation of a
ControlWrapper which wraps a Control . |
static class |
ControlWrapper.AroundWrapper<T extends ControlWrapper>
Default implementation of a
ControlWrapper which wraps some other form of `ControlWrapper` with a new interface. |
static class |
ControlWrapper.Transparent<T extends Control> |
Modifier and Type | Method and Description |
---|---|
default void |
dispose()
Disposes the underlying control.
|
default Object |
getLayoutData()
Returns the LayoutData for this control.
|
default Composite |
getParent()
Returns the parent of this Control.
|
Control |
getRootControl()
Returns the wrapped
Control (only appropriate for limited purposes!). |
default Shell |
getShell()
Returns the parent Shell of this Control.
|
default boolean |
isDisposed()
Returns true iff the underlying control is disposed.
|
default void |
setLayoutData(Object layoutData)
Sets the LayoutData for this control.
|
default boolean |
setParent(Composite parent)
Changes the parent of the widget to be the one provided.
|
static <T extends Control> |
transparent(T control)
Most-efficient way to transparently pass a Control to a ControlWrapper API.
|
default void setLayoutData(Object layoutData)
default Object getLayoutData()
default Composite getParent()
default Shell getShell()
default void dispose()
default boolean isDisposed()
default boolean setParent(Composite parent)
true
if the parent is successfully changedControl getRootControl()
Control
(only appropriate for limited purposes!).
The implementor of this ControlWrapper is free to change the wrapped Control as she sees fit, and she doesn't have to tell you about it! You shouldn't rely on this control being anything in particular.
You can rely on this Control for:
But that's all. If you use it for something else, it's on you when it breaks.
static <T extends Control> ControlWrapper.Transparent<T> transparent(T control)