public class EntityComboBoxModel extends FilteredComboBoxModel<Entity>
FilteredComboBoxModel.ItemFinder<T,V>
COMBO_BOX_NULL_CAPTION
ASYNC_REFRESH
Constructor and Description |
---|
EntityComboBoxModel(EntityType entityType,
EntityConnectionProvider connectionProvider) |
Modifier and Type | Method and Description |
---|---|
EntityConnectionProvider |
connectionProvider() |
EntityComboBoxModel |
createForeignKeyConditionComboBoxModel(ForeignKey foreignKey)
Returns a combo box model for selecting a foreign key value for using as a condition this model.
|
EntityComboBoxModel |
createForeignKeyFilterComboBoxModel(ForeignKey foreignKey)
Returns a combo box model for selecting a foreign key value for filtering this model.
|
<T> Value<T> |
createSelectorValue(Attribute<T> attribute)
Creates a
Value linked to the selected entity via the value of the given attribute. |
Optional<Entity> |
entity(Key primaryKey) |
EntityType |
entityType() |
void |
forceRefresh()
Forces a refresh of this model, disregarding the staticData directive
|
Predicate<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.setIncludeCondition(Predicate) . |
Collection<Key> |
getForeignKeyFilterKeys(ForeignKey foreignKey) |
OrderBy |
getOrderBy() |
Collection<Attribute<?>> |
getSelectAttributes() |
Supplier<Condition> |
getSelectConditionSupplier() |
boolean |
isListenToEditEvents()
True if this combo box model responds to entity edit events, by adding inserted items,
updating any updated items and removing deleted ones.
|
boolean |
isStaticData() |
boolean |
isStrictForeignKeyFiltering() |
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
|
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
|
protected Collection<Entity> |
performQuery()
Retrieves the entities to present in this EntityComboBoxModel, taking into account
the select condition supplier (
getSelectConditionSupplier() ) as well as the
select attributes (getSelectAttributes() ) and order by clause (getOrderBy() . |
protected Collection<Entity> |
refreshItems() |
void |
selectByKey(Key primaryKey)
Selects the entity with the given primary key, if the entity is not available
in the model this method returns silently without changing the selection
|
void |
setForeignKeyFilterKeys(ForeignKey foreignKey,
Collection<Key> keys)
Filters this combo box model so that only items referencing the given keys via the given foreign key are shown.
|
void |
setListenToEditEvents(boolean listenToEditEvents)
Set to true if this combo box model should respond to entity edit events, by adding inserted items,
updating any updated items and removing deleted ones.
|
void |
setNullCaption(String caption)
Enables the null item and sets the null item caption.
|
void |
setOrderBy(OrderBy orderBy)
Sets the order by to use when selecting entities for this model.
|
void |
setSelectAttributes(Collection<Attribute<?>> selectAttributes)
Specifies the attributes to include when selecting the entities to populate this model with.
|
void |
setSelectConditionSupplier(Supplier<Condition> selectConditionSupplier)
Sets the condition provider to use when querying data, set to null to fetch all underlying entities.
|
void |
setStaticData(boolean staticData)
Specifies whether this models data should be considered static, that is, only fetched once.
|
void |
setStrictForeignKeyFiltering(boolean strictForeignKeyFiltering)
Specifies whether foreign key filtering should be strict or not.
|
String |
toString() |
protected Entity |
translateSelectionItem(Object item) |
addFilterListener, addItem, addListDataListener, addRefreshFailedListener, addRefreshListener, addSelectionListener, allowSelectionChange, clear, containsItem, createSelectorValue, filteredItemCount, filteredItems, filterItems, fireContentsChanged, getElementAt, getIncludeCondition, getSelectedItem, getSize, getSortComparator, isAsyncRefresh, isCleared, isFiltered, isFilterSelectedItem, isIncludeNull, isNullSelected, isSelectionEmpty, isVisible, items, refresh, refreshingObserver, refreshThen, removeFilterListener, removeItem, removeListDataListener, removeRefreshFailedListener, removeRefreshListener, removeSelectionListener, replaceItem, selectedValue, setAsyncRefresh, setFilterSelectedItem, setIncludeCondition, setIncludeNull, setItems, setNullItem, setSelectedItem, setSortComparator, visibleItemCount, visibleItems
public EntityComboBoxModel(EntityType entityType, EntityConnectionProvider connectionProvider)
entityType
- the type of the entity this combo box model should representconnectionProvider
- a EntityConnectionProvider instancepublic final EntityConnectionProvider connectionProvider()
public final EntityType entityType()
public final void forceRefresh()
setStaticData(boolean)
public final boolean isStaticData()
forceRefresh()
public final void setStaticData(boolean staticData)
forceRefresh()
disregards this directive.staticData
- the valuepublic final void setNullCaption(String caption)
caption
- the null item captionFilteredComboBoxModel.setIncludeNull(boolean)
,
FilteredComboBoxModel.setNullItem(Object)
public final void setSelectAttributes(Collection<Attribute<?>> selectAttributes)
selectAttributes
- the attributes to select, an empty Collection for all available attributesIllegalArgumentException
- in case any of the given attributes is not part of the underlying entity typepublic final Collection<Attribute<?>> getSelectAttributes()
public final boolean isListenToEditEvents()
EntityEditEvents
public final void setListenToEditEvents(boolean listenToEditEvents)
listenToEditEvents
- if true then this model listens to entity edit eventsEntityEditEvents
public final Optional<Entity> entity(Key primaryKey)
primaryKey
- the primary key of the entity to fetch from this modelpublic final void selectByKey(Key primaryKey)
primaryKey
- the primary key of the entity to selectpublic final void setSelectConditionSupplier(Supplier<Condition> selectConditionSupplier)
selectConditionSupplier
- the condition supplierpublic final Supplier<Condition> getSelectConditionSupplier()
public final void setOrderBy(OrderBy orderBy)
FilteredComboBoxModel.setSortComparator(Comparator)
orderBy
- the order byFilteredComboBoxModel.setSortComparator(Comparator)
public final OrderBy getOrderBy()
public final Predicate<Entity> foreignKeyIncludeCondition()
Predicate
to this model via FilteredComboBoxModel.setIncludeCondition(Predicate)
.
Predicate fkCondition = model.foreignKeyIncludeCondition(); model.setIncludeCondition(item -> fkCondition.test(item) && ...);
Predicate
based on the foreign key filter entitiessetForeignKeyFilterKeys(ForeignKey, Collection)
public final void setForeignKeyFilterKeys(ForeignKey foreignKey, Collection<Key> keys)
foreignKey
- the foreign keykeys
- the keys, null or empty for nonepublic final Collection<Key> getForeignKeyFilterKeys(ForeignKey foreignKey)
foreignKey
- the foreign keypublic final void setStrictForeignKeyFiltering(boolean strictForeignKeyFiltering)
strictForeignKeyFiltering
- the valuesetForeignKeyFilterKeys(ForeignKey, Collection)
public final boolean isStrictForeignKeyFiltering()
public final EntityComboBoxModel createForeignKeyFilterComboBoxModel(ForeignKey foreignKey)
foreignKey
- the foreign keylinkForeignKeyFilterComboBoxModel(ForeignKey, EntityComboBoxModel)
public final EntityComboBoxModel createForeignKeyConditionComboBoxModel(ForeignKey foreignKey)
foreignKey
- the foreign keylinkForeignKeyConditionComboBoxModel(ForeignKey, EntityComboBoxModel)
public final void linkForeignKeyFilterComboBoxModel(ForeignKey foreignKey, EntityComboBoxModel foreignKeyModel)
foreignKey
- the foreign key attributeforeignKeyModel
- the combo box model to linkpublic final void linkForeignKeyConditionComboBoxModel(ForeignKey foreignKey, EntityComboBoxModel foreignKeyModel)
foreignKey
- the foreign key attributeforeignKeyModel
- the combo box model to linkpublic final <T> Value<T> createSelectorValue(Attribute<T> attribute)
Value
linked to the selected entity via the value of the given attribute.T
- the attribute typeattribute
- the attributeValue
for selecting items by attribute valueprotected final Entity translateSelectionItem(Object item)
translateSelectionItem
in class FilteredComboBoxModel<Entity>
item
- the item to be selectedprotected final Collection<Entity> refreshItems()
refreshItems
in class FilteredComboBoxModel<Entity>
protected Collection<Entity> performQuery()
getSelectConditionSupplier()
) as well as the
select attributes (getSelectAttributes()
) and order by clause (getOrderBy()
.getSelectConditionSupplier()
,
getSelectAttributes()
,
getOrderBy()