Class SliceListModel<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 SliceListModel<T extends GObject> extends GObject implements ListModel<T>, SectionModel<T>

A list model that presents a slice of another model.

This is useful when implementing paging by setting the size to the number of elements per page and updating the offset whenever a different page is opened.

GtkSliceListModel passes through sections from the underlying model.

  • Constructor Details

    • SliceListModel

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

      public SliceListModel(@Nullable ListModel model, int offset, int size)

      Creates a new slice model.

      It presents the slice from offset to offset + size of the given model.

      Parameters:
      model - The model to use
      offset - the offset of the slice
      size - maximum size of the slice
    • SliceListModel

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

    • getType

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

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

      protected SliceListModel 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 used or null if none.
      Returns:
      The model in use
    • getOffset

      public int getOffset()
      Gets the offset set via gtk_slice_list_model_set_offset().
      Returns:
      The offset
    • getSize

      public int getSize()
      Gets the size set via gtk_slice_list_model_set_size().
      Returns:
      The size
    • setModel

      public void setModel(@Nullable ListModel model)

      Sets the model to show a slice of.

      The model's item type must conform to self's item type.

      Parameters:
      model - The model to be sliced
    • setOffset

      public void setOffset(int offset)

      Sets the offset into the original model for this slice.

      If the offset is too large for the sliced model, this SliceListModel will end up empty.

      Parameters:
      offset - the new offset to use
    • setSize

      public void setSize(int size)

      Sets the maximum size. this SliceListModel will never have more items than size.

      It can however have fewer items if the offset is too large or the model sliced from doesn't have enough items.

      Parameters:
      size - the maximum size
    • builder

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