Package org.eclipse.jface.widgets

# Class SashFactory

java.lang.Object
org.eclipse.jface.widgets.AbstractWidgetFactory<F,C,Composite>
org.eclipse.jface.widgets.AbstractControlFactory<SashFactory,Sash>
org.eclipse.jface.widgets.SashFactory

public final class SashFactory extends AbstractControlFactory<SashFactory,Sash>
This class provides a convenient shorthand for creating and initializing `Sash`. This offers several benefits over creating Sash normal way:

- The same factory can be used many times to create several Sash instances
- The setters on SashFactory all return "this", allowing them to be chained
- SashFactory accepts a Lambda for `SelectionEvent` (see `onSelect(java.util.function.Consumer<org.eclipse.swt.events.SelectionEvent>)`)

Example usage:

     Sash sash = SashFactory.newSash(SWT.HORIZONTAL) //
                    .onSelect(event -> sashSelected(event)) //
                    .layoutData(gridData) //
                    .create(parent);

The above example creates a horizontal sash, registers a SelectionListener and finally creates the sash in "parent".

     GridDataFactory gridDataFactory = GridDataFactory.swtDefaults();
     SashFactory sashFactory = SashFactory.newSash(SWT.HORIZONTAL).onSelect(event -> sashSelected(event))
                    .layout(gridDataFactory::create);
     sashFactory.data("Sash 1").create(parent);
     sashFactory.data("Sash 2").create(parent);
     sashFactory.data("Sash 3").create(parent);

The above example creates three sashs using the same instance of SashFactory. Note the layout method. A Supplier is used to create unique GridData for every single sash.

Since:
  3.21

## Method Summary

Modifier and Type
Method
Description
`static SashFactory`
`newSash(int style)`
Creates a new SashFactory with the given style.
`SashFactory`
`onSelect(Consumer<SelectionEvent> consumer)`
Creates a `SelectionListener` and registers it for the widgetSelected event.

### 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`

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

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

## Method Details

### newSash

public static SashFactory newSash(int style)
Creates a new SashFactory with the given style. Refer to `Sash(Composite, int)` for possible styles.

Returns:
  a new SashFactory instance

### onSelect

public SashFactory onSelect(Consumer<SelectionEvent> consumer)
Creates a `SelectionListener` and registers it for the widgetSelected event. If the receiver is selected by the user the given consumer is invoked. The `SelectionEvent` is passed to the consumer.

Parameters:
  `consumer` - the consumer whose accept method is called
Returns:
  this
See Also:
  - `Sash.addSelectionListener(SelectionListener)`
  - `SelectionListener.widgetSelectedAdapter(Consumer)`