Class MapListModel<T extends GObject>

All Implemented Interfaces:
Iterable<T>, Collection<T>, List<T>, SequencedCollection<T>, ListModel<T>, SectionModel<T>, Proxy, ListModelJavaList<T>

@Generated("org.javagi.JavaGI") public class MapListModel<T extends GObject> extends GObject implements ListModel<T>, SectionModel<T>

A list model that maps the items in another model to different items.

GtkMapListModel uses a Gtk.MapListModelMapFunc.

Example: Create a list of GtkEventControllers

static gpointer
map_to_controllers (gpointer widget,
                    gpointer data)
{
  gpointer result = gtk_widget_observe_controllers (widget);
  g_object_unref (widget);
  return result;
}

widgets = gtk_widget_observe_children (widget);

controllers = gtk_map_list_model_new (widgets,
                                      map_to_controllers,
                                      NULL, NULL);

model = gtk_flatten_list_model_new (GTK_TYPE_EVENT_CONTROLLER,
                                    controllers);

GtkMapListModel will attempt to discard the mapped objects as soon as they are no longer needed and recreate them if necessary.

GtkMapListModel passes through sections from the underlying model.

  • Constructor Details

    • MapListModel

      public MapListModel(MemorySegment address)
      Create a MapListModel instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • MapListModel

      public MapListModel(@Nullable ListModel model, @Nullable MapListModelMapFunc mapFunc)
      Creates a new GtkMapListModel for the given arguments.
      Parameters:
      model - The model to map
      mapFunc - map function
    • MapListModel

      public MapListModel()
      Create a new MapListModel.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the MapListModel class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected MapListModel asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class GObject
      Returns:
      the instance as if it were its parent type
    • getModel

      public @Nullable ListModel getModel()
      Gets the model that is currently being mapped or null if none.
      Returns:
      The model that gets mapped
    • hasMap

      public boolean hasMap()
      Checks if a map function is currently set on self.
      Returns:
      true if a map function is set
    • setMapFunc

      public void setMapFunc(@Nullable MapListModelMapFunc mapFunc)

      Sets the function used to map items.

      The function will be called whenever an item needs to be mapped and must return the item to use for the given input item.

      Note that GtkMapListModel may call this function multiple times on the same item, because it may delete items it doesn't need anymore.

      GTK makes no effort to ensure that mapFunc conforms to the item type of self. It assumes that the caller knows what they are doing and the map function returns items of the appropriate type.

      Parameters:
      mapFunc - map function
    • setModel

      public void setModel(@Nullable ListModel model)

      Sets the model to be mapped.

      GTK makes no effort to ensure that model conforms to the item type expected by the map function. It assumes that the caller knows what they are doing and have set up an appropriate map function.

      Parameters:
      model - The model to be mapped
    • builder

      public static MapListModel.Builder<? extends MapListModel.Builder> builder()
      A MapListModel.Builder object constructs a MapListModel with the specified properties. Use the various set...() methods to set properties, and finish construction with MapListModel.Builder.build().
      Returns:
      the builder object