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

public class EntityComboBoxModel extends is.codion.swing.common.model.component.combobox.FilteredComboBoxModel<is.codion.framework.domain.entity.Entity>
A ComboBoxModel based on an Entity, showing by default all the entities in the underlying table.
  • Nested Class Summary

    Nested classes/interfaces inherited from class is.codion.swing.common.model.component.combobox.FilteredComboBoxModel

    is.codion.swing.common.model.component.combobox.FilteredComboBoxModel.ItemFinder<T extends Object,V extends Object>

    Nested classes/interfaces inherited from interface is.codion.common.model.FilteredModel

    is.codion.common.model.FilteredModel.AbstractRefresher<T extends Object>, is.codion.common.model.FilteredModel.Refresher<T extends Object>
  • Field Summary

    Fields inherited from class is.codion.swing.common.model.component.combobox.FilteredComboBoxModel

    COMBO_BOX_NULL_CAPTION

    Fields inherited from interface is.codion.common.model.FilteredModel

    ASYNC_REFRESH
  • Constructor Summary

    Constructors
    Constructor
    Description
    EntityComboBoxModel(is.codion.framework.domain.entity.EntityType entityType, is.codion.framework.db.EntityConnectionProvider connectionProvider)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    final is.codion.common.value.ValueSet<is.codion.framework.domain.entity.attribute.Attribute<?>>
    Controls the attributes to include when selecting the entities to populate this model with.
    final is.codion.common.value.Value<Supplier<is.codion.framework.domain.entity.condition.Condition>>
    Controls the condition supplier to use when querying data, set to null to fetch all underlying entities.
    final is.codion.framework.db.EntityConnectionProvider
     
    createForeignKeyConditionComboBoxModel(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey)
    Returns a combo box model for selecting a foreign key value for using as a condition this model.
    createForeignKeyFilterComboBoxModel(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey)
    Returns a combo box model for selecting a foreign key value for filtering this model.
    final <T> is.codion.common.value.Value<T>
    createSelectorValue(is.codion.framework.domain.entity.attribute.Attribute<T> attribute)
    Creates a Value linked to the selected entity via the value of the given attribute.
    final is.codion.framework.domain.entity.EntityType
     
    final Optional<is.codion.framework.domain.entity.Entity>
    find(is.codion.framework.domain.entity.Entity.Key primaryKey)
     
    final Predicate<is.codion.framework.domain.entity.Entity>
    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().
    final Collection<is.codion.framework.domain.entity.Entity.Key>
    getForeignKeyFilterKeys(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey)
     
    final is.codion.common.state.State
     
    final void
    linkForeignKeyConditionComboBoxModel(is.codion.framework.domain.entity.attribute.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
    final void
    linkForeignKeyFilterComboBoxModel(is.codion.framework.domain.entity.attribute.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
    final is.codion.common.value.Value<is.codion.framework.domain.entity.OrderBy>
    Controls the order by to use when selecting entities for this model.
    protected Collection<is.codion.framework.domain.entity.Entity>
    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().
    final void
    select(is.codion.framework.domain.entity.Entity.Key primaryKey)
    Selects the entity with the given primary key, whether filtered or visible.
    final void
    setForeignKeyFilterKeys(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey, Collection<is.codion.framework.domain.entity.Entity.Key> keys)
    Filters this combo box model so that only items referencing the given keys via the given foreign key are shown.
    final void
    setNullCaption(String nullCaption)
    Enables the null item and sets the null item caption.
    final is.codion.common.state.State
    Controls whether foreign key filtering should be strict or not.
    final String
     

    Methods inherited from class is.codion.swing.common.model.component.combobox.FilteredComboBoxModel

    add, addListDataListener, addSelectionListener, clear, cleared, comparator, containsItem, createSelectorValue, filtered, filteredCount, filteredItems, filterItems, filterSelectedItem, getElementAt, getSelectedItem, getSize, includeCondition, includeNull, items, itemValidator, nullItem, nullSelected, refresh, refresher, refreshThen, remove, removeListDataListener, removeSelectionListener, replace, selectedItemTranslator, selectedValue, selectionEmpty, setItems, setSelectedItem, validSelectionPredicate, visible, visibleCount, visibleItems

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • EntityComboBoxModel

      public EntityComboBoxModel(is.codion.framework.domain.entity.EntityType entityType, is.codion.framework.db.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 is.codion.framework.db.EntityConnectionProvider connectionProvider()
      Returns:
      the connection provider used by this combo box model
    • entityType

      public final is.codion.framework.domain.entity.EntityType entityType()
      Returns:
      the type of the entity this combo box model is based on
    • 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:
      • FilteredComboBoxModel.includeNull()
      • FilteredComboBoxModel.nullItem()
    • attributes

      public final is.codion.common.value.ValueSet<is.codion.framework.domain.entity.attribute.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
    • handleEditEvents

      public final is.codion.common.state.State handleEditEvents()
      Returns:
      the state controlling whether this combo box model should handle entity edit events, by adding inserted items, updating any updated items and removing deleted ones
      See Also:
      • EntityEditEvents
    • find

      public final Optional<is.codion.framework.domain.entity.Entity> find(is.codion.framework.domain.entity.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(is.codion.framework.domain.entity.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 is.codion.common.value.Value<Supplier<is.codion.framework.domain.entity.condition.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 is.codion.common.value.Value<is.codion.framework.domain.entity.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:
      • FilteredComboBoxModel.comparator()
    • foreignKeyIncludeCondition

      public final Predicate<is.codion.framework.domain.entity.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(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey, Collection<is.codion.framework.domain.entity.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<is.codion.framework.domain.entity.Entity.Key> getForeignKeyFilterKeys(is.codion.framework.domain.entity.attribute.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 is.codion.common.state.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(is.codion.framework.domain.entity.attribute.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(is.codion.framework.domain.entity.attribute.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(is.codion.framework.domain.entity.attribute.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(is.codion.framework.domain.entity.attribute.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> is.codion.common.value.Value<T> createSelectorValue(is.codion.framework.domain.entity.attribute.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<is.codion.framework.domain.entity.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: