Interface EntityTableModel<E extends EntityEditModel>

Type Parameters:
E - the type of EntityEditModel used by this EntityTableModel
All Superinterfaces:
is.codion.common.model.FilteredModel<is.codion.framework.domain.entity.Entity>

public interface EntityTableModel<E extends EntityEditModel> extends is.codion.common.model.FilteredModel<is.codion.framework.domain.entity.Entity>
Specifies a table model containing Entity instances.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Represents preferences for an Attribute based table column.
    static enum 
    Defines the actions a table model can perform when entities are inserted via the associated edit model

    Nested classes/interfaces inherited from interface is.codion.common.model.FilteredModel

    is.codion.common.model.FilteredModel.AbstractRefresher<T extends Object>, is.codion.common.model.FilteredModel.Refresher<T extends Object>
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final is.codion.common.property.PropertyValue<EntityTableModel.OnInsert>
    Specifies the default action a table model takes when entities are inserted via its edit model.
    static final is.codion.common.property.PropertyValue<Boolean>
    Specifies whether the table model sort order is used as a basis for the query order by clause.
    static final is.codion.common.property.PropertyValue<Boolean>
    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

    Modifier and Type
    Method
    Description
    void
     
    is.codion.common.value.ValueSet<is.codion.framework.domain.entity.attribute.Attribute<?>>
    Returns the ValueSet controlling which attributes are included when selecting entities to populate this model.
    backgroundColor(int row, is.codion.framework.domain.entity.attribute.Attribute<?> attribute)
     
    void
    Clears all items from this table model
    is.codion.common.state.StateObserver
     
    EntityTableConditionModel<is.codion.framework.domain.entity.attribute.Attribute<?>>
     
    is.codion.common.state.State
    Returns a State controlling whether this table model should display all underlying entities when no query condition has been set.
    is.codion.framework.db.EntityConnectionProvider
     
    void
    Deletes the selected entities
    is.codion.common.state.State
     
    is.codion.common.state.State
     
    <C extends E>
    C
     
    is.codion.framework.domain.entity.Entities
     
    is.codion.framework.domain.entity.EntityDefinition
     
    is.codion.framework.domain.entity.EntityType
     
    Optional<is.codion.framework.domain.entity.Entity>
    find(is.codion.framework.domain.entity.Entity.Key primaryKey)
    Finds the entity in this table model having the given primary key
    Collection<is.codion.framework.domain.entity.Entity>
    find(Collection<is.codion.framework.domain.entity.Entity.Key> keys)
    Finds entities in this table model according to the values in keys
    foregroundColor(int row, is.codion.framework.domain.entity.attribute.Attribute<?> attribute)
     
    int
     
    int
    indexOf(is.codion.framework.domain.entity.Entity.Key primaryKey)
     
    is.codion.common.value.Value<Integer>
    Returns the Value controlling the maximum number of rows to fetch via the underlying query the next time this table model is refreshed, a value of -1 means all rows should be fetched
    is.codion.common.value.Value<EntityTableModel.OnInsert>
     
    is.codion.common.state.State
    Specifies whether the current sort order is used as a basis for the query order by clause.
    is.codion.common.state.State
    Returns whether the values of hidden columns are included when querying data
    void
    Refreshes the items in this table model, according to the underlying condition
    void
    refresh(Collection<is.codion.framework.domain.entity.Entity.Key> keys)
    Refreshes the entities with the given keys by re-selecting them from the underlying database.
    is.codion.common.state.State
     
    void
    replace(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey, Collection<is.codion.framework.domain.entity.Entity> foreignKeyValues)
    For every entity in this table model, replaces the foreign key instance bearing the primary key with the corresponding entity from foreignKeyValues, useful when attribute values have been changed in the referenced entity that must be reflected in the table model.
    void
    replace(Collection<is.codion.framework.domain.entity.Entity> entities)
    Replaces the given entities in this table model
    void
    Saves any user preferences.
    void
    select(Collection<is.codion.framework.domain.entity.Entity.Key> keys)
    Selects entities according to the primary keys in primaryKeys
    is.codion.common.model.table.TableSelectionModel<is.codion.framework.domain.entity.Entity>
     
    void
    setVisibleColumns(is.codion.framework.domain.entity.attribute.Attribute<?>... attributes)
    Arranges the column model so that only the given columns are visible and in the given order
    void
    setVisibleColumns(List<is.codion.framework.domain.entity.attribute.Attribute<?>> attributes)
    Arranges the column model so that only the given columns are visible and in the given order

    Methods inherited from interface is.codion.common.model.FilteredModel

    containsItem, filtered, filteredCount, filteredItems, filterItems, includeCondition, items, refresher, refreshThen, visible, visibleCount, visibleItems
  • Field Details

    • QUERY_HIDDEN_COLUMNS

      static final is.codion.common.property.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 is.codion.common.property.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 attributes. Value type: Boolean
      Default value: false
    • ON_INSERT

      static final is.codion.common.property.PropertyValue<EntityTableModel.OnInsert> ON_INSERT
      Specifies the default action a table model takes when entities are inserted via its edit model. Value type: EntityTableModel.OnInsert
      Default value: EntityTableModel.OnInsert.ADD_TOP
  • Method Details

    • entityType

      is.codion.framework.domain.entity.EntityType entityType()
      Returns:
      the type of the entity this table model is based on
    • connectionProvider

      is.codion.framework.db.EntityConnectionProvider connectionProvider()
      Returns:
      the connection provider used by this table model
    • entities

      is.codion.framework.domain.entity.Entities entities()
      Returns:
      the underlying domain entities
    • entityDefinition

      is.codion.framework.domain.entity.EntityDefinition entityDefinition()
      Returns:
      the definition of the underlying entity
    • editModel

      <C extends E> C editModel()
      Type Parameters:
      C - the edit model type Returns the EntityEditModel associated with this table model
      Returns:
      the edit model associated with this table model
    • replace

      void replace(is.codion.framework.domain.entity.attribute.ForeignKey foreignKey, Collection<is.codion.framework.domain.entity.Entity> foreignKeyValues)
      For every entity in this table model, replaces the foreign key instance bearing the primary key with the corresponding entity from foreignKeyValues, useful when attribute values have been changed in the referenced entity that must be reflected in the table model.
      Parameters:
      foreignKey - the foreign key
      foreignKeyValues - the foreign key entities
    • replace

      void replace(Collection<is.codion.framework.domain.entity.Entity> entities)
      Replaces the given entities in this table model
      Parameters:
      entities - the entities to replace
    • refresh

      void refresh(Collection<is.codion.framework.domain.entity.Entity.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
    • conditionModel

      EntityTableConditionModel<is.codion.framework.domain.entity.attribute.Attribute<?>> conditionModel()
      Returns:
      the EntityTableConditionModel instance used by this table model
    • editable

      is.codion.common.state.State editable()
      Returns:
      the State controlling whether this table model is editable
    • backgroundColor

      Object backgroundColor(int row, is.codion.framework.domain.entity.attribute.Attribute<?> attribute)
      Parameters:
      row - the row for which to retrieve the background color
      attribute - 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, is.codion.framework.domain.entity.attribute.Attribute<?> attribute)
      Parameters:
      row - the row for which to retrieve the foreground color
      attribute - 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)
    • attributes

      is.codion.common.value.ValueSet<is.codion.framework.domain.entity.attribute.Attribute<?>> attributes()
      Returns the ValueSet controlling which attributes are included when selecting entities to populate this model. Note that an empty ValueSet indicates that the default select attributes should be used.
      Returns:
      the ValueSet controlling the selected attributes
      See Also:
    • limit

      is.codion.common.value.Value<Integer> limit()
      Returns the Value controlling the maximum number of rows to fetch via the underlying query the next time this table model is refreshed, a value of -1 means all rows should be fetched
      Returns:
      the value controlling the limit
    • queryHiddenColumns

      is.codion.common.state.State queryHiddenColumns()
      Returns whether the values of hidden columns are included when querying data
      Returns:
      the State controlling whether the values of hidden columns are included when querying data
    • orderQueryBySortOrder

      is.codion.common.state.State 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 attributes.
      Returns:
      the State controlling whether the current sort order should be used as a basis for the query order by clause
    • deleteSelected

      void deleteSelected() throws is.codion.common.db.exception.DatabaseException
      Deletes the selected entities
      Throws:
      is.codion.common.db.exception.DatabaseException - in case of a database exception
      is.codion.common.model.CancelException - in case the user cancels the operation
      IllegalStateException - in case this table model has no edit model or if the edit model does not allow deleting
    • conditionRequired

      is.codion.common.state.State conditionRequired()
      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 rows 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
    • editEvents

      is.codion.common.state.State editEvents()
      Returns:
      the state controlling whether this table model handles entity edit events, by replacing foreign key values
      See Also:
    • onInsert

      is.codion.common.value.Value<EntityTableModel.OnInsert> onInsert()
      Returns:
      the Value controlling the action to perform when entities are inserted via the associated edit model
      See Also:
    • removeDeleted

      is.codion.common.state.State removeDeleted()
      Returns:
      the State controlling whether entities that are deleted via the associated edit model should be automatically removed from this table model
    • find

      Collection<is.codion.framework.domain.entity.Entity> find(Collection<is.codion.framework.domain.entity.Entity.Key> keys)
      Finds entities in this table model according to the values in keys
      Parameters:
      keys - the primary key values to use as condition
      Returns:
      the entities from this table model having the primary key values as in keys
    • select

      void select(Collection<is.codion.framework.domain.entity.Entity.Key> keys)
      Selects entities according to the primary keys in primaryKeys
      Parameters:
      keys - the primary keys of the entities to select
    • find

      Optional<is.codion.framework.domain.entity.Entity> find(is.codion.framework.domain.entity.Entity.Key primaryKey)
      Finds the entity in this table model having the given primary key
      Parameters:
      primaryKey - the primary key to search by
      Returns:
      the entity with the given primary key from the table model, an empty Optional if not found
    • indexOf

      int indexOf(is.codion.framework.domain.entity.Entity.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 if EntityModel.USE_CLIENT_PREFERENCES is set to 'false', calling this method has no effect.
    • setVisibleColumns

      void setVisibleColumns(is.codion.framework.domain.entity.attribute.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<is.codion.framework.domain.entity.attribute.Attribute<?>> attributes)
      Arranges the column model so that only the given columns are visible and in the given order
      Parameters:
      attributes - the column attributes
    • refresh

      void refresh()
      Refreshes the items in this table model, according to the underlying condition
      Specified by:
      refresh in interface is.codion.common.model.FilteredModel<E extends EntityEditModel>
      See Also:
    • clear

      void clear()
      Clears all items from this table model
    • getRowCount

      int getRowCount()
      Returns:
      the number of visible rows in this table model
    • selectionModel

      is.codion.common.model.table.TableSelectionModel<is.codion.framework.domain.entity.Entity> selectionModel()
      Returns:
      the TableSelectionModel
    • conditionChanged

      is.codion.common.state.StateObserver conditionChanged()
      Returns:
      a StateObserver indicating if the search condition has changed since last refresh
    • addSelectionListener

      void addSelectionListener(Runnable listener)
      Parameters:
      listener - notified when the selection changes in the underlying selection model