Class FormToolkit
- Direct Known Subclasses:
TabbedPropertySheetWidgetFactory
In addition to being the control factory, the toolkit is also responsible for painting flat borders for select controls, managing hyperlink groups and control colors.
The toolkit creates some of the most common controls used to populate Eclipse
forms. Controls that must be created using their constructors,
adapt()
method is available to change its properties in the
same way as with the supported toolkit controls.
Typically, one toolkit object is created per workbench part (for example, an editor or a form wizard). The toolkit is disposed when the part is disposed. To conserve resources, it is possible to create one color object for the entire plug-in and share it between several toolkits. The plug-in is responsible for disposing the colors (disposing the toolkit that uses shared color object will not dispose the colors).
FormToolkit is normally instantiated, but can also be subclassed if some of
the methods needs to be modified. In those cases, super
must
be called to preserve normal behaviour.
- Since:
- 3.0
-
Field Summary
-
Constructor Summary
ConstructorDescriptionFormToolkit
(Display display) Creates a toolkit that is self-sufficient (will manage its own colors).FormToolkit
(FormColors colors) Creates a toolkit that will use the provided (shared) colors. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adapts a composite to be used in a form associated with this toolkit.void
Adapts a control to be used in a form that is associated with this toolkit.createButton
(Composite parent, String text, int style) Creates a button as a part of the form.createComposite
(Composite parent) Creates the composite as a part of the form.createComposite
(Composite parent, int style) Creates the composite as part of the form using the provided style.createCompositeSeparator
(Composite parent) Creates the composite that can server as a separator between various parts of a form.createExpandableComposite
(Composite parent, int expansionStyle) Creates an expandable composite as a part of the form.createForm
(Composite parent) Creates a form widget in the provided parent.createFormText
(Composite parent, boolean trackFocus) Creates a rich text as a part of the form.createHyperlink
(Composite parent, String text, int style) Creates a hyperlink as a part of the form.createImageHyperlink
(Composite parent, int style) Creates an image hyperlink as a part of the form.createLabel
(Composite parent, String text) Creates a label as a part of the form.createLabel
(Composite parent, String text, int style) Creates a label as a part of the form.createPageBook
(Composite parent, int style) Creates a scrolled page book widget as a part of the form.createScrolledForm
(Composite parent) Creates a scrolled form widget in the provided parent.createSection
(Composite parent, int sectionStyle) Creates a section as a part of the form.createSeparator
(Composite parent, int style) Creates a separator label as a part of the form.createTable
(Composite parent, int style) Creates a table as a part of the form.createText
(Composite parent, String value) Creates a text as a part of the form.createText
(Composite parent, String value, int style) Creates a text as a part of the form.createTree
(Composite parent, int style) Creates a tree widget as a part of the form.void
decorateFormHeading
(Form form) Takes advantage of the gradients and other capabilities to decorate the form heading using colors computed based on the current skin and operating system.void
dispose()
Disposes the toolkit.static void
A helper method that ensures the provided control is visible when ScrolledComposite is somewhere in the parent chain.int
Returns the margin required around the children whose border is being painted by the toolkit usingpaintBordersFor(Composite)
.int
Returns the border style used for various widgets created by this toolkit.Returns the colors used by this toolkit.Returns the hyperlink group that manages hyperlinks for this toolkit.int
Returns the orientation that all the widgets created by this toolkit will inherit, if set.void
paintBordersFor
(Composite parent) Paints flat borders for widgets created by this toolkit within the provided parent.void
Refreshes the hyperlink colors by loading from JFace settings.void
setBackground
(Color bg) Sets the background color for the entire toolkit.void
setBorderStyle
(int style) Sets the border style to be used when creating widgets.static void
setControlVisible
(Control c, boolean verticalOnly) A utility method that ensures that the control is visible in the scrolled composite.void
setOrientation
(int orientation) Sets the orientation that all the widgets created by this toolkit will inherit.
-
Field Details
-
KEY_DRAW_BORDER
- See Also:
-
TREE_BORDER
- See Also:
-
TEXT_BORDER
- See Also:
-
-
Constructor Details
-
FormToolkit
Creates a toolkit that is self-sufficient (will manage its own colors).Clients that call this method must call
dispose()
when they are finished using the toolkit. -
FormToolkit
Creates a toolkit that will use the provided (shared) colors. The toolkit will dispose the colors if and only if they are not marked as shared via themarkShared()
method.Clients that call this method must call
dispose()
when they are finished using the toolkit.- Parameters:
colors
- the shared colors
-
-
Method Details
-
createButton
Creates a button as a part of the form.- Parameters:
parent
- the button parenttext
- an optional text for the button (can benull
)style
- the button style (for example,SWT.PUSH
)- Returns:
- the button widget
-
createComposite
Creates the composite as a part of the form.- Parameters:
parent
- the composite parent- Returns:
- the composite widget
-
createComposite
Creates the composite as part of the form using the provided style.- Parameters:
parent
- the composite parentstyle
- the composite style- Returns:
- the composite widget
-
createCompositeSeparator
Creates the composite that can server as a separator between various parts of a form. Separator height should be controlled by setting the height hint on the layout data for the composite.- Parameters:
parent
- the separator parent- Returns:
- the separator widget
-
createLabel
Creates a label as a part of the form.- Parameters:
parent
- the label parenttext
- the label text- Returns:
- the label widget
-
createLabel
Creates a label as a part of the form.- Parameters:
parent
- the label parenttext
- the label textstyle
- the label style- Returns:
- the label widget
-
createHyperlink
Creates a hyperlink as a part of the form. The hyperlink will be added to the hyperlink group that belongs to this toolkit.- Parameters:
parent
- the hyperlink parenttext
- the text of the hyperlinkstyle
- the hyperlink style- Returns:
- the hyperlink widget
-
createImageHyperlink
Creates an image hyperlink as a part of the form. The hyperlink will be added to the hyperlink group that belongs to this toolkit.- Parameters:
parent
- the hyperlink parentstyle
- the hyperlink style- Returns:
- the image hyperlink widget
-
createFormText
Creates a rich text as a part of the form.- Parameters:
parent
- the rich text parenttrackFocus
- iftrue
, the toolkit will monitor focus transfers to ensure that the hyperlink in focus is visible in the form.- Returns:
- the rich text widget
-
adapt
Adapts a control to be used in a form that is associated with this toolkit. This involves adjusting colors and optionally adding handlers to ensure focus tracking and keyboard management.- Parameters:
control
- a control to adapttrackFocus
- iftrue
, form will be scrolled horizontally and/or vertically if needed to ensure that the control is visible when it gains focus. Set it tofalse
if the control is not capable of gaining focus.trackKeyboard
- iftrue
, the control that is capable of gaining focus will be tracked for certain keys that are important to the underlying form (for example, PageUp, PageDown, ScrollUp, ScrollDown etc.). Set it tofalse
if the control is not capable of gaining focus or these particular key event are already used by the control.
-
adapt
Adapts a composite to be used in a form associated with this toolkit.- Parameters:
composite
- the composite to adapt
-
ensureVisible
A helper method that ensures the provided control is visible when ScrolledComposite is somewhere in the parent chain. If scroll bars are visible and the control is clipped, the client of the scrolled composite will be scrolled to reveal the control.- Parameters:
c
- the control to reveal
-
createSection
Creates a section as a part of the form.- Parameters:
parent
- the section parentsectionStyle
- the section style- Returns:
- the section widget
-
createExpandableComposite
Creates an expandable composite as a part of the form.- Parameters:
parent
- the expandable composite parentexpansionStyle
- the expandable composite style- Returns:
- the expandable composite widget
-
createSeparator
Creates a separator label as a part of the form.- Parameters:
parent
- the separator parentstyle
- the separator style- Returns:
- the separator label
-
createTable
Creates a table as a part of the form.- Parameters:
parent
- the table parentstyle
- the table style- Returns:
- the table widget
-
createText
Creates a text as a part of the form.- Parameters:
parent
- the text parentvalue
- the text initial value- Returns:
- the text widget
-
createText
Creates a text as a part of the form.- Parameters:
parent
- the text parentvalue
- the text initial valuestyle
- the text style- Returns:
- the text widget
-
createTree
Creates a tree widget as a part of the form.- Parameters:
parent
- the tree parentstyle
- the tree style- Returns:
- the tree widget
-
createScrolledForm
Creates a scrolled form widget in the provided parent. If you do not require scrolling because there is already a scrolled composite up the parent chain, use 'createForm' instead.- Parameters:
parent
- the scrolled form parent- Returns:
- the form that can scroll itself
- See Also:
-
createForm
Creates a form widget in the provided parent. Note that this widget does not scroll its content, so make sure there is a scrolled composite up the parent chain. If you require scrolling, use 'createScrolledForm' instead.- Parameters:
parent
- the form parent- Returns:
- the form that does not scroll
- See Also:
-
decorateFormHeading
Takes advantage of the gradients and other capabilities to decorate the form heading using colors computed based on the current skin and operating system.- Parameters:
form
- the form to decorate- Since:
- 3.3
-
createPageBook
Creates a scrolled page book widget as a part of the form.- Parameters:
parent
- the page book parentstyle
- the text style- Returns:
- the scrolled page book widget
-
dispose
public void dispose()Disposes the toolkit. -
getHyperlinkGroup
Returns the hyperlink group that manages hyperlinks for this toolkit.- Returns:
- the hyperlink group
-
setBackground
Sets the background color for the entire toolkit. The method delegates the call to the FormColors object and also updates the hyperlink group so that hyperlinks and other objects are in sync.- Parameters:
bg
- the new background color
-
refreshHyperlinkColors
public void refreshHyperlinkColors()Refreshes the hyperlink colors by loading from JFace settings. -
paintBordersFor
Paints flat borders for widgets created by this toolkit within the provided parent. Borders will not be painted if the global border style is SWT.BORDER (i.e. if native borders are used). Call this method during creation of a form composite to get the borders of its children painted. Care should be taken when selection layout margins. At least one pixel margin width and height must be chosen to allow the toolkit to paint the border on the parent around the widgets.Borders are painted for some controls that are selected by the toolkit by default. If a control needs a border but is not on its list, it is possible to force borders in the following ways:
widget.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER); or widget.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
If borders would normally be painted for a control, but they are not wanted, it is possible to suppress them in the following way:
widget.setData(FormToolkit.KEY_DRAW_BORDER, Boolean.FALSE);
- Parameters:
parent
- the parent that owns the children for which the border needs to be painted.
-
getColors
Returns the colors used by this toolkit.- Returns:
- the color object
-
getBorderStyle
public int getBorderStyle()Returns the border style used for various widgets created by this toolkit. The intent of the toolkit is to create controls with styles that yield a 'flat' appearance. On systems where the native borders are already flat, we set the style to SWT.BORDER and don't paint the borders ourselves. Otherwise, the style is set to SWT.NULL, and borders are painted by the toolkit.- Returns:
- the global border style
-
getBorderMargin
public int getBorderMargin()Returns the margin required around the children whose border is being painted by the toolkit usingpaintBordersFor(Composite)
. Since the border is painted around the controls on the parent, a number of pixels needs to be reserved for this border. For windowing systems where the native border is used, this margin is 0.- Returns:
- the margin in the parent when children have their border painted
- Since:
- 3.3
-
setBorderStyle
public void setBorderStyle(int style) Sets the border style to be used when creating widgets. The toolkit chooses the correct style based on the platform but this value can be changed using this method.- Parameters:
style
-SWT.BORDER
orSWT.NULL
- See Also:
-
setControlVisible
A utility method that ensures that the control is visible in the scrolled composite. The prerequisite for this method is that the control has a class that extends ScrolledComposite somewhere in the parent chain. If the control is partially or fully clipped, the composite is scrolled to set by setting the origin to the control origin.- Parameters:
c
- the control to make visibleverticalOnly
- iftrue
, the scrolled composite will be scrolled only vertically if needed. Otherwise, the scrolled composite origin will be set to the control origin.- Since:
- 3.1
-
getOrientation
public int getOrientation()Returns the orientation that all the widgets created by this toolkit will inherit, if set. Can beSWT.NULL
,SWT.LEFT_TO_RIGHT
andSWT.RIGHT_TO_LEFT
.- Returns:
- orientation style for this toolkit, or
SWT.NULL
if not set. The default orientation is inherited from the Window default orientation. - Since:
- 3.1
- See Also:
-
setOrientation
public void setOrientation(int orientation) Sets the orientation that all the widgets created by this toolkit will inherit. Can beSWT.NULL
,SWT.LEFT_TO_RIGHT
andSWT.RIGHT_TO_LEFT
.- Parameters:
orientation
- style for this toolkit.- Since:
- 3.1
-