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>

@Generated("org.javagi.JavaGI") public class SingleSelection<T extends GObject> extends GObject implements ListModel<T>, SectionModel<T>, SelectionModel<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.

  • Constructor Details

    • SingleSelection

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

      public SingleSelection(@Nullable ListModel model)
      Creates a new selection to handle model.
      Parameters:
      model - the GListModel to manage
    • SingleSelection

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

    • getType

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

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

      protected SingleSelection 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
    • getAutoselect

      public boolean getAutoselect()
      Checks if autoselect has been enabled or disabled via gtk_single_selection_set_autoselect().
      Returns:
      true if autoselect is enabled
    • getCanUnselect

      public boolean getCanUnselect()
      If true, gtk_selection_model_unselect_item() is supported and allows unselecting the selected item.
      Returns:
      true to support unselecting
    • getModel

      public @Nullable ListModel 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_POSITION is returned.

      Returns:
      The position of the selected item
    • getSelectedItem

      public T getSelectedItem()

      Gets the selected item.

      If no item is selected, null is returned.

      Returns:
      The selected item
    • setAutoselect

      public void setAutoselect(boolean autoselect)

      Enables or disables autoselect.

      If autoselect is true, 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 - true to 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:autoselect will cause unselecting to not work, so it practically makes no sense to set both at the same time.

      Parameters:
      canUnselect - true to allow unselecting
    • setModel

      public void setModel(@Nullable ListModel model)

      Sets the model that this SingleSelection should wrap.

      If model is null, this SingleSelection will be empty.

      Parameters:
      model - A GListModel to wrap
    • setSelected

      public void setSelected(int position)

      Selects the item at the given position.

      If the list does not have an item at position or GTK_INVALID_LIST_POSITION is given, the behavior depends on the value of the Gtk.SingleSelection:autoselect property: 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 if Gtk.SingleSelection:can-unselect is set to false.

      Parameters:
      position - the item to select or GTK_INVALID_LIST_POSITION
    • builder

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