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 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` (see `onExpanded(Consumer)`) and `onExpanding(Consumer)`

Example usage:

     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 Type
Method
Description
`SectionFactory`
`description(String description)`
Sets the description text.
`SectionFactory`
`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.
`SectionFactory`
`onExpanded(Consumer<ExpansionEvent> consumer)`
Creates an `IExpansionListener` and registers it for the expansionStateChanged event.
`SectionFactory`
`onExpanding(Consumer<ExpansionEvent> consumer)`
Creates an `IExpansionListener` and registers it for the expansionStateChanging event.
`SectionFactory`
`title(String title)`
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`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Method Details

### newSection

public static SectionFactory newSection(int style)
Creates a new SectionFactory with the given style. Refer to `Section(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 in `AbstractWidgetFactory.create(P)`

Parameters:
  `description` - new description text; not `null`
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 `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:
  - `Section.setDescriptionControl(Control)`

### onExpanded

public SectionFactory onExpanded(Consumer<ExpansionEvent> consumer)
Creates an `IExpansionListener` and registers it for the expansionStateChanged event. If the section was expanded by the user the given consumer is invoked. The `ExpansionEvent` is 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 an `IExpansionListener` and registers it for the expansionStateChanging event. If the section is expanded by the user the given consumer is invoked. The `ExpansionEvent` is passed to the consumer.

Parameters:
  `consumer` - the consumer whose accept method is called
Returns:
  this
See Also:
  - `ExpandableComposite.addExpansionListener(IExpansionListener)`
  - `IExpansionListener.expansionStateChanging(ExpansionEvent)`