java.lang.Object
is.codion.swing.common.model.component.combobox.FilteredComboBoxModel<Entity>
is.codion.swing.framework.model.component.EntityComboBoxModel
All Implemented Interfaces:
FilteredModel<Entity>, ComboBoxModel<Entity>, ListModel<Entity>

public class EntityComboBoxModel extends FilteredComboBoxModel<Entity>
A ComboBoxModel based on an Entity, showing by default all the entities in the underlying table.
  • Constructor Details

    • EntityComboBoxModel

      public EntityComboBoxModel(EntityType entityType, EntityConnectionProvider connectionProvider)
      Parameters:
      entityType - the type of the entity this combo box model should represent
      connectionProvider - a EntityConnectionProvider instance
  • Method Details

    • toString

      public final String toString()
      Overrides:
      toString in class Object
    • connectionProvider

      public final EntityConnectionProvider connectionProvider()
      Returns:
      the connection provider used by this combo box model
    • entityType

      public final EntityType entityType()
      Returns:
      the type of the entity this combo box model is based on
    • forceRefresh

      public final void forceRefresh()
      Forces a refresh of this model, disregarding the staticData directive
      See Also:
    • staticData

      public final State staticData()
      Specifies whether this models data should be considered static, that is, only fetched once. Note that forceRefresh() disregards this directive.
      Returns:
      the State controlling whether the data is regarded as static
    • setNullCaption

      public final void setNullCaption(String nullCaption)
      Enables the null item and sets the null item caption.
      Parameters:
      nullCaption - the null item caption
      Throws:
      NullPointerException - in case nullCaption is null
      See Also:
    • attributes

      public final ValueSet<Attribute<?>> attributes()
      Controls the attributes to include when selecting the entities to populate this model with. Note that the primary key attribute values are always included. An empty Collection indicates that all attributes should be selected.
      Returns:
      the ValueSet controlling the attributes to select, an empty ValueSet indicating all available attributes
    • respondToEditEvents

      public final State respondToEditEvents()
      Returns:
      the state controlling whether this combo box model should respond to entity edit events, by adding inserted items, updating any updated items and removing deleted ones
      See Also:
    • find

      public final Optional<Entity> find(Entity.Key primaryKey)
      Parameters:
      primaryKey - the primary key of the entity to fetch from this model
      Returns:
      the entity with the given key if found in the model, an empty Optional otherwise
    • select

      public final void select(Entity.Key primaryKey)
      Selects the entity with the given primary key, whether filtered or visible. If the entity is not available in the model this method returns silently without changing the selection.
      Parameters:
      primaryKey - the primary key of the entity to select
    • condition

      public final Value<Supplier<Condition>> condition()
      Controls the condition supplier to use when querying data, set to null to fetch all underlying entities.
      Returns:
      a value controlling the condition supplier
    • orderBy

      public final Value<OrderBy> orderBy()
      Controls the order by to use when selecting entities for this model. Note that in order for this to have an effect, you must disable sorting by setting the sort comparator to null (FilteredComboBoxModel.comparator()
      Returns:
      the Value controlling the orderBy
      See Also:
    • foreignKeyIncludeCondition

      public final Predicate<Entity> foreignKeyIncludeCondition()
      Use this method to retrieve the default foreign key filter include condition if you want to add a custom Predicate to this model via FilteredComboBoxModel.includeCondition().
         Predicate fkCondition = model.foreignKeyIncludeCondition();
         model.includeCondition().set(item -> fkCondition.test(item) && ...);
       
      Returns:
      the Predicate based on the foreign key filter entities
      See Also:
    • setForeignKeyFilterKeys

      public final void setForeignKeyFilterKeys(ForeignKey foreignKey, Collection<Entity.Key> keys)
      Filters this combo box model so that only items referencing the given keys via the given foreign key are shown.
      Parameters:
      foreignKey - the foreign key
      keys - the keys, null or empty for none
    • getForeignKeyFilterKeys

      public final Collection<Entity.Key> getForeignKeyFilterKeys(ForeignKey foreignKey)
      Parameters:
      foreignKey - the foreign key
      Returns:
      the keys currently used to filter the items of this model by foreign key, an empty collection for none
    • strictForeignKeyFiltering

      public final State strictForeignKeyFiltering()
      Controls whether foreign key filtering should be strict or not. When the filtering is strict only entities with the correct reference are included, that is, entities with null values for the given foreign key are filtered. Non-strict simply means that entities with null references are not filtered.
      Returns:
      the State controlling whether foreign key filtering should be strict
      See Also:
    • createForeignKeyFilterComboBoxModel

      public final EntityComboBoxModel createForeignKeyFilterComboBoxModel(ForeignKey foreignKey)
      Returns a combo box model for selecting a foreign key value for filtering this model.
      Parameters:
      foreignKey - the foreign key
      Returns:
      a combo box model for selecting a filtering value for this combo box model
      See Also:
    • createForeignKeyConditionComboBoxModel

      public final EntityComboBoxModel createForeignKeyConditionComboBoxModel(ForeignKey foreignKey)
      Returns a combo box model for selecting a foreign key value for using as a condition this model. Note that each time the selection changes in the created model this model is refreshed.
      Parameters:
      foreignKey - the foreign key
      Returns:
      a combo box model for selecting a filtering value for this combo box model
      See Also:
    • linkForeignKeyFilterComboBoxModel

      public final void linkForeignKeyFilterComboBoxModel(ForeignKey foreignKey, EntityComboBoxModel foreignKeyModel)
      Links the given combo box model representing master entities to this combo box model so that selection in the master model filters this model according to the selected master entity
      Parameters:
      foreignKey - the foreign key attribute
      foreignKeyModel - the combo box model to link
    • linkForeignKeyConditionComboBoxModel

      public final void linkForeignKeyConditionComboBoxModel(ForeignKey foreignKey, EntityComboBoxModel foreignKeyModel)
      Links the given combo box model representing master entities to this combo box model so that selection in the master model refreshes this model with the selected master entity as condition
      Parameters:
      foreignKey - the foreign key attribute
      foreignKeyModel - the combo box model to link
    • createSelectorValue

      public final <T> Value<T> createSelectorValue(Attribute<T> attribute)
      Creates a Value linked to the selected entity via the value of the given attribute.
      Type Parameters:
      T - the attribute type
      Parameters:
      attribute - the attribute
      Returns:
      a Value for selecting items by attribute value
    • performQuery

      protected Collection<Entity> performQuery()
      Retrieves the entities to present in this EntityComboBoxModel, taking into account the condition supplier (condition()) as well as the select attributes (attributes()) and order by clause (orderBy().
      Returns:
      the entities to present in this EntityComboBoxModel
      See Also: