Module is.codion.framework.model
Package is.codion.framework.model
Interface EntityTableModel<E extends EntityEditModel>
-
- Type Parameters:
E
- the type ofEntityEditModel
used by thisEntityTableModel
- All Superinterfaces:
FilteredModel<Entity>
- All Known Implementing Classes:
FXEntityListModel
,SwingEntityTableModel
public interface EntityTableModel<E extends EntityEditModel> extends FilteredModel<Entity>
Specifies a table model containingEntity
instances.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
EntityTableModel.ColumnPreferences
Represents preferences for an Attribute based table column.static class
EntityTableModel.InsertAction
Defines the actions a table model can perform when entities are inserted via the associated edit model
-
Field Summary
Fields Modifier and Type Field Description static PropertyValue<Boolean>
ORDER_QUERY_BY_SORT_ORDER
Specifies whether the table model sort order is used as a basis for the query order by clause.static PropertyValue<Boolean>
QUERY_HIDDEN_COLUMNS
Specifies whether the values of hidden columns are included in the underlying query
Value type: Boolean
Default value: true-
Fields inherited from interface is.codion.common.model.FilteredModel
ASYNC_REFRESH
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addEntities(Collection<Entity> entities)
Adds the given entities to the bottom of this table model.void
addEntitiesAt(int index, Collection<Entity> entities)
Adds the given entities to the top of this table model.void
addEntitiesAtSorted(int index, Collection<Entity> entities)
Adds the given entities to the top of this table model and then, if sorting is enabled, sorts this table model.void
addEntitiesSorted(Collection<Entity> entities)
Adds the given entities to the bottom of this table model and then, if sorting is enabled, sorts this table model.void
addSelectionListener(EventListener listener)
Object
backgroundColor(int row, Attribute<?> attribute)
void
clear()
Clears all items from this table modelstatic EntityTableModel.ColumnPreferences
columnPreferences(Attribute<?> attribute, int index, int width)
Creates a newEntityTableModel.ColumnPreferences
instance.StateObserver
conditionChangedObserver()
EntityConnectionProvider
connectionProvider()
void
deleteSelected()
Deletes the selected entitiesE
editModel()
Returns theEntityEditModel
associated with this table modelEntities
entities()
Collection<Entity>
entitiesByKey(Collection<Key> keys)
Finds entities according to the values inkeys
Entity
entityByKey(Key primaryKey)
EntityDefinition
entityDefinition()
EntityType
entityType()
Object
foregroundColor(int row, Attribute<?> attribute)
EntityTableModel.InsertAction
getInsertAction()
int
getLimit()
Returns the maximum number of records to fetch via the underlying query the next time this table model is refreshed, a value of -1 means all records should be fetchedint
getRowCount()
int
indexOf(Key primaryKey)
boolean
isBatchUpdateEnabled()
boolean
isDeleteEnabled()
boolean
isEditable()
boolean
isOrderQueryBySortOrder()
Specifies whether the current sort order is used as a basis for the query order by clause.boolean
isQueryHiddenColumns()
Returns whether the values of hidden columns are included when querying databoolean
isReadOnly()
boolean
isRemoveDeletedEntities()
boolean
isUpdateEnabled()
State
queryConditionRequiredState()
Returns a State controlling whether this table model should display all underlying entities when no query condition has been set.void
refresh()
Refreshes the items in this table model, according to the underlying conditionvoid
refreshEntities(List<Key> keys)
Refreshes the entities with the given keys by re-selecting them from the underlying database.void
replaceEntities(Collection<Entity> entities)
Replaces the given entities in this table modelvoid
replaceForeignKeyValues(ForeignKey foreignKey, Collection<Entity> foreignKeyValues)
For every entity in this table model, replaces the foreign key instance bearing the primary key with the corresponding entity fromforeignKeyValues
, useful when property values have been changed in the referenced entity that must be reflected in the table model.void
savePreferences()
Saves any user preferences.void
selectByKey(Collection<Key> keys)
Sets the selected entities according to the primary keys inprimaryKeys
SelectionModel<Entity>
selectionModel()
void
setBatchUpdateEnabled(boolean batchUpdateEnabled)
void
setEditable(boolean editable)
boolean
setForeignKeyConditionValues(ForeignKey foreignKey, Collection<Entity> foreignKeyValues)
SetsforeignKeyValues
as the search condition values for the given foreign key and refreshes this table model.void
setInsertAction(EntityTableModel.InsertAction insertAction)
void
setLimit(int limit)
Sets the maximum number of records to fetch via the underlying query the next time this table model is refreshed, a value of -1 means all records should be fetchedvoid
setOrderQueryBySortOrder(boolean orderQueryBySortOrder)
Specifies whether the current sort order is used as a basis for the query order by clause.void
setQueryHiddenColumns(boolean queryHiddenColumns)
void
setRemoveDeletedEntities(boolean removeDeletedEntities)
void
setVisibleColumns(Attribute<?>... attributes)
Arranges the column model so that only the given columns are visible and in the given ordervoid
setVisibleColumns(List<Attribute<?>> attributes)
Arranges the column model so that only the given columns are visible and in the given orderEntityTableConditionModel
tableConditionModel()
String
tableDataAsDelimitedString(char delimiter)
void
update(List<Entity> entities)
Updates the given entities.-
Methods inherited from interface is.codion.common.model.FilteredModel
addFilterListener, addRefreshFailedListener, addRefreshListener, containsItem, filteredItemCount, filteredItems, filterItems, getIncludeCondition, isAsyncRefresh, isFiltered, isVisible, items, refreshingObserver, refreshThen, removeFilterListener, removeRefreshFailedListener, removeRefreshListener, setAsyncRefresh, setIncludeCondition, visibleItemCount, visibleItems
-
-
-
-
Field Detail
-
QUERY_HIDDEN_COLUMNS
static final PropertyValue<Boolean> QUERY_HIDDEN_COLUMNS
Specifies whether the values of hidden columns are included in the underlying query
Value type: Boolean
Default value: true
-
ORDER_QUERY_BY_SORT_ORDER
static final PropertyValue<Boolean> ORDER_QUERY_BY_SORT_ORDER
Specifies whether the table model sort order is used as a basis for the query order by clause. Note that this only applies to column properties. Value type: Boolean
Default value: false
-
-
Method Detail
-
entityType
EntityType entityType()
- Returns:
- the type of the entity this table model is based on
-
connectionProvider
EntityConnectionProvider connectionProvider()
- Returns:
- the connection provider used by this table model
-
entities
Entities entities()
- Returns:
- the underlying domain entities
-
entityDefinition
EntityDefinition entityDefinition()
- Returns:
- the definition of the underlying entity
-
editModel
E editModel()
Returns theEntityEditModel
associated with this table model- Returns:
- the edit model associated with this table model
-
setForeignKeyConditionValues
boolean setForeignKeyConditionValues(ForeignKey foreignKey, Collection<Entity> foreignKeyValues)
SetsforeignKeyValues
as the search condition values for the given foreign key and refreshes this table model.- Parameters:
foreignKey
- the foreign keyforeignKeyValues
- the entities to use as condition values- Returns:
- true if the table search condition changed due to this call and a refresh is in order, false otherwise
-
replaceForeignKeyValues
void replaceForeignKeyValues(ForeignKey foreignKey, Collection<Entity> foreignKeyValues)
For every entity in this table model, replaces the foreign key instance bearing the primary key with the corresponding entity fromforeignKeyValues
, useful when property values have been changed in the referenced entity that must be reflected in the table model.- Parameters:
foreignKey
- the foreign keyforeignKeyValues
- the foreign key entities
-
addEntities
void addEntities(Collection<Entity> entities)
Adds the given entities to the bottom of this table model. It is recommended to only manually add entities directly to this table model after they have been inserted into the underlying table since otherwise they will disappear during the next table model refresh.- Parameters:
entities
- the entities to add
-
addEntitiesSorted
void addEntitiesSorted(Collection<Entity> entities)
Adds the given entities to the bottom of this table model and then, if sorting is enabled, sorts this table model. It is recommended to only manually add entities directly to this table model after they have been inserted into the underlying table since otherwise they will disappear during the next table model refresh.- Parameters:
entities
- the entities to add
-
addEntitiesAt
void addEntitiesAt(int index, Collection<Entity> entities)
Adds the given entities to the top of this table model. It is recommended to only manually add entities directly to this table model after they have been inserted into the underlying table since otherwise they will disappear during the next table model refresh.- Parameters:
index
- the index at which to addentities
- the entities to add
-
addEntitiesAtSorted
void addEntitiesAtSorted(int index, Collection<Entity> entities)
Adds the given entities to the top of this table model and then, if sorting is enabled, sorts this table model. It is recommended to only manually add entities directly to this table model after they have been inserted into the underlying table since otherwise they will disappear during the next table model refresh.- Parameters:
index
- the index at which to addentities
- the entities to add
-
replaceEntities
void replaceEntities(Collection<Entity> entities)
Replaces the given entities in this table model- Parameters:
entities
- the entities to replace
-
refreshEntities
void refreshEntities(List<Key> keys)
Refreshes the entities with the given keys by re-selecting them from the underlying database.- Parameters:
keys
- the keys of the entities to refresh
-
tableConditionModel
EntityTableConditionModel tableConditionModel()
- Returns:
- the
EntityTableConditionModel
instance used by this table model
-
isEditable
boolean isEditable()
- Returns:
- true if this table model is editable
-
setEditable
void setEditable(boolean editable)
- Parameters:
editable
- true if this table model should be editable
-
isDeleteEnabled
boolean isDeleteEnabled()
- Returns:
- true if the underlying edit model allows deletion of records
-
isReadOnly
boolean isReadOnly()
- Returns:
- true if the underlying edit model is read only
-
isUpdateEnabled
boolean isUpdateEnabled()
- Returns:
- true if the underlying edit model allows updating of records
-
isBatchUpdateEnabled
boolean isBatchUpdateEnabled()
- Returns:
- true if multiple entities can be updated at a time
-
setBatchUpdateEnabled
void setBatchUpdateEnabled(boolean batchUpdateEnabled)
- Parameters:
batchUpdateEnabled
- true if this model should enable multiple entities to be updated at a time
-
backgroundColor
Object backgroundColor(int row, Attribute<?> attribute)
- Parameters:
row
- the row for which to retrieve the background colorattribute
- the attribute for which to retrieve the background color- Returns:
- an Object representing the background color for this row and attribute, specified by the row entity
- See Also:
EntityDefinition.Builder.backgroundColorProvider(ColorProvider)
-
foregroundColor
Object foregroundColor(int row, Attribute<?> attribute)
- Parameters:
row
- the row for which to retrieve the foreground colorattribute
- the attribute for which to retrieve the foreground color- Returns:
- an Object representing the foreground color for this row and attribute, specified by the row entity
- See Also:
EntityDefinition.Builder.foregroundColorProvider(ColorProvider)
-
getLimit
int getLimit()
Returns the maximum number of records to fetch via the underlying query the next time this table model is refreshed, a value of -1 means all records should be fetched- Returns:
- the fetch count
-
setLimit
void setLimit(int limit)
Sets the maximum number of records to fetch via the underlying query the next time this table model is refreshed, a value of -1 means all records should be fetched- Parameters:
limit
- the fetch count
-
isQueryHiddenColumns
boolean isQueryHiddenColumns()
Returns whether the values of hidden columns are included when querying data- Returns:
- true if the values of hidden columns are included when querying data
-
setQueryHiddenColumns
void setQueryHiddenColumns(boolean queryHiddenColumns)
- Parameters:
queryHiddenColumns
- true if the values of hidden columns should be included when querying data- See Also:
QUERY_HIDDEN_COLUMNS
-
isOrderQueryBySortOrder
boolean isOrderQueryBySortOrder()
Specifies whether the current sort order is used as a basis for the query order by clause. Note that this only applies to column properties.- Returns:
- true if the current sort order should be used as a basis for the query order by clause
-
setOrderQueryBySortOrder
void setOrderQueryBySortOrder(boolean orderQueryBySortOrder)
Specifies whether the current sort order is used as a basis for the query order by clause. Note that this only applies to column properties.- Parameters:
orderQueryBySortOrder
- true if the current sort order should be used as a basis for the query order by clause
-
update
void update(List<Entity> entities) throws ValidationException, DatabaseException
Updates the given entities. If the entities are unmodified or the list is empty this method returns silently.- Parameters:
entities
- the entities to update- Throws:
DatabaseException
- in case of a database exceptionCancelException
- in case the user cancels the operationRecordModifiedException
- in case an entity was modified by another userValidationException
- in case validation failsIllegalStateException
- in case this table model has no edit model or if the edit model does not allow updating- See Also:
EntityValidator.validate(Entity)
-
deleteSelected
void deleteSelected() throws DatabaseException
Deletes the selected entities- Throws:
DatabaseException
- in case of a database exceptionCancelException
- in case the user cancels the operationIllegalStateException
- in case this table model has no edit model or if the edit model does not allow deleting
-
queryConditionRequiredState
State queryConditionRequiredState()
Returns a State controlling whether this table model should display all underlying entities when no query condition has been set. Setting this value to 'true' prevents all records from being fetched by accident, when no condition has been set, which is recommended for tables with a large underlying dataset.- Returns:
- a State specifying whether this table model requires a query condition
-
isRemoveDeletedEntities
boolean isRemoveDeletedEntities()
- Returns:
- true if entities that are deleted via the associated edit model should be automatically removed from this table model
-
setRemoveDeletedEntities
void setRemoveDeletedEntities(boolean removeDeletedEntities)
- Parameters:
removeDeletedEntities
- true if entities that are deleted via the associated edit model should be automatically removed from this table model
-
getInsertAction
EntityTableModel.InsertAction getInsertAction()
- Returns:
- the action performed when entities are inserted via the associated edit model
-
setInsertAction
void setInsertAction(EntityTableModel.InsertAction insertAction)
- Parameters:
insertAction
- the action to perform when entities are inserted via the associated edit model
-
entitiesByKey
Collection<Entity> entitiesByKey(Collection<Key> keys)
Finds entities according to the values inkeys
- Parameters:
keys
- the primary key values to use as condition- Returns:
- the entities having the primary key values as in
keys
-
selectByKey
void selectByKey(Collection<Key> keys)
Sets the selected entities according to the primary keys inprimaryKeys
- Parameters:
keys
- the primary keys of the entities to select
-
entityByKey
Entity entityByKey(Key primaryKey)
- Parameters:
primaryKey
- the primary key to search by- Returns:
- the entity with the given primary key from the table model, null if it's not found
-
indexOf
int indexOf(Key primaryKey)
- Parameters:
primaryKey
- the primary key- Returns:
- the row index of the entity with the given primary key, -1 if not found
-
savePreferences
void savePreferences()
Saves any user preferences. Note that ifEntityModel.USE_CLIENT_PREFERENCES
is set to 'false', calling this method has no effect.
-
setVisibleColumns
void setVisibleColumns(Attribute<?>... attributes)
Arranges the column model so that only the given columns are visible and in the given order- Parameters:
attributes
- the column attributes
-
setVisibleColumns
void setVisibleColumns(List<Attribute<?>> attributes)
Arranges the column model so that only the given columns are visible and in the given order- Parameters:
attributes
- the column attributes
-
tableDataAsDelimitedString
String tableDataAsDelimitedString(char delimiter)
- Parameters:
delimiter
- the delimiter- Returns:
- the table data as a tab delimited string, with column names as a header
-
refresh
void refresh()
Refreshes the items in this table model, according to the underlying condition- Specified by:
refresh
in interfaceFilteredModel<E extends EntityEditModel>
- See Also:
tableConditionModel()
-
clear
void clear()
Clears all items from this table model
-
getRowCount
int getRowCount()
- Returns:
- the number of visible rows in this table model
-
selectionModel
SelectionModel<Entity> selectionModel()
- Returns:
- the
SelectionModel
-
conditionChangedObserver
StateObserver conditionChangedObserver()
- Returns:
- a StateObserver indicating if the search condition has changed since last refresh
-
addSelectionListener
void addSelectionListener(EventListener listener)
- Parameters:
listener
- notified when the selection changes in the underlying selection model
-
columnPreferences
static EntityTableModel.ColumnPreferences columnPreferences(Attribute<?> attribute, int index, int width)
Creates a newEntityTableModel.ColumnPreferences
instance.- Parameters:
attribute
- the attributeindex
- the column index, -1 if not visiblewidth
- the column width- Returns:
- a new
EntityTableModel.ColumnPreferences
instance.
-
-