Package org.eclipse.jface.widgets
Class TreeFactory
java.lang.Object
org.eclipse.jface.widgets.AbstractWidgetFactory<F,C,Composite>
org.eclipse.jface.widgets.AbstractControlFactory<TreeFactory,Tree>
org.eclipse.jface.widgets.TreeFactory
This class provides a convenient shorthand for creating and initializing
Tree
. This offers several benefits over creating Tree normal way:
- The same factory can be used many times to create several Tree instances
- The setters on TreeFactory all return "this", allowing them to be chained
- TreeFactory accepts a Lambda for
SelectionEvent
(seeonSelect(java.util.function.Consumer<org.eclipse.swt.events.SelectionEvent>)
) - TreeFactory accepts a Lambda for
TreeEvent
(seeonExpand(java.util.function.Consumer<org.eclipse.swt.events.TreeEvent>)
) - TreeFactory accepts a Lambda for
TreeEvent
(seeonCollapse(java.util.function.Consumer<org.eclipse.swt.events.TreeEvent>)
)
Tree tree = TreeFactory.newTree(SWT.CHECK) // .headerVisible(true) // .linesVisible(true) // .onSelect(e -> treeClicked(e)) // .onExpand(e -> treeExpanded(e)) // .create(parent);
The above example creates a tree, sets some properties, registers a SelectionListener and a TreeListener for expansion and finally creates the tree in "parent".
Note that this class does not extend AbstractCompositeFactory
even
though Tree extends Composite. This is because Tree is not supposed to be
used like a Composite.
- Since:
- 3.18
-
Method Summary
Modifier and TypeMethodDescriptionheaderVisible
(boolean visible) Marks the receiver's header as visible if the argument is true, and marks it invisible otherwise.itemCount
(int count) Sets the number of root-level items contained in the receiver.linesVisible
(boolean visible) Marks the receiver's lines as visible if the argument is true, and marks it invisible otherwise.static TreeFactory
newTree
(int style) Creates a new TreeFactory with the given style.onCollapse
(Consumer<TreeEvent> consumer) Creates aTreeListener
and registers it for the collapsed event.Creates aTreeListener
and registers it for the expanded event.onSelect
(Consumer<SelectionEvent> consumer) Creates aSelectionListener
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
-
Method Details
-
newTree
Creates a new TreeFactory with the given style. Refer toTree(Composite, int)
for possible styles.- Returns:
- a new TreeFactory instance
-
linesVisible
Marks the receiver's lines as visible if the argument is true, and marks it invisible otherwise. Note that some platforms draw grid lines while others may draw alternating row colors.- Parameters:
visible
- the visibility state- Returns:
- this
- See Also:
-
headerVisible
Marks the receiver's header as visible if the argument is true, and marks it invisible otherwise.- Parameters:
visible
- the visibility state- Returns:
- this
- See Also:
-
itemCount
Sets the number of root-level items contained in the receiver.- Parameters:
count
- the number of items- 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:
-
onCollapse
Creates aTreeListener
and registers it for the collapsed event. If the receiver is collapsed by the user the given consumer is invoked. TheTreeEvent
is passed to the consumer.- Parameters:
consumer
- the consumer whose accept method is called- Returns:
- this
- See Also:
-
onExpand
Creates aTreeListener
and registers it for the expanded event. If the receiver is expanded by the user the given consumer is invoked. TheTreeEvent
is passed to the consumer.- Parameters:
consumer
- the consumer whose accept method is called- Returns:
- this
- See Also:
-