Package com.tonic.vellum.widget
Class SelectList<T>
- java.lang.Object
-
- com.tonic.vellum.Section
-
- com.tonic.vellum.widget.AbstractListSection
-
- com.tonic.vellum.widget.SelectList<T>
-
public final class SelectList<T> extends AbstractListSection
A scrollable, selectable list of typed items, each rendered to a display string; ENTER fires the selection handlers.
-
-
Constructor Summary
Constructors Constructor Description SelectList()Creates an empty list.SelectList(java.util.List<T> items)Creates a list populated with the given items.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SelectList<T>onSelect(java.util.function.IntConsumer handler)Sets the handler called with the row index on ENTER.SelectList<T>onSelectItem(java.util.function.Consumer<T> handler)Sets the handler called with the item on ENTER.SelectList<T>renderer(java.util.function.Function<T,java.lang.String> renderer)Sets the function that renders each item to a display string.TselectedItem()SelectList<T>setItems(java.util.List<T> newItems)Replaces the items with the given list.-
Methods inherited from class com.tonic.vellum.widget.AbstractListSection
onHighlight, select, selectedIndex
-
-
-
-
Constructor Detail
-
SelectList
public SelectList()
Creates an empty list.
-
SelectList
public SelectList(java.util.List<T> items)
Creates a list populated with the given items.- Parameters:
items- the initial items
-
-
Method Detail
-
setItems
public SelectList<T> setItems(java.util.List<T> newItems)
Replaces the items with the given list.- Parameters:
newItems- the new items- Returns:
- this SelectList for chaining
-
renderer
public SelectList<T> renderer(java.util.function.Function<T,java.lang.String> renderer)
Sets the function that renders each item to a display string.- Parameters:
renderer- the item-to-string function- Returns:
- this SelectList for chaining
-
selectedItem
public T selectedItem()
- Returns:
- the selected item, or null when the list is empty
-
onSelectItem
public SelectList<T> onSelectItem(java.util.function.Consumer<T> handler)
Sets the handler called with the item on ENTER.- Parameters:
handler- the item activation handler- Returns:
- this SelectList for chaining
-
onSelect
public SelectList<T> onSelect(java.util.function.IntConsumer handler)
Description copied from class:AbstractListSectionSets the handler called with the row index on ENTER.- Overrides:
onSelectin classAbstractListSection- Parameters:
handler- the activation handler- Returns:
- this AbstractListSection for chaining
-
-