Class LinkFactory

public final class LinkFactory extends AbstractControlFactory<LinkFactory,Link>
This class provides a convenient shorthand for creating and initializing Link. This offers several benefits over creating Link objects via the new operator: Example usage:
 Link link = LinkFactory.newLink(SWT.NONE) //
                .text("Click me!") //
                .onSelect(event -> clicked(event)) //
                .layoutData(gridData) //

The above example creates a link with a text, registers a SelectionListener and finally creates the link in "parent".

 GridDataFactory gridDataFactory = GridDataFactory.swtDefaults();
 LinkFactory linkFactory = LinkFactory.newLink(SWT.PUSH).onSelect(event -> clicked(event))
 linkFactory.text("Link 1").create(parent);
 linkFactory.text("Link 2").create(parent);
 linkFactory.text("Link 3").create(parent);

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

  • Method Details

    • newLink

      public static LinkFactory newLink(int style)
      Creates a new factory with the given style. Refer to Link(Composite, int) for possible styles.
      a new LinkFactory instance
    • text

      public LinkFactory text(String text)
      Sets the receiver's text.

      This method sets the label. The label may include the mnemonic character but must not contain line delimiters.

      Mnemonics are indicated by an '&' that causes the next character to be the mnemonic. When the user presses a key sequence that matches the mnemonic, a selection event occurs. On most platforms, the mnemonic appears underlined but may be emphasized in a platform specific manner. The mnemonic indicator character '&' can be escaped by doubling it in the string, causing a single '&' to be displayed.

      text - the text
      See Also:
    • onSelect

      public LinkFactory 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.
      consumer - the consumer whose accept method is called
      See Also: