Package org.eclipse.ui.forms.widgets
Class SectionFactory
java.lang.Object
org.eclipse.jface.widgets.AbstractWidgetFactory<F,C,Composite>
org.eclipse.jface.widgets.AbstractControlFactory<F,C>
org.eclipse.jface.widgets.AbstractCompositeFactory<SectionFactory,Section>
org.eclipse.ui.forms.widgets.SectionFactory
This class provides a convenient shorthand for creating and initializing
Section
. This offers several benefits over creating Section normal
way:
- The same factory can be used many times to create several Section instances
- The setters on SectionFactory all return "this", allowing them to be chained
- SectionFactory accepts a Lambda for
ExpansionEvent
(seeonExpanded(Consumer)
) andonExpanding(Consumer)
Section section = SectionFactory.newSection(Section.TWISTIE | Section.DESCRIPTION) // .title("My Section") // .description("My section created with a factory") // .onExpand(event -> sectionExpanded(event)) // .create(parent);
The above example creates a section with a title, a description, registers an IExpansionListener and finally creates the section in "parent".
SectionFactory sectionFactory = SectionFactory.newSection(Section.TWISTIE); sectionFactory.title("Section 1").create(parent); sectionFactory.title("Section 2").create(parent); sectionFactory.title("Section 3").create(parent);
The above example creates three section using the same instance of SectionFactory.
- Since:
- 3.10
-
Method Summary
Modifier and TypeMethodDescriptiondescription
(String description) Sets the description text.description
(Function<Section, Control> controlFunction) Sets a function which must provide a description control for the given Section.static SectionFactory
newSection
(int style) Creates a new SectionFactory with the given style.onExpanded
(Consumer<ExpansionEvent> consumer) Creates anIExpansionListener
and registers it for the expansionStateChanged event.onExpanding
(Consumer<ExpansionEvent> consumer) Creates anIExpansionListener
and registers it for the expansionStateChanging event.Sets the title of the section.Methods inherited from class org.eclipse.jface.widgets.AbstractCompositeFactory
layout
Methods inherited from class org.eclipse.jface.widgets.AbstractControlFactory
background, enabled, font, foreground, layoutData, orientation, supplyLayoutData, tooltip
Methods inherited from class org.eclipse.jface.widgets.AbstractWidgetFactory
addProperty, cast, create, data, data
-
Method Details
-
newSection
Creates a new SectionFactory with the given style. Refer toSection(Composite, int)
for possible styles.- Parameters:
style
- the style to use- Returns:
- a new SectionFactory instance
-
title
Sets the title of the section. The title will act as a hyperlink and activating it will toggle the client between expanded and collapsed state.- Parameters:
title
- the new title string- See Also:
-
description
Sets the description text. Has no effect if DESCRIPTION style was not used inAbstractWidgetFactory.create(P)
- Parameters:
description
- new description text; notnull
- See Also:
-
description
Sets a function which must provide a description control for the given Section. The control must not be null and must be a direct child of the section.This method and
DESCRIPTION
style are mutually exclusive. Use the method only if you want to create the description control yourself.- Parameters:
controlFunction
- the function to create the description control- See Also:
-
onExpanded
Creates anIExpansionListener
and registers it for the expansionStateChanged event. If the section was expanded by the user the given consumer is invoked. TheExpansionEvent
is passed to the consumer.- Parameters:
consumer
- the consumer whose accept method is called- Returns:
- this
- See Also:
-
onExpanding
Creates anIExpansionListener
and registers it for the expansionStateChanging event. If the section is expanded by the user the given consumer is invoked. TheExpansionEvent
is passed to the consumer.- Parameters:
consumer
- the consumer whose accept method is called- Returns:
- this
- See Also:
-