Package me.hackware.api.setting.impl
Class ListSetting<T>
- Type Parameters:
T- the type of items in the list
A generic setting that stores a set of selected items from a list.
In normal mode the options are fixed and items are toggled on/off. In editable mode the user can add, edit and remove entries at runtime (the options list itself becomes the data).
Usage examples:
// Fixed-option mode
ListSetting<String> fruits = new ListSetting<String>("Fruits")
.options(List.of("apple", "banana", "cherry"))
.nameMapper(s -> s)
.idMapper(s -> s)
.limit(3);
// Editable free-form mode
ListSetting<String> patterns = new ListSetting<String>("Patterns")
.editable(s -> s);
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a new entry (editable mode).defaultValue(Set<T> defaultValue) Sets the default (and initial) selection for this list.description(String description) displayName(T item) Enables editable mode, allowing the user to add, edit and remove entries.intReturns the number of entries.Resolve an item from its serialized id, ornullif unknown.Returns an unmodifiable view of the entries (same as options in editable mode).getEntry(int index) Returns the entry at the given index, ornullif out of range.intgetLimit()Get the selected items as a list of serialized string ids.Set the function that converts an item to a unique string id (for serialization).booleanbooleanisSelected(T item) booleanisSelectedById(String id) limit(int max) Maximum number of items that may be selected.nameMapper(Function<T, String> nameMapper) Set the function that converts an item to its user-facing display name.onListChanged(Runnable callback) Called whenever the list content changes (add/remove/edit) in editable mode.onSelectionChanged(Runnable callback) Called whenever the selection state changes (toggle, setValue, setFromIds).Set the available options for this list.voidremoveEntry(int index) Removes the entry at the given index (editable mode).intvoidReplaces the entry at the given index (editable mode).voidsetFromIds(List<String> ids) Restore selected items from a list of serialized string ids.voidvoidToggle the selection state of an item and save.visible(boolean visible) visible(BooleanSupplier visible) Methods inherited from class me.hackware.api.setting.Setting
displayName, get, getDefaultValue, getDescription, getDisplayName, getGroup, getName, getOwner, group, isBulkLoading, isVisible, onChanged, setBulkLoadProbe, setOwner
-
Constructor Details
-
ListSetting
-
ListSetting
-
-
Method Details
-
options
Set the available options for this list. -
nameMapper
Set the function that converts an item to its user-facing display name. -
idMapper
Set the function that converts an item to a unique string id (for serialization). -
defaultValue
Sets the default (and initial) selection for this list. Does NOT trigger a save.- Overrides:
defaultValuein classSetting<Set<T>>
-
visible
-
visible
-
description
- Overrides:
descriptionin classSetting<Set<T>>
-
limit
Maximum number of items that may be selected. Defaults to the full list size. -
editable
Enables editable mode, allowing the user to add, edit and remove entries.- Parameters:
factory- converts a serialized string id back into aTinstance (forListSetting<String>this is simplys -> s)
-
onListChanged
Called whenever the list content changes (add/remove/edit) in editable mode. -
onSelectionChanged
Called whenever the selection state changes (toggle, setValue, setFromIds). -
getOptions
-
getNameMapper
-
getIdMapper
-
getLimit
public int getLimit() -
isEditable
public boolean isEditable() -
displayName
-
itemId
-
fromId
Resolve an item from its serialized id, ornullif unknown. -
getEntries
Returns an unmodifiable view of the entries (same as options in editable mode). -
entryCount
public int entryCount()Returns the number of entries. -
getEntry
Returns the entry at the given index, ornullif out of range. -
addEntry
Adds a new entry (editable mode). -
removeEntry
public void removeEntry(int index) Removes the entry at the given index (editable mode). -
setEntry
Replaces the entry at the given index (editable mode). -
isSelected
-
isSelectedById
-
toggle
Toggle the selection state of an item and save. -
selectedCount
public int selectedCount() -
firstSelectedName
-
getSelected
-
getSelectedIds
Get the selected items as a list of serialized string ids. -
setValue
-
setFromIds
Restore selected items from a list of serialized string ids.
-