Class EntityComboBoxModel
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.
-
Nested Class Summary
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic 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: trueFields inherited from interface is.codion.swing.common.model.component.combobox.FilterComboBoxModel
COMBO_BOX_NULL_CAPTIONFields inherited from interface is.codion.common.model.FilterModel
ASYNC_REFRESH -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(is.codion.framework.domain.entity.Entity item) voidaddListDataListener(ListDataListener listener) 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.voidclear()booleancleared()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.EntityConnectionProviderbooleancontainsItem(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 aValuelinked 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) static EntityComboBoxModelentityComboBoxModel(is.codion.framework.domain.entity.EntityType entityType, is.codion.framework.db.EntityConnectionProvider connectionProvider) is.codion.framework.domain.entity.EntityTypebooleanfiltered(is.codion.framework.domain.entity.Entity item) intCollection<is.codion.framework.domain.entity.Entity>voidis.codion.common.state.StateOptional<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 customPredicateto this model viaincludeCondition().is.codion.framework.domain.entity.EntitygetElementAt(int index) Collection<is.codion.framework.domain.entity.Entity.Key>getForeignKeyFilterKeys(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey) is.codion.framework.domain.entity.EntityintgetSize()is.codion.common.state.Stateis.codion.common.value.Value<Predicate<is.codion.framework.domain.entity.Entity>>is.codion.common.state.StateCollection<is.codion.framework.domain.entity.Entity>items()voidlinkForeignKeyConditionComboBoxModel(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 conditionvoidlinkForeignKeyFilterComboBoxModel(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 entityis.codion.common.value.Value<is.codion.framework.domain.entity.Entity>nullItem()booleanis.codion.common.value.Value<is.codion.framework.domain.entity.OrderBy>orderBy()Controls the order by to use when selecting entities for this model.voidrefresh()is.codion.common.model.FilterModel.Refresher<is.codion.framework.domain.entity.Entity>voidrefreshThen(Consumer<Collection<is.codion.framework.domain.entity.Entity>> afterRefresh) voidremove(is.codion.framework.domain.entity.Entity item) voidremoveListDataListener(ListDataListener listener) voidreplace(is.codion.framework.domain.entity.Entity item, is.codion.framework.domain.entity.Entity replacement) voidselect(is.codion.framework.domain.entity.Entity.Key primaryKey) Selects the entity with the given primary key, whether filtered or visible.is.codion.framework.domain.entity.Entityis.codion.common.state.StateObserveris.codion.common.event.EventObserver<is.codion.framework.domain.entity.Entity>voidsetForeignKeyFilterKeys(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.voidsetItems(Collection<is.codion.framework.domain.entity.Entity> items) voidsetNullCaption(String nullCaption) Enables the null item and sets the null item caption.voidsetSelectedItem(Object selectedItem) voidis.codion.common.state.StateControls whether foreign key filtering should be strict or not.toString()is.codion.common.value.Value<Predicate<is.codion.framework.domain.entity.Entity>>is.codion.common.value.Value<Predicate<is.codion.framework.domain.entity.Entity>>booleanvisible(is.codion.framework.domain.entity.Entity item) intList<is.codion.framework.domain.entity.Entity>
-
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- See Also:
-
handleEditEvents()EntityEditModel.POST_EDIT_EVENTS
-
-
Method Details
-
toString
-
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
Enables the null item and sets the null item caption.- Parameters:
nullCaption- the null item caption- Throws:
NullPointerException- in casenullCaptionis 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
Use this method to retrieve the default foreign key filter include condition if you want to add a customPredicateto this model viaincludeCondition().Predicate fkCondition = model.foreignKeyIncludeCondition(); model.includeCondition().set(item -> fkCondition.test(item) && ...);
- Returns:
- the
Predicatebased 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 keykeys- 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 attributeforeignKeyModel- 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 attributeforeignKeyModel- 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 aValuelinked to the selected entity via the value of the given attribute.- Type Parameters:
T- the attribute type- Parameters:
attribute- the attribute- Returns:
- a
Valuefor selecting items by attribute value
-
clear
public void clear()- Specified by:
clearin interfaceis.codion.swing.common.model.component.combobox.FilterComboBoxModel<is.codion.framework.domain.entity.Entity>
-
cleared
public boolean cleared()- Specified by:
clearedin interfaceis.codion.swing.common.model.component.combobox.FilterComboBoxModel<is.codion.framework.domain.entity.Entity>
-
setItems
- Specified by:
setItemsin interfaceis.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:
addin interfaceis.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:
removein interfaceis.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:
replacein interfaceis.codion.swing.common.model.component.combobox.FilterComboBoxModel<is.codion.framework.domain.entity.Entity>
-
sortItems
public void sortItems()- Specified by:
sortItemsin interfaceis.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:
comparatorin interfaceis.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:
validatorin interfaceis.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:
selectedItemTranslatorin interfaceis.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:
validSelectionPredicatein interfaceis.codion.swing.common.model.component.combobox.FilterComboBoxModel<is.codion.framework.domain.entity.Entity>
-
includeNull
public is.codion.common.state.State includeNull()- Specified by:
includeNullin interfaceis.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:
nullItemin interfaceis.codion.swing.common.model.component.combobox.FilterComboBoxModel<is.codion.framework.domain.entity.Entity>
-
nullSelected
public boolean nullSelected()- Specified by:
nullSelectedin interfaceis.codion.swing.common.model.component.combobox.FilterComboBoxModel<is.codion.framework.domain.entity.Entity>
-
selectionEmpty
public is.codion.common.state.StateObserver selectionEmpty()- Specified by:
selectionEmptyin interfaceis.codion.swing.common.model.component.combobox.FilterComboBoxModel<is.codion.framework.domain.entity.Entity>
-
selectedValue
public is.codion.framework.domain.entity.Entity selectedValue()- Specified by:
selectedValuein interfaceis.codion.swing.common.model.component.combobox.FilterComboBoxModel<is.codion.framework.domain.entity.Entity>
-
getSelectedItem
public is.codion.framework.domain.entity.Entity getSelectedItem()- Specified by:
getSelectedItemin interfaceComboBoxModel<is.codion.framework.domain.entity.Entity>- Specified by:
getSelectedItemin interfaceis.codion.swing.common.model.component.combobox.FilterComboBoxModel<is.codion.framework.domain.entity.Entity>
-
filterSelectedItem
public is.codion.common.state.State filterSelectedItem()- Specified by:
filterSelectedItemin interfaceis.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:
createSelectorValuein interfaceis.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:
selectionEventin interfaceis.codion.swing.common.model.component.combobox.FilterComboBoxModel<is.codion.framework.domain.entity.Entity>
-
filterItems
public void filterItems()- Specified by:
filterItemsin interfaceis.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:
includeConditionin interfaceis.codion.common.model.FilterModel<is.codion.framework.domain.entity.Entity>
-
items
- Specified by:
itemsin interfaceis.codion.common.model.FilterModel<is.codion.framework.domain.entity.Entity>
-
visibleItems
- Specified by:
visibleItemsin interfaceis.codion.common.model.FilterModel<is.codion.framework.domain.entity.Entity>
-
filteredItems
- Specified by:
filteredItemsin interfaceis.codion.common.model.FilterModel<is.codion.framework.domain.entity.Entity>
-
visibleCount
public int visibleCount()- Specified by:
visibleCountin interfaceis.codion.common.model.FilterModel<is.codion.framework.domain.entity.Entity>
-
filteredCount
public int filteredCount()- Specified by:
filteredCountin interfaceis.codion.common.model.FilterModel<is.codion.framework.domain.entity.Entity>
-
containsItem
public boolean containsItem(is.codion.framework.domain.entity.Entity item) - Specified by:
containsItemin interfaceis.codion.common.model.FilterModel<is.codion.framework.domain.entity.Entity>
-
visible
public boolean visible(is.codion.framework.domain.entity.Entity item) - Specified by:
visiblein interfaceis.codion.common.model.FilterModel<is.codion.framework.domain.entity.Entity>
-
filtered
public boolean filtered(is.codion.framework.domain.entity.Entity item) - Specified by:
filteredin interfaceis.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:
refresherin interfaceis.codion.common.model.FilterModel<is.codion.framework.domain.entity.Entity>
-
refresh
public void refresh()- Specified by:
refreshin interfaceis.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:
refreshThenin interfaceis.codion.common.model.FilterModel<is.codion.framework.domain.entity.Entity>
-
setSelectedItem
- Specified by:
setSelectedItemin interfaceComboBoxModel<is.codion.framework.domain.entity.Entity>
-
getSize
public int getSize() -
getElementAt
public is.codion.framework.domain.entity.Entity getElementAt(int index) - Specified by:
getElementAtin interfaceListModel<is.codion.framework.domain.entity.Entity>
-
addListDataListener
- Specified by:
addListDataListenerin interfaceListModel<is.codion.framework.domain.entity.Entity>
-
removeListDataListener
- Specified by:
removeListDataListenerin interfaceListModel<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 representconnectionProvider- a EntityConnectionProvider instance- Returns:
- a new
EntityComboBoxModelinstance
-