Class LinkFactory
Link
. This offers several benefits over creating Link objects via the
new operator:
- The same factory can be used many times to create several Link instances
- The setters all return "this", allowing them to be chained
- This class accepts a Lambda for
SelectionEvent
(seeonSelect(java.util.function.Consumer<org.eclipse.swt.events.SelectionEvent>)
)
Link link = LinkFactory.newLink(SWT.NONE) // .text("Click me!") // .onSelect(event -> clicked(event)) // .layoutData(gridData) // .create(parent);
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)) .layout(gridDataFactory::create); 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.
- Since:
- 3.21
-
Method Summary
Modifier and TypeMethodDescriptionstatic LinkFactory
newLink
(int style) Creates a new factory with the given style.onSelect
(Consumer<SelectionEvent> consumer) Creates aSelectionListener
and registers it for the widgetSelected event.Sets the receiver's text.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
-
Method Details
-
newLink
Creates a new factory with the given style. Refer toLink(Composite, int)
for possible styles.- Returns:
- a new LinkFactory instance
-
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.
- Parameters:
text
- the text- Returns:
- this
- See Also:
-
onSelect
Creates aSelectionListener
and registers it for the widgetSelected event. If the receiver is selected by the user the given consumer is invoked. TheSelectionEvent
is passed to the consumer.- Parameters:
consumer
- the consumer whose accept method is called- Returns:
- this
- See Also:
-