Interface ListModel<T extends GObject>
- All Superinterfaces:
Collection<T>
,Iterable<T>
,List<T>
,ListModelJavaList<T>
,Proxy
,SequencedCollection<T>
- All Known Subinterfaces:
SectionModel<T>
,SelectionModel<T>
- All Known Implementing Classes:
AnyFilter
,BookmarkList
,CompletionContext
,DirectoryList
,EnumListModel
,EveryFilter
,FilterListModel
,FlattenListModel
,FontFamily
,FontFamily.FontFamilyImpl
,FontMap
,FontMap.FontMapImpl
,FontMap.FontMapImpl
,ListIndexModel
,ListModel.ListModelImpl
,ListStore
,MapListModel
,MultiFilter
,MultiFilter.MultiFilterImpl
,MultiSelection
,MultiSorter
,NoSelection
,SectionModel.SectionModelImpl
,SelectionFilterModel
,SelectionModel.SelectionModelImpl
,ShortcutController
,SingleSelection
,SliceListModel
,SortListModel
,StringList
,TreeListModel
,ViewStackPages
GListModel
is an interface that represents a mutable list of
GObject
. Its main intention is as a model for various widgets
in user interfaces, such as list views, but it can also be used as a
convenient method of returning lists of data, with support for
updates.
Each object in the list may also report changes in itself via some
mechanism (normally the GObject.Object::notify
signal). Taken
together with the Gio.ListModel::items-changed
signal, this provides
for a list that can change its membership, and in which the members can
change their individual properties.
A good example would be the list of visible wireless network access points, where each access point can report dynamic properties such as signal strength.
It is important to note that the GListModel
itself does not report
changes to the individual items. It only reports changes to the list
membership. If you want to observe changes to the objects themselves
then you need to connect signals to the objects that you are
interested in.
All items in a GListModel
are of (or derived from) the same type.
getItemType()
returns that type. The type may be an
interface, in which case all objects in the list must implement it.
The semantics are close to that of an array:
getNItems()
returns the number of items in the list
and getItem(int)
returns an item at a (0-based) position.
In order to allow implementations to calculate the list length lazily,
you can also iterate over items: starting from 0, repeatedly call
getItem(int)
until it returns NULL
.
An implementation may create objects lazily, but must take care to return the same object for a given position until all references to it are gone.
On the other side, a consumer is expected only to hold references on objects that are currently ‘user visible’, in order to facilitate the maximum level of laziness in the implementation of the list and to reduce the required number of signal connections at a given time.
This interface is intended only to be used from a single thread. The
thread in which it is appropriate to use it depends on the particular
implementation, but typically it will be from the thread that owns
the thread-default main context (see
MainContext.pushThreadDefault()
) in effect at the time that the
model was created.
Over time, it has established itself as good practice for list model
implementations to provide properties item-type
and n-items
to
ease working with them. While it is not required, it is recommended
that implementations provide these two properties. They should return
the values of getItemType()
and
getNItems()
respectively and be defined as such:
properties[PROP_ITEM_TYPE] =
g_param_spec_gtype ("item-type", NULL, NULL, G_TYPE_OBJECT,
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
properties[PROP_N_ITEMS] =
g_param_spec_uint ("n-items", NULL, NULL, 0, G_MAXUINT, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
Functional interface declaration of theItemsChangedCallback
callback.static class
The ListModelImpl type represents a native instance of the ListModel interface.static class
The virtual function table forGListModel
. -
Method Summary
Modifier and TypeMethodDescriptiondefault void
emitItemsChanged
(int position, int removed, int added) Emits the "items-changed" signal.default T
getItem
(int position) Get the item atposition
.default Type
Gets the type of the items in this ListModel.default int
Gets the number of items in this ListModel.static Type
getType()
Get the GType of the ListModel classdefault void
itemsChanged
(int position, int removed, int added) Emits theGListModel
::items-changed signal on this ListModel.This signal is emitted whenever items were added to or removed fromlist
.Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.List
addFirst, addLast, equals, getFirst, getLast, hashCode, removeFirst, removeLast, replaceAll, reversed, sort, spliterator
Methods inherited from interface io.github.jwharm.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
-
getItemType
Gets the type of the items in this ListModel.All items returned from g_list_model_get_item() are of the type returned by this function, or a subtype, or if the type is an interface, they are an implementation of that interface.
The item type of a
GListModel
can not change during the life of the model.- Returns:
- the
GType
of the items contained in this ListModel.
-
getNItems
default int getNItems()Gets the number of items in this ListModel.Depending on the model implementation, calling this function may be less efficient than iterating the list with increasing values for
position
until g_list_model_get_item() returnsnull
.- Specified by:
getNItems
in interfaceListModelJavaList<T extends GObject>
- Returns:
- the number of items in this ListModel.
-
getItem
Get the item atposition
.If
position
is greater than the number of items in this ListModel,null
is returned.null
is never returned for an index that is smaller than the length of the list.This function is meant to be used by language bindings in place of g_list_model_get_item().
See also: g_list_model_get_n_items()
- Specified by:
getItem
in interfaceListModelJavaList<T extends GObject>
- Parameters:
position
- the position of the item to fetch- Returns:
- the object at
position
.
-
itemsChanged
default void itemsChanged(int position, int removed, int added) Emits theGListModel
::items-changed signal on this ListModel.This function should only be called by classes implementing
GListModel
. It has to be called after the internal representation of this ListModel has been updated, because handlers connected to this signal might query the new state of the list.Implementations must only make changes to the model (as visible to its consumer) in places that will not cause problems for that consumer. For models that are driven directly by a write API (such as
GListStore
), changes can be reported in response to uses of that API. For models that represent remote data, changes should only be made from a fresh mainloop dispatch. It is particularly not permitted to make changes in response to a call to theGListModel
consumer API.Stated another way: in general, it is assumed that code making a series of accesses to the model via the API, without returning to the mainloop, and without calling other code, will continue to view the same contents of the model.
- Parameters:
position
- the position at which this ListModel changedremoved
- the number of items removedadded
- the number of items added
-
onItemsChanged
default SignalConnection<ListModel.ItemsChangedCallback> onItemsChanged(ListModel.ItemsChangedCallback handler) This signal is emitted whenever items were added to or removed fromlist
. Atposition
,removed
items were removed andadded
items were added in their place.Note: If
removed != added
, the positions of all later items in the model change.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitItemsChanged
default void emitItemsChanged(int position, int removed, int added) Emits the "items-changed" signal. SeeonItemsChanged(org.gnome.gio.ListModel.ItemsChangedCallback)
.
-