Interface SelectionModel<T extends GObject>
- All Superinterfaces:
Collection<T>,Iterable<T>,List<T>,ListModel<T>,ListModelJavaList<T>,Proxy,SequencedCollection<T>
- All Known Implementing Classes:
MultiSelection,NoSelection,SelectionModel.SelectionModel$Impl,SingleSelection,ViewStackPages
This support is then used by widgets using list models to add the ability to select and unselect various items.
GTK provides default implementations of the most common selection modes such
as SingleSelection, so you will only need to implement this
interface if you want detailed control about how selections should be handled.
A GtkSelectionModel supports a single boolean per item indicating if an item is
selected or not. This can be queried via isSelected(int).
When the selected state of one or more items changes, the model will emit the
Gtk.SelectionModel::selection-changed signal by calling the
selectionChanged(int, int) function. The positions given
in that signal may have their selection state changed, though that is not a
requirement. If new items added to the model via the
Gio.ListModel::items-changed signal are selected or not is up to the
implementation.
Note that items added via Gio.ListModel::items-changed may already
be selected and no Gtk.SelectionModel::selection-changed will be
emitted for them. So to track which items are selected, it is necessary to
listen to both signals.
Additionally, the interface can expose functionality to select and unselect
items. If these functions are implemented, GTK's list widgets will allow users
to select and unselect items. However, GtkSelectionModels are free to only
implement them partially or not at all. In that case the widgets will not
support the unimplemented operations.
When selecting or unselecting is supported by a model, the return values of the selection functions do not indicate if selection or unselection happened. They are only meant to indicate complete failure, like when this mode of selecting is not supported by the model.
Selections may happen asynchronously, so the only reliable way to find out when an item was selected is to listen to the signals that indicate selection.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceFunctional interface declaration of theSelectionChangedCallbackcallback.static classThe SelectionModel$Impl type represents a native instance of the SelectionModel interface.static classThe list of virtual functions for theGtkSelectionModelinterface.Nested classes/interfaces inherited from interface org.gnome.gio.ListModel
ListModel.ItemsChangedCallback, ListModel.ListModel$Impl, ListModel.ListModelInterfaceNested classes/interfaces inherited from interface org.javagi.gio.ListModelJavaList
ListModelJavaList.SubList<E extends @Nullable GObject,List extends ListModelJavaList<E>> -
Method Summary
Modifier and TypeMethodDescriptiondefault voidemitSelectionChanged(int position, int nItems) Emits the "selection-changed" signal.default BitsetGets the set containing all currently selected items in the model.default BitsetgetSelectionInRange(int position, int nItems) Gets the set of selected items in a range.static @Nullable TypegetType()Get the GType of the SelectionModel classdefault booleanisSelected(int position) Checks if the given item is selected.Emitted when the selection state of some of the items inmodelchanges.default booleanRequests to select all items in the model.default voidselectionChanged(int position, int nItems) Helper function for implementations ofGtkSelectionModel.default booleanselectItem(int position, boolean unselectRest) Requests to select an item in the model.default booleanselectRange(int position, int nItems, boolean unselectRest) Requests to select a range of items in the model.default booleansetSelection(Bitset selected, Bitset mask) Make selection changes.default booleanRequests to unselect all items in the model.default booleanunselectItem(int position) Requests to unselect an item in the model.default booleanunselectRange(int position, int nItems) Requests to unselect a range of items in the model.Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
addFirst, addLast, equals, getFirst, getLast, hashCode, removeFirst, removeLast, replaceAll, reversed, sort, spliteratorMethods inherited from interface org.gnome.gio.ListModel
emitItemsChanged, getItem, getItemType, getNItems, itemsChanged, onItemsChangedMethods inherited from interface org.javagi.gio.ListModelJavaList
add, add, addAll, addAll, clear, contains, containsAll, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, retainAll, set, size, subList, toArray, toArray
-
Method Details
-
getType
-
getSelection
Gets the set containing all currently selected items in the model.This function may be slow, so if you are only interested in single item, consider using
isSelected(int)or if you are only interested in a few, considergetSelectionInRange(int, int).- Returns:
- a
GtkBitsetcontaining all the values currently selected inmodel.If no items are selected, the bitset is empty. The bitset must not be modified.
-
getSelectionInRange
Gets the set of selected items in a range.This function is an optimization for
getSelection()when you are only interested in part of the model's selected state. A common use case is in response to theGtk.SelectionModel::selection-changedsignal.- Parameters:
position- start of the queried rangenItems- number of items in the queried range- Returns:
- A
GtkBitsetthat matches the selection state for the given range with all other values being undefined. The bitset must not be modified.
-
isSelected
default boolean isSelected(int position) Checks if the given item is selected.- Parameters:
position- the position of the item to query- Returns:
trueif the item is selected
-
selectAll
default boolean selectAll()Requests to select all items in the model.- Returns:
trueif this action was supported and no fallback should be tried. This does not mean that all items are now selected.
-
selectItem
default boolean selectItem(int position, boolean unselectRest) Requests to select an item in the model.- Parameters:
position- the position of the item to selectunselectRest- whether previously selected items should be unselected- Returns:
trueif this action was supported and no fallback should be tried. This does not mean the item was selected.
-
selectRange
default boolean selectRange(int position, int nItems, boolean unselectRest) Requests to select a range of items in the model.- Parameters:
position- the first item to selectnItems- the number of items to selectunselectRest- whether previously selected items should be unselected- Returns:
trueif this action was supported and no fallback should be tried. This does not mean the range was selected.
-
selectionChanged
default void selectionChanged(int position, int nItems) Helper function for implementations ofGtkSelectionModel.Call this when the selection changes to emit the
Gtk.SelectionModel::selection-changedsignal.- Parameters:
position- the first changed itemnItems- the number of changed items
-
setSelection
Make selection changes.This is the most advanced selection updating method that allows the most fine-grained control over selection changes. If you can, you should try the simpler versions, as implementations are more likely to implement support for those.
Requests that the selection state of all positions set in
maskbe updated to the respective value in theselectedbitmask.In pseudocode, it would look something like this:
for (i = 0; i < n_items; i++) { // don't change values not in the mask if (!gtk_bitset_contains (mask, i)) continue; if (gtk_bitset_contains (selected, i)) select_item (i); else unselect_item (i); } gtk_selection_model_selection_changed (model, first_changed_item, n_changed_items);maskandselectedmust not be modified. They may refer to the same bitset, which would mean that every item in the set should be selected.- Parameters:
selected- bitmask specifying if items should be selected or unselectedmask- bitmask specifying which items should be updated- Returns:
trueif this action was supported and no fallback should be tried. This does not mean that all items were updated according to the inputs.
-
unselectAll
default boolean unselectAll()Requests to unselect all items in the model.- Returns:
trueif this action was supported and no fallback should be tried. This does not mean that all items are now unselected.
-
unselectItem
default boolean unselectItem(int position) Requests to unselect an item in the model.- Parameters:
position- the position of the item to unselect- Returns:
trueif this action was supported and no fallback should be tried. This does not mean the item was unselected.
-
unselectRange
default boolean unselectRange(int position, int nItems) Requests to unselect a range of items in the model.- Parameters:
position- the first item to unselectnItems- the number of items to unselect- Returns:
trueif this action was supported and no fallback should be tried. This does not mean the range was unselected.
-
onSelectionChanged
default SignalConnection<SelectionModel.SelectionChangedCallback> onSelectionChanged(SelectionModel.SelectionChangedCallback handler) Emitted when the selection state of some of the items inmodelchanges.Note that this signal does not specify the new selection state of the items, they need to be queried manually. It is also not necessary for a model to change the selection state of any of the items in the selection model, though it would be rather useless to emit such a signal.
- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitSelectionChanged
default void emitSelectionChanged(int position, int nItems) Emits the "selection-changed" signal. SeeonSelectionChanged(org.gnome.gtk.SelectionModel.SelectionChangedCallback).
-