Class EntityComboBoxModel
java.lang.Object
is.codion.swing.framework.model.component.EntityComboBoxModel
- All Implemented Interfaces:
FilterModel<Entity>
,FilterComboBoxModel<Entity>
,ComboBoxModel<Entity>
,ListModel<Entity>
A ComboBoxModel based on an Entity, showing by default all the entities in the underlying table.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Provides a combo box for filtering this combo box instance, either by filter predicate or query condition.static interface
Links a given combo box model representing master entities to this combo box model so that selection in the master model filters this model, either filter predicate or query conditionNested classes/interfaces inherited from interface is.codion.swing.common.model.component.combobox.FilterComboBoxModel
FilterComboBoxModel.ComboBoxItems<T>, FilterComboBoxModel.ComboBoxSelection<T>, FilterComboBoxModel.ItemFinder<T,
V>, FilterComboBoxModel.NullItem<T> Nested classes/interfaces inherited from interface is.codion.common.model.FilterModel
FilterModel.AbstractRefresher<T>, FilterModel.FilteredItems<T>, FilterModel.Items<T>, FilterModel.Refresher<T>, FilterModel.VisibleItems<T>
-
Field Summary
Modifier and TypeFieldDescriptionstatic final 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: trueFields inherited from interface is.codion.swing.common.model.component.combobox.FilterComboBoxModel
NULL_CAPTION
Fields inherited from interface is.codion.common.model.FilterModel
ASYNC_REFRESH
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addListDataListener
(ListDataListener listener) Controls 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.<T> Value<T>
createSelectorValue
(Attribute<T> attribute) Creates aValue
linked to the selected entity via the value of the given attribute.<V> Value<V>
createSelectorValue
(FilterComboBoxModel.ItemFinder<Entity, V> itemFinder) static EntityComboBoxModel
entityComboBoxModel
(EntityType entityType, EntityConnectionProvider connectionProvider) void
filterByForeignKey
(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 visible.find
(Entity.Key primaryKey) foreignKeyComboBoxModel
(ForeignKey foreignKey) foreignKeyComboBoxModelLinker
(ForeignKey foreignKey) foreignKeyFilterKeys
(ForeignKey foreignKey) Use this method to retrieve the default foreign key filter visible predicate if you want to add a customPredicate
to this model viaFilterModel.VisibleItems.predicate()
.getElementAt
(int index) int
getSize()
items()
orderBy()
Controls the order by to use when selecting entities for this model.void
refresh()
Refreshes the items in this model using itsFilterModel.Refresher
.void
refresh
(Consumer<Collection<Entity>> onRefresh) Refreshes the data in this filter model using itsFilterModel.Refresher
.void
removeListDataListener
(ListDataListener listener) void
select
(Entity.Key primaryKey) Selects the entity with the given primary key, whether filtered or visible.void
setNullCaption
(String nullCaption) Enables the null item and sets the null item caption.void
setSelectedItem
(Object selectedItem) Controls whether foreign key filtering should be strict or not.toString()
-
Field Details
-
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
-
-
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
-
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. -
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:
-
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 viaFilterModel.VisibleItems.comparator()
-
foreignKeyVisiblePredicate
Use this method to retrieve the default foreign key filter visible predicate if you want to add a customPredicate
to this model viaFilterModel.VisibleItems.predicate()
.Predicate fkPredicate = model.foreignKeyVisiblePredicate(); model.items().visiblePredicate().set(item -> fkPredicate.test(item) && ...);
- Returns:
- the
Predicate
based on the foreign key filter entities - See Also:
-
filterByForeignKey
Filters this combo box model so that only items referencing the given keys via the given foreign key are visible. Note that this uses theFilterModel.VisibleItems.predicate()
and replaces any previously set prediate.- Parameters:
foreignKey
- the foreign keykeys
- the keys, an empty Collection to clear the filter- See Also:
-
foreignKeyFilterKeys
- 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
- See Also:
-
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:
-
foreignKeyComboBoxModel
public EntityComboBoxModel.ForeignKeyComboBoxModelFactory foreignKeyComboBoxModel(ForeignKey foreignKey) - Parameters:
foreignKey
- the foreign key- Returns:
- a new
EntityComboBoxModel.ForeignKeyComboBoxModelFactory
-
foreignKeyComboBoxModelLinker
public EntityComboBoxModel.ForeignKeyComboBoxModelLinker foreignKeyComboBoxModelLinker(ForeignKey foreignKey) - Parameters:
foreignKey
- the foreign key- Returns:
- a new
EntityComboBoxModel.ForeignKeyComboBoxModelLinker
-
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
-
selection
- Specified by:
selection
in interfaceFilterComboBoxModel<Entity>
- Specified by:
selection
in interfaceFilterModel<Entity>
- Returns:
- the
SingleItemSelection
instance used by this filter model
-
getSelectedItem
- Specified by:
getSelectedItem
in interfaceComboBoxModel<Entity>
- Specified by:
getSelectedItem
in interfaceFilterComboBoxModel<Entity>
- Returns:
- the selected item, N.B. this can include the
nullItem
in case it has been set viaFilterComboBoxModel.ComboBoxItems.nullItem()
,FilterComboBoxModel.ComboBoxSelection.value()
is usually what you want
-
createSelectorValue
- Specified by:
createSelectorValue
in interfaceFilterComboBoxModel<Entity>
- Type Parameters:
V
- the value type- Parameters:
itemFinder
- responsible for finding the item to select- Returns:
- a
Value
linked to the selected item using the givenFilterComboBoxModel.ItemFinder
instance
-
items
- Specified by:
items
in interfaceFilterComboBoxModel<Entity>
- Specified by:
items
in interfaceFilterModel<Entity>
- Returns:
- the model items
-
refresher
- Specified by:
refresher
in interfaceFilterModel<Entity>
- Returns:
- this models Refresher instance
-
refresh
public void refresh()Description copied from interface:FilterModel
Refreshes the items in this model using itsFilterModel.Refresher
.- Specified by:
refresh
in interfaceFilterModel<Entity>
- See Also:
-
refresh
Description copied from interface:FilterModel
Refreshes the data in this filter model using itsFilterModel.Refresher
. Note that this method only throws exceptions when run synchronously off the user interface thread. UseFilterModel.Refresher.failure()
to listen for exceptions that happen during asynchronous refresh.- Specified by:
refresh
in interfaceFilterModel<Entity>
- Parameters:
onRefresh
- called after a successful refresh, may be null- See Also:
-
setSelectedItem
- Specified by:
setSelectedItem
in interfaceComboBoxModel<Entity>
-
getSize
public int getSize() -
getElementAt
- Specified by:
getElementAt
in interfaceListModel<Entity>
-
addListDataListener
- Specified by:
addListDataListener
in interfaceListModel<Entity>
-
removeListDataListener
- Specified by:
removeListDataListener
in interfaceListModel<Entity>
-
entityComboBoxModel
public static EntityComboBoxModel entityComboBoxModel(EntityType entityType, EntityConnectionProvider connectionProvider) - Parameters:
entityType
- the type of the entity this combo box model should representconnectionProvider
- a EntityConnectionProvider instance- Returns:
- a new
EntityComboBoxModel
instance
-