Package io.goobi.viewer.faces.utils
Class SelectItemBuilder
java.lang.Object
io.goobi.viewer.faces.utils.SelectItemBuilder
Tools to create SelectItem collections to use in jsf components.
- Author:
- Florian Alpers
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> SelectItemcreateSelectItem(Function<T, Object> valueSupplier, Function<T, String> labelSupplier, Function<T, String> descriptionSupplier, T value, Predicate<T> disabledPredicate) getAsAlphabeticallySortedMap(List<T> items, Function<T, String> sortValueSupplier) Sorts the given list of items into buckets for each starting letter.static <T> List<SelectItem> getAsGroupedSelectItems(Map<String, List<T>> map, Function<T, Object> valueSupplier, Function<T, String> labelSupplier, Function<T, String> descriptionSupplier, Predicate<T> disabledPredicate) Creates a List ofselectItemsfrom the given map, grouped into OptGroups for each map key.getAsSortedMap(List<T> items, Function<T, List<String>> sortValueSupplier, Function<String, String> keyGenerator) Sorts the given list of items into buckets for each values returned by the sortValueSupplier.
-
Method Details
-
getAsAlphabeticallySortedMap
public static <T> SortedMap<String,List<T>> getAsAlphabeticallySortedMap(List<T> items, Function<T, String> sortValueSupplier) Sorts the given list of items into buckets for each starting letter.- Type Parameters:
T-- Parameters:
items- List of items that should be sortedsortValueSupplier- Function mapping an item to the sting according to which it should be sorted- Returns:
- Map with starting letters of sort values as keys
-
getAsSortedMap
public static <T> SortedMap<String,List<T>> getAsSortedMap(List<T> items, Function<T, List<String>> sortValueSupplier, Function<String, String> keyGenerator) Sorts the given list of items into buckets for each values returned by the sortValueSupplier.- Type Parameters:
T-- Parameters:
items- List of items that should be sortedsortValueSupplier- Function mapping an item to the string according to which it should be sortedkeyGenerator- Function that creates labels for the return values of the sortValueSupplier. These labels are used as the actual keys of the map- Returns:
- Map with starting letters of sort values as keys
-
getAsGroupedSelectItems
public static <T> List<SelectItem> getAsGroupedSelectItems(Map<String, List<T>> map, Function<T, Object> valueSupplier, Function<T, String> labelSupplier, Function<T, String> descriptionSupplier, Predicate<T> disabledPredicate) Creates a List ofselectItemsfrom the given map, grouped into OptGroups for each map key.- Type Parameters:
T-- Parameters:
map- Map of items to include in selectItemsvalueSupplier- function extracting the select value from an itemlabelSupplier- function extracting the display label from an itemdescriptionSupplier- function extracting the description from an itemdisabledPredicate- predicate determining whether an item is disabled- Returns:
- List
-
createSelectItem
public static <T> SelectItem createSelectItem(Function<T, Object> valueSupplier, Function<T, String> labelSupplier, Function<T, String> descriptionSupplier, T value, Predicate<T> disabledPredicate) - Type Parameters:
T-- Parameters:
valueSupplier- function extracting the select value from an itemlabelSupplier- function extracting the display label from an itemdescriptionSupplier- function extracting the description from an itemvalue- the item to create a SelectItem fordisabledPredicate- predicate determining whether the item is disabled- Returns:
- SelectItem
-