Class EntityComboBoxModel
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>
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
FilteredComboBoxModel.ItemFinder<T,
V> Nested classes/interfaces inherited from interface is.codion.common.model.FilteredModel
FilteredModel.AbstractRefresher<T>, FilteredModel.Refresher<T>
-
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
ConstructorDescriptionEntityComboBoxModel
(EntityType entityType, EntityConnectionProvider connectionProvider) -
Method Summary
Modifier and TypeMethodDescriptionControls the attributes to include when selecting the entities to populate this model with.Controls the condition supplier to use when querying data, set to null to fetch all underlying entities.final EntityConnectionProvider
final EntityComboBoxModel
createForeignKeyConditionComboBoxModel
(ForeignKey foreignKey) Returns a combo box model for selecting a foreign key value for using as a condition this model.final EntityComboBoxModel
createForeignKeyFilterComboBoxModel
(ForeignKey foreignKey) Returns a combo box model for selecting a foreign key value for filtering this model.final <T> Value<T>
createSelectorValue
(Attribute<T> attribute) Creates aValue
linked to the selected entity via the value of the given attribute.final EntityType
find
(Entity.Key primaryKey) final void
Forces a refresh of this model, disregarding the staticData directiveUse this method to retrieve the default foreign key filter include condition if you want to add a customPredicate
to this model viaFilteredComboBoxModel.includeCondition()
.final Collection<Entity.Key>
getForeignKeyFilterKeys
(ForeignKey foreignKey) 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 conditionfinal 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 entityorderBy()
Controls the order by to use when selecting entities for this model.protected Collection<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 State
final void
select
(Entity.Key primaryKey) Selects the entity with the given primary key, whether filtered or visible.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.final void
setNullCaption
(String nullCaption) Enables the null item and sets the null item caption.final State
Specifies whether this models data should be considered static, that is, only fetched once.final State
Controls whether foreign key filtering should be strict or not.final String
toString()
Methods inherited from class is.codion.swing.common.model.component.combobox.FilteredComboBoxModel
add, addListDataListener, addSelectionListener, allowSelectionPredicate, 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, visible, visibleCount, visibleItems
-
Constructor Details
-
EntityComboBoxModel
- Parameters:
entityType
- the type of the entity this combo box model should representconnectionProvider
- a EntityConnectionProvider instance
-
-
Method Details
-
toString
-
connectionProvider
- Returns:
- the connection provider used by this combo box model
-
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
Specifies whether this models data should be considered static, that is, only fetched once. Note thatforceRefresh()
disregards this directive.- Returns:
- the State controlling whether the data is regarded as static
-
setNullCaption
Enables the null item and sets the null item caption.- Parameters:
nullCaption
- the null item caption- Throws:
NullPointerException
- in casenullCaption
is null- See Also:
-
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
- 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
- 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
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
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
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
Use this method to retrieve the default foreign key filter include condition if you want to add a customPredicate
to this model viaFilteredComboBoxModel.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
Filters this combo box model so that only items referencing the given keys via the given foreign key are shown.- Parameters:
foreignKey
- the foreign keykeys
- the keys, null or empty for none
-
getForeignKeyFilterKeys
- 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
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
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
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 attributeforeignKeyModel
- 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 attributeforeignKeyModel
- the combo box model to link
-
createSelectorValue
Creates aValue
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
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:
-