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
-
public final class SectionFactory extends org.eclipse.jface.widgets.AbstractCompositeFactory<SectionFactory,Section>
This class provides a convenient shorthand for creating and initializingSection. 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SectionFactorydescription(String description)Sets the description text.SectionFactorydescription(Function<Section,Control> controlFunction)Sets a function which must provide a description control for the given Section.static SectionFactorynewSection(int style)Creates a new SectionFactory with the given style.SectionFactoryonExpanded(Consumer<ExpansionEvent> consumer)Creates anIExpansionListenerand registers it for the expansionStateChanged event.SectionFactoryonExpanding(Consumer<ExpansionEvent> consumer)Creates anIExpansionListenerand registers it for the expansionStateChanging event.SectionFactorytitle(String title)Sets the title of the section.-
Methods inherited from class org.eclipse.jface.widgets.AbstractControlFactory
background, enabled, font, foreground, layoutData, orientation, supplyLayoutData, tooltip
-
-
-
-
Method Detail
-
newSection
public static SectionFactory newSection(int style)
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
public SectionFactory title(String 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:
ExpandableComposite.setText(String)
-
description
public SectionFactory description(String 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:
Section.setDescription(String)
-
description
public SectionFactory description(Function<Section,Control> controlFunction)
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
DESCRIPTIONstyle 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:
Section.setDescriptionControl(Control)
-
onExpanded
public SectionFactory onExpanded(Consumer<ExpansionEvent> consumer)
Creates anIExpansionListenerand registers it for the expansionStateChanged event. If the section was expanded by the user the given consumer is invoked. TheExpansionEventis passed to the consumer.- Parameters:
consumer- the consumer whose accept method is called- Returns:
- this
- See Also:
ExpandableComposite.addExpansionListener(IExpansionListener),IExpansionListener.expansionStateChanged(ExpansionEvent)
-
onExpanding
public SectionFactory onExpanding(Consumer<ExpansionEvent> consumer)
Creates anIExpansionListenerand registers it for the expansionStateChanging event. If the section is expanded by the user the given consumer is invoked. TheExpansionEventis passed to the consumer.- Parameters:
consumer- the consumer whose accept method is called- Returns:
- this
- See Also:
ExpandableComposite.addExpansionListener(IExpansionListener),IExpansionListener.expansionStateChanging(ExpansionEvent)
-
-