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

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

    Nested classes/interfaces inherited from interface is.codion.swing.common.model.component.combobox.FilterComboBoxModel

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

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

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

    Fields
    Modifier and Type
    Field
    Description
    static final is.codion.common.property.PropertyValue<Boolean>
    Specifies whether entity combo box models handle entity edit events, by replacing updated entities and removing deleted ones
    Value type: Boolean
    Default value: true

    Fields inherited from interface is.codion.swing.common.model.component.combobox.FilterComboBoxModel

    COMBO_BOX_NULL_CAPTION

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

    ASYNC_REFRESH
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(is.codion.framework.domain.entity.Entity item)
     
    void
     
    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.
    void
     
    boolean
     
    is.codion.common.value.Value<Comparator<is.codion.framework.domain.entity.Entity>>
     
    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.
    is.codion.framework.db.EntityConnectionProvider
     
    boolean
    containsItem(is.codion.framework.domain.entity.Entity item)
     
    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.
    <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.
    <V> is.codion.common.value.Value<V>
    createSelectorValue(is.codion.swing.common.model.component.combobox.FilterComboBoxModel.ItemFinder<is.codion.framework.domain.entity.Entity,V> itemFinder)
     
    entityComboBoxModel(is.codion.framework.domain.entity.EntityType entityType, is.codion.framework.db.EntityConnectionProvider connectionProvider)
     
    is.codion.framework.domain.entity.EntityType
     
    boolean
    filtered(is.codion.framework.domain.entity.Entity item)
     
    int
     
    Collection<is.codion.framework.domain.entity.Entity>
     
    void
     
    is.codion.common.state.State
     
    Optional<is.codion.framework.domain.entity.Entity>
    find(is.codion.framework.domain.entity.Entity.Key primaryKey)
     
    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 includeCondition().
    is.codion.framework.domain.entity.Entity
    getElementAt(int index)
     
    Collection<is.codion.framework.domain.entity.Entity.Key>
    getForeignKeyFilterKeys(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey)
     
    is.codion.framework.domain.entity.Entity
     
    int
     
    is.codion.common.state.State
     
    is.codion.common.value.Value<Predicate<is.codion.framework.domain.entity.Entity>>
     
    is.codion.common.state.State
     
    Collection<is.codion.framework.domain.entity.Entity>
     
    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
    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
    is.codion.common.value.Value<is.codion.framework.domain.entity.Entity>
     
    boolean
     
    is.codion.common.value.Value<is.codion.framework.domain.entity.OrderBy>
    Controls the order by to use when selecting entities for this model.
    void
     
    is.codion.common.model.FilterModel.Refresher<is.codion.framework.domain.entity.Entity>
     
    void
    refreshThen(Consumer<Collection<is.codion.framework.domain.entity.Entity>> afterRefresh)
     
    void
    remove(is.codion.framework.domain.entity.Entity item)
     
    void
     
    void
    replace(is.codion.framework.domain.entity.Entity item, is.codion.framework.domain.entity.Entity replacement)
     
    void
    select(is.codion.framework.domain.entity.Entity.Key primaryKey)
    Selects the entity with the given primary key, whether filtered or visible.
    is.codion.common.value.Value<Function<Object,is.codion.framework.domain.entity.Entity>>
     
    is.codion.framework.domain.entity.Entity
     
    is.codion.common.state.StateObserver
     
    is.codion.common.event.EventObserver<is.codion.framework.domain.entity.Entity>
     
    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.
    void
    setItems(Collection<is.codion.framework.domain.entity.Entity> items)
     
    void
    setNullCaption(String nullCaption)
    Enables the null item and sets the null item caption.
    void
    setSelectedItem(Object selectedItem)
     
    void
     
    is.codion.common.state.State
    Controls whether foreign key filtering should be strict or not.
     
    is.codion.common.value.Value<Predicate<is.codion.framework.domain.entity.Entity>>
     
    is.codion.common.value.Value<Predicate<is.codion.framework.domain.entity.Entity>>
     
    boolean
    visible(is.codion.framework.domain.entity.Entity item)
     
    int
     
    List<is.codion.framework.domain.entity.Entity>
     

    Methods inherited from class java.lang.Object

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

    • HANDLE_EDIT_EVENTS

      public static final is.codion.common.property.PropertyValue<Boolean> HANDLE_EDIT_EVENTS
      Specifies whether entity combo box models handle entity edit events, by replacing updated entities and removing deleted ones
      Value type: Boolean
      Default value: true
      See Also:
  • Method Details

    • toString

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

      public is.codion.framework.db.EntityConnectionProvider connectionProvider()
      Returns:
      the connection provider used by this combo box model
    • entityType

      public is.codion.framework.domain.entity.EntityType entityType()
      Returns:
      the type of the entity this combo box model is based on
    • setNullCaption

      public 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 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 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 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 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 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 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 (comparator()
      Returns:
      the Value controlling the orderBy
      See Also:
    • foreignKeyIncludeCondition

      public 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 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 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, an empty Collection for none
    • getForeignKeyFilterKeys

      public 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 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 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 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 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 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 <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
    • clear

      public void clear()
      Specified by:
      clear in interface is.codion.swing.common.model.component.combobox.FilterComboBoxModel<is.codion.framework.domain.entity.Entity>
    • cleared

      public boolean cleared()
      Specified by:
      cleared in interface is.codion.swing.common.model.component.combobox.FilterComboBoxModel<is.codion.framework.domain.entity.Entity>
    • setItems

      public void setItems(Collection<is.codion.framework.domain.entity.Entity> items)
      Specified by:
      setItems in interface is.codion.swing.common.model.component.combobox.FilterComboBoxModel<is.codion.framework.domain.entity.Entity>
    • add

      public void add(is.codion.framework.domain.entity.Entity item)
      Specified by:
      add in interface is.codion.swing.common.model.component.combobox.FilterComboBoxModel<is.codion.framework.domain.entity.Entity>
    • remove

      public void remove(is.codion.framework.domain.entity.Entity item)
      Specified by:
      remove in interface is.codion.swing.common.model.component.combobox.FilterComboBoxModel<is.codion.framework.domain.entity.Entity>
    • replace

      public void replace(is.codion.framework.domain.entity.Entity item, is.codion.framework.domain.entity.Entity replacement)
      Specified by:
      replace in interface is.codion.swing.common.model.component.combobox.FilterComboBoxModel<is.codion.framework.domain.entity.Entity>
    • sortItems

      public void sortItems()
      Specified by:
      sortItems in interface is.codion.swing.common.model.component.combobox.FilterComboBoxModel<is.codion.framework.domain.entity.Entity>
    • comparator

      public is.codion.common.value.Value<Comparator<is.codion.framework.domain.entity.Entity>> comparator()
      Specified by:
      comparator in interface is.codion.swing.common.model.component.combobox.FilterComboBoxModel<is.codion.framework.domain.entity.Entity>
    • validator

      public is.codion.common.value.Value<Predicate<is.codion.framework.domain.entity.Entity>> validator()
      Specified by:
      validator in interface is.codion.swing.common.model.component.combobox.FilterComboBoxModel<is.codion.framework.domain.entity.Entity>
    • selectedItemTranslator

      public is.codion.common.value.Value<Function<Object,is.codion.framework.domain.entity.Entity>> selectedItemTranslator()
      Specified by:
      selectedItemTranslator in interface is.codion.swing.common.model.component.combobox.FilterComboBoxModel<is.codion.framework.domain.entity.Entity>
    • validSelectionPredicate

      public is.codion.common.value.Value<Predicate<is.codion.framework.domain.entity.Entity>> validSelectionPredicate()
      Specified by:
      validSelectionPredicate in interface is.codion.swing.common.model.component.combobox.FilterComboBoxModel<is.codion.framework.domain.entity.Entity>
    • includeNull

      public is.codion.common.state.State includeNull()
      Specified by:
      includeNull in interface is.codion.swing.common.model.component.combobox.FilterComboBoxModel<is.codion.framework.domain.entity.Entity>
    • nullItem

      public is.codion.common.value.Value<is.codion.framework.domain.entity.Entity> nullItem()
      Specified by:
      nullItem in interface is.codion.swing.common.model.component.combobox.FilterComboBoxModel<is.codion.framework.domain.entity.Entity>
    • nullSelected

      public boolean nullSelected()
      Specified by:
      nullSelected in interface is.codion.swing.common.model.component.combobox.FilterComboBoxModel<is.codion.framework.domain.entity.Entity>
    • selectionEmpty

      public is.codion.common.state.StateObserver selectionEmpty()
      Specified by:
      selectionEmpty in interface is.codion.swing.common.model.component.combobox.FilterComboBoxModel<is.codion.framework.domain.entity.Entity>
    • selectedValue

      public is.codion.framework.domain.entity.Entity selectedValue()
      Specified by:
      selectedValue in interface is.codion.swing.common.model.component.combobox.FilterComboBoxModel<is.codion.framework.domain.entity.Entity>
    • getSelectedItem

      public is.codion.framework.domain.entity.Entity getSelectedItem()
      Specified by:
      getSelectedItem in interface ComboBoxModel<is.codion.framework.domain.entity.Entity>
      Specified by:
      getSelectedItem in interface is.codion.swing.common.model.component.combobox.FilterComboBoxModel<is.codion.framework.domain.entity.Entity>
    • filterSelectedItem

      public is.codion.common.state.State filterSelectedItem()
      Specified by:
      filterSelectedItem in interface is.codion.swing.common.model.component.combobox.FilterComboBoxModel<is.codion.framework.domain.entity.Entity>
    • createSelectorValue

      public <V> is.codion.common.value.Value<V> createSelectorValue(is.codion.swing.common.model.component.combobox.FilterComboBoxModel.ItemFinder<is.codion.framework.domain.entity.Entity,V> itemFinder)
      Specified by:
      createSelectorValue in interface is.codion.swing.common.model.component.combobox.FilterComboBoxModel<is.codion.framework.domain.entity.Entity>
    • selectionEvent

      public is.codion.common.event.EventObserver<is.codion.framework.domain.entity.Entity> selectionEvent()
      Specified by:
      selectionEvent in interface is.codion.swing.common.model.component.combobox.FilterComboBoxModel<is.codion.framework.domain.entity.Entity>
    • filterItems

      public void filterItems()
      Specified by:
      filterItems in interface is.codion.common.model.FilterModel<is.codion.framework.domain.entity.Entity>
    • includeCondition

      public is.codion.common.value.Value<Predicate<is.codion.framework.domain.entity.Entity>> includeCondition()
      Specified by:
      includeCondition in interface is.codion.common.model.FilterModel<is.codion.framework.domain.entity.Entity>
    • items

      public Collection<is.codion.framework.domain.entity.Entity> items()
      Specified by:
      items in interface is.codion.common.model.FilterModel<is.codion.framework.domain.entity.Entity>
    • visibleItems

      public List<is.codion.framework.domain.entity.Entity> visibleItems()
      Specified by:
      visibleItems in interface is.codion.common.model.FilterModel<is.codion.framework.domain.entity.Entity>
    • filteredItems

      public Collection<is.codion.framework.domain.entity.Entity> filteredItems()
      Specified by:
      filteredItems in interface is.codion.common.model.FilterModel<is.codion.framework.domain.entity.Entity>
    • visibleCount

      public int visibleCount()
      Specified by:
      visibleCount in interface is.codion.common.model.FilterModel<is.codion.framework.domain.entity.Entity>
    • filteredCount

      public int filteredCount()
      Specified by:
      filteredCount in interface is.codion.common.model.FilterModel<is.codion.framework.domain.entity.Entity>
    • containsItem

      public boolean containsItem(is.codion.framework.domain.entity.Entity item)
      Specified by:
      containsItem in interface is.codion.common.model.FilterModel<is.codion.framework.domain.entity.Entity>
    • visible

      public boolean visible(is.codion.framework.domain.entity.Entity item)
      Specified by:
      visible in interface is.codion.common.model.FilterModel<is.codion.framework.domain.entity.Entity>
    • filtered

      public boolean filtered(is.codion.framework.domain.entity.Entity item)
      Specified by:
      filtered in interface is.codion.common.model.FilterModel<is.codion.framework.domain.entity.Entity>
    • refresher

      public is.codion.common.model.FilterModel.Refresher<is.codion.framework.domain.entity.Entity> refresher()
      Specified by:
      refresher in interface is.codion.common.model.FilterModel<is.codion.framework.domain.entity.Entity>
    • refresh

      public void refresh()
      Specified by:
      refresh in interface is.codion.common.model.FilterModel<is.codion.framework.domain.entity.Entity>
    • refreshThen

      public void refreshThen(Consumer<Collection<is.codion.framework.domain.entity.Entity>> afterRefresh)
      Specified by:
      refreshThen in interface is.codion.common.model.FilterModel<is.codion.framework.domain.entity.Entity>
    • setSelectedItem

      public void setSelectedItem(Object selectedItem)
      Specified by:
      setSelectedItem in interface ComboBoxModel<is.codion.framework.domain.entity.Entity>
    • getSize

      public int getSize()
      Specified by:
      getSize in interface ListModel<is.codion.framework.domain.entity.Entity>
    • getElementAt

      public is.codion.framework.domain.entity.Entity getElementAt(int index)
      Specified by:
      getElementAt in interface ListModel<is.codion.framework.domain.entity.Entity>
    • addListDataListener

      public void addListDataListener(ListDataListener listener)
      Specified by:
      addListDataListener in interface ListModel<is.codion.framework.domain.entity.Entity>
    • removeListDataListener

      public void removeListDataListener(ListDataListener listener)
      Specified by:
      removeListDataListener in interface ListModel<is.codion.framework.domain.entity.Entity>
    • entityComboBoxModel

      public static EntityComboBoxModel 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
      Returns:
      a new EntityComboBoxModel instance