# Class ShellFactory

java.lang.Object
org.eclipse.jface.widgets.AbstractWidgetFactory<ShellFactory, Shell, Composite>
org.eclipse.jface.widgets.AbstractControlFactory<ShellFactory, Shell>
org.eclipse.jface.widgets.AbstractCompositeFactory<ShellFactory, Shell>
org.eclipse.jface.widgets.ShellFactory

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

- The same factory can be used many times to create several Shell instances
- The setters on ShellFactory all return "this", allowing them to be chained

Example usage:

    Shell shell = ShellFactory.newShell(SWT.BORDER) //
                    .text("My Shell") //
                    .maximized(true) //
                    .create(parent);

The above example creates a maximized shell with a text and creates the shell in "parent". Where "parent" has to be another shell.

    GridDataFactory gridDataFactory = GridDataFactory.swtDefaults();
    ShellFactory shellFactory = ShellFactory.newShell(SWT.PUSH).layout(gridDataFactory::create);
    shellFactory.text("Shell 1").create(parent);
    shellFactory.text("Shell 2").create(parent);
    shellFactory.text("Shell 3").create(parent);

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

Since:
  3.21

## Method Summary

Modifier and Type
Method
Description
`final Shell`
`create(Display display)`
Creates the shell in the given display.
`ShellFactory`
`fullScreen(boolean fullScreen)`
Sets the full screen state of the receiver.
`ShellFactory`
`maximized(boolean maximized)`
Sets the maximized state of the receiver.
`ShellFactory`
`menuBar(Function<Decorations, Menu> menuFunction)`
Sets the shell's menu bar by a `Function`.
`ShellFactory`
`minimized(boolean minimized)`
Sets the minimized stated of the receiver.
`static ShellFactory`
`newShell(int style)`
Creates a new ShellFactory with the given style.
`ShellFactory`
`onActivate(Consumer<ShellEvent> consumer)`
Creates a `ShellListener` and registers it for the activated event.
`ShellFactory`
`onClose(Consumer<ShellEvent> consumer)`
Creates a `ShellListener` and registers it for the closed event.
`ShellFactory`
`onDeactivate(Consumer<ShellEvent> consumer)`
Creates a `ShellListener` and registers it for the deactivated event.
`ShellFactory`
`onDeiconify(Consumer<ShellEvent> consumer)`
Creates a `ShellListener` and registers it for the deiconified (un-minimized) event.
`ShellFactory`
`onIconify(Consumer<ShellEvent> consumer)`
Creates a `ShellListener` and registers it for the iconified (minimized) event.
`ShellFactory`
`text(String text)`
Sets the receiver's text, which is the string that the window manager will typically display as the receiver's title, to the argument, which must not be null.

### Methods inherited from class AbstractCompositeFactory

`layout`

### Methods inherited from class AbstractControlFactory

`background, enabled, font, foreground, layoutData, orientation, supplyLayoutData, tooltip`

### Methods inherited from class AbstractWidgetFactory

`addProperty, cast, create, data, data`

### Methods inherited from class Object

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

## Method Details

### create

public final Shell create(Display display)
Creates the shell in the given display.

Returns:
  the created shell
Since:
  3.28

### newShell

public static ShellFactory newShell(int style)
Creates a new ShellFactory with the given style. Refer to `Shell(Shell, int)` for possible styles.

Returns:
  a new ShellFactory instance

### text

public ShellFactory text(String text)
Sets the receiver's text, which is the string that the window manager will typically display as the receiver's title, to the argument, which must not be null.

Note: If control characters like '\n', '\t' etc. are used in the string, then the behavior is platform dependent.

Returns:
  this
See Also:
  - `Decorations.setText(String)`

### minimized

public ShellFactory minimized(boolean minimized)
Sets the minimized stated of the receiver. If the argument is `true` causes the receiver to switch to the minimized state, and if the argument is `false` and the receiver was previously minimized, causes the receiver to switch back to either the maximized or normal states.

Note: The result of intermixing calls to `setMaximized(true)` and `setMinimized(true)` will vary by platform. Typically, the behavior will match the platform user's expectations, but not always. This should be avoided if possible.

Parameters:
  `minimized` - the new minimized state
Returns:
  this
See Also:
  - `Decorations.setMinimized(boolean)`
  - `Decorations.setMaximized(boolean)`

### maximized

public ShellFactory maximized(boolean maximized)
Sets the maximized state of the receiver. If the argument is `true` causes the receiver to switch to the maximized state, and if the argument is `false` and the receiver was previously maximized, causes the receiver to switch back to either the minimized or normal states.

Note: The result of intermixing calls to `setMaximized(true)` and `setMinimized(true)` will vary by platform. Typically, the behavior will match the platform user's expectations, but not always. This should be avoided if possible.

Parameters:
  `maximized` - the new maximized state
Returns:
  this
See Also:
  - `Decorations.setMinimized(boolean)`
  - `Decorations.setMaximized(boolean)`

### fullScreen

public ShellFactory fullScreen(boolean fullScreen)
Sets the full screen state of the receiver. If the argument is `true` causes the receiver to switch to the full screen state, and if the argument is `false` and the receiver was previously switched into full screen state, causes the receiver to switch back to either the maximized or normal states.

Note: The result of intermixing calls to `setFullScreen(true)`, `setMaximized(true)` and `setMinimized(true)` will vary by platform. Typically, the behavior will match the platform user's expectations, but not always. This should be avoided if possible.

Parameters:
  `fullScreen` - the new fullscreen state
Returns:
  this
See Also:
  - `Shell.setFullScreen(boolean)`

### menuBar

public ShellFactory menuBar(Function<Decorations, Menu> menuFunction)
Sets the shell's menu bar by a `Function`. Implemented as callback since the shell itself is needed to create the menu.

    Shell shell = ShellFactory.newShell(SWT.BORDER) //
                    .text("My Shell") //
                    .menuBar(shell -> new Menu(shell, SWT.BAR)) //
                    .create(parent);

Or with more logic to create the menu (e.g. add items):

    Shell shell = ShellFactory.newShell(SWT.BORDER) //
                    .text("My Shell") //
                    .menuBar(this::fillMenu) //
                    .create(parent);

Parameters:
  `menuFunction` - the function (or lambda) to create the menu for the given shell
Returns:
  this
See Also:
  - `Decorations.setMenuBar(org.eclipse.swt.widgets.Menu)`

### onActivate

public ShellFactory onActivate(Consumer<ShellEvent> consumer)
Creates a `ShellListener` and registers it for the activated event. If event is raised it calls the given consumer. The `ShellEvent` is passed to the consumer.

Parameters:
  `consumer` - the consumer whose accept method is called
Returns:
  this
See Also:
  - `Shell.addShellListener(ShellListener)`
  - `ShellListener.shellActivatedAdapter(Consumer)`

### onDeactivate

public ShellFactory onDeactivate(Consumer<ShellEvent> consumer)
Creates a `ShellListener` and registers it for the deactivated event. If event is raised it calls the given consumer. The `ShellEvent` is passed to the consumer.

Parameters:
  `consumer` - the consumer whose accept method is called
Returns:
  this
See Also:
  - `Shell.addShellListener(ShellListener)`
  - `ShellListener.shellDeactivatedAdapter(Consumer)`

### onIconify

public ShellFactory onIconify(Consumer<ShellEvent> consumer)
Creates a `ShellListener` and registers it for the iconified (minimized) event. If event is raised it calls the given consumer. The `ShellEvent` is passed to the consumer.

Parameters:
  `consumer` - the consumer whose accept method is called
Returns:
  this
See Also:
  - `Shell.addShellListener(ShellListener)`
  - `ShellListener.shellIconifiedAdapter(Consumer)`

### onDeiconify

public ShellFactory onDeiconify(Consumer<ShellEvent> consumer)
Creates a `ShellListener` and registers it for the deiconified (un-minimized) event. If event is raised it calls the given consumer. The `ShellEvent` is passed to the consumer.

Parameters:
  `consumer` - the consumer whose accept method is called
Returns:
  this
See Also:
  - `Shell.addShellListener(ShellListener)`
  - `ShellListener.shellDeiconifiedAdapter(Consumer)`

### onClose

public ShellFactory onClose(Consumer<ShellEvent> consumer)
Creates a `ShellListener` and registers it for the closed event. If event is raised it calls the given consumer. The `ShellEvent` is passed to the consumer.

Parameters:
  `consumer` - the consumer whose accept method is called
Returns:
  this
See Also:
  - `Shell.addShellListener(ShellListener)`
  - `ShellListener.shellClosedAdapter(Consumer)`