Class SingleSelection<T extends GObject>
- All Implemented Interfaces:
Iterable<T>, Collection<T>, List<T>, SequencedCollection<T>, ListModel<T>, SectionModel<T>, SelectionModel<T>, Proxy, ListModelJavaList<T>
A selection model that allows selecting a single item.
Note that the selection is persistent -- if the selected item is removed
and re-added in the same Gio.ListModel::items-changed emission, it
stays selected. In particular, this means that changing the sort order of an
underlying sort model will preserve the selection.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classSingleSelection.Builder<B extends SingleSelection.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static classSingleSelection.SingleSelectionClass<T extends GObject>Nested classes/interfaces inherited from class GObject
GObject.NotifyCallback, GObject.ObjectClassNested classes/interfaces inherited from interface ListModel
ListModel.ItemsChangedCallback, ListModel.ListModel$Impl, ListModel.ListModelInterfaceNested classes/interfaces inherited from interface ListModelJavaList
ListModelJavaList.SubList<E,List> Nested classes/interfaces inherited from interface SectionModel
SectionModel.SectionModel$Impl, SectionModel.SectionModelInterface, SectionModel.SectionsChangedCallbackNested classes/interfaces inherited from interface SelectionModel
SelectionModel.SelectionChangedCallback, SelectionModel.SelectionModel$Impl, SelectionModel.SelectionModelInterface -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new SingleSelection.SingleSelection(MemorySegment address) Create a SingleSelection instance for the provided memory address.SingleSelection(@Nullable ListModel model) Creates a new selection to handlemodel. -
Method Summary
Modifier and TypeMethodDescriptionprotected SingleSelectionasParent()Return this instance as if it were its parent type.static SingleSelection.Builder<? extends SingleSelection.Builder> builder()ASingleSelection.Builderobject constructs aSingleSelectionwith the specified properties.booleanChecks if autoselect has been enabled or disabled via gtk_single_selection_set_autoselect().booleanIftrue, gtk_selection_model_unselect_item() is supported and allows unselecting the selected item.static MemoryLayoutThe memory layout of the native struct.@Nullable ListModelgetModel()Gets the model that this SingleSelection is wrapping.intGets the position of the selected item.Gets the selected item.static @Nullable TypegetType()Get the GType of the SingleSelection class.voidsetAutoselect(boolean autoselect) Enables or disables autoselect.voidsetCanUnselect(boolean canUnselect) Iftrue, unselecting the current item via gtk_selection_model_unselect_item() is supported.voidSets the model that this SingleSelection should wrap.voidsetSelected(int position) Selects the item at the given position.Methods inherited from class GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newv, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withPropertiesMethods inherited from class TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class ProxyInstance
equals, handle, hashCodeMethods inherited from class Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface List
addFirst, addLast, equals, getFirst, getLast, hashCode, removeFirst, removeLast, replaceAll, reversed, sort, spliteratorMethods inherited from interface ListModel
emitItemsChanged, getItem, getItemType, getNItems, itemsChanged, onItemsChangedMethods inherited from interface ListModelJavaList
add, add, addAll, addAll, clear, contains, containsAll, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, retainAll, set, size, subList, toArray, toArrayMethods inherited from interface SectionModel
emitSectionsChanged, getSection, onSectionsChanged, sectionsChangedMethods inherited from interface SelectionModel
emitSelectionChanged, getSelection, getSelectionInRange, isSelected, onSelectionChanged, selectAll, selectionChanged, selectItem, selectRange, setSelection, unselectAll, unselectItem, unselectRange
-
Constructor Details
-
SingleSelection
Create a SingleSelection instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
SingleSelection
Creates a new selection to handlemodel.- Parameters:
model- theGListModelto manage
-
SingleSelection
public SingleSelection()Create a new SingleSelection.
-
-
Method Details
-
getType
Get the GType of the SingleSelection class.- Returns:
- the GType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
asParent
Return this instance as if it were its parent type. Comparable to the Javasuperkeyword, but ensures the parent typeclass is also used in native code. -
getAutoselect
public boolean getAutoselect()Checks if autoselect has been enabled or disabled via gtk_single_selection_set_autoselect().- Returns:
trueif autoselect is enabled
-
getCanUnselect
public boolean getCanUnselect()Iftrue, gtk_selection_model_unselect_item() is supported and allows unselecting the selected item.- Returns:
trueto support unselecting
-
getModel
Gets the model that this SingleSelection is wrapping.- Returns:
- The model being wrapped
-
getSelected
public int getSelected()Gets the position of the selected item.
If no item is selected,
GTK_INVALID_LIST_POSITIONis returned.- Returns:
- The position of the selected item
-
getSelectedItem
Gets the selected item.
If no item is selected,
nullis returned.- Returns:
- The selected item
-
setAutoselect
public void setAutoselect(boolean autoselect) Enables or disables autoselect.
If
autoselectistrue, this SingleSelection will enforce that an item is always selected. It will select a new item when the currently selected item is deleted and it will disallow unselecting the current item.- Parameters:
autoselect-trueto always select an item
-
setCanUnselect
public void setCanUnselect(boolean canUnselect) If
true, unselecting the current item via gtk_selection_model_unselect_item() is supported.Note that setting
Gtk.SingleSelection:autoselectwill cause unselecting to not work, so it practically makes no sense to set both at the same time.- Parameters:
canUnselect-trueto allow unselecting
-
setModel
Sets the model that this SingleSelection should wrap.
If
modelisnull, this SingleSelection will be empty.- Parameters:
model- AGListModelto wrap
-
setSelected
public void setSelected(int position) Selects the item at the given position.
If the list does not have an item at
positionorGTK_INVALID_LIST_POSITIONis given, the behavior depends on the value of theGtk.SingleSelection:autoselectproperty: If it is set, no change will occur and the old item will stay selected. If it is unset, the selection will be unset and no item will be selected. This also applies ifGtk.SingleSelection:can-unselectis set tofalse.- Parameters:
position- the item to select orGTK_INVALID_LIST_POSITION
-
builder
ASingleSelection.Builderobject constructs aSingleSelectionwith the specified properties. Use the variousset...()methods to set properties, and finish construction withSingleSelection.Builder.build().- Returns:
- the builder object
-