public class SwingEntityTableModel extends DefaultFilteredTableModel<Entity,Attribute<?>> implements EntityTableModel<SwingEntityEditModel>
DefaultFilteredTableModel.DefaultSummaryValueProvider<T extends Number,C>
EntityTableModel.ColumnPreferences, EntityTableModel.InsertAction
FilteredTableModel.ColumnValueProvider<R,C>, FilteredTableModel.RowsRemoved
listenerList
ORDER_QUERY_BY_SORT_ORDER, QUERY_HIDDEN_COLUMNS
ASYNC_REFRESH
Constructor and Description |
---|
SwingEntityTableModel(EntityType entityType,
EntityConnectionProvider connectionProvider)
Instantiates a new SwingEntityTableModel.
|
SwingEntityTableModel(EntityType entityType,
EntityConnectionProvider connectionProvider,
EntityTableConditionModel tableConditionModel)
Instantiates a new SwingEntityTableModel.
|
SwingEntityTableModel(SwingEntityEditModel editModel)
Instantiates a new SwingEntityTableModel.
|
SwingEntityTableModel(SwingEntityEditModel editModel,
EntityTableConditionModel tableConditionModel)
Instantiates a new SwingEntityTableModel.
|
Modifier and Type | Method and 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) |
Color |
backgroundColor(int row,
Attribute<?> attribute) |
StateObserver |
conditionChangedObserver() |
EntityConnectionProvider |
connectionProvider() |
static List<FilteredTableColumn<Attribute<?>>> |
createColumns(EntityDefinition definition)
Initializes default
TableColumn s for all visible properties in the given entity type. |
static List<FilteredTableColumn<Attribute<?>>> |
createColumns(List<Property<?>> properties)
Initializes default
TableColumn s from the given properties. |
protected <T extends Number> |
createColumnValueProvider(Attribute<?> attribute)
Creates a ColumnValueProvider for the given column
|
void |
deleteSelected()
Deletes the selected entities
|
SwingEntityEditModel |
editModel()
Returns the
EntityEditModel associated with this table model |
Entities |
entities() |
Collection<Entity> |
entitiesByKey(Collection<Key> keys)
Finds entities according to the values in
keys |
Entity |
entityByKey(Key primaryKey) |
EntityDefinition |
entityDefinition() |
EntityType |
entityType() |
Color |
foregroundColor(int row,
Attribute<?> attribute) |
protected Color |
getColor(Object color)
Returns a
Color instance from the given Object. |
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 fetched
|
int |
indexOf(Key primaryKey) |
boolean |
isBatchUpdateEnabled() |
boolean |
isCellEditable(int rowIndex,
int modelColumnIndex)
Returns true if the cell at
rowIndex and modelColumnIndex is editable. |
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 data
|
boolean |
isReadOnly() |
boolean |
isRemoveDeletedEntities() |
boolean |
isUpdateEnabled() |
protected OrderBy |
orderBy()
The order by clause to use when selecting the data for this model.
|
State |
queryConditionRequiredState()
Returns a State controlling whether this table model should display all underlying entities
when no query condition has been set.
|
void |
refreshEntities(List<Key> keys)
Refreshes the entities with the given keys by re-selecting them from the underlying database.
|
protected Collection<Entity> |
refreshItems()
Queries for the data used to populate this EntityTableModel when it is refreshed,
using the order by clause returned by
orderBy() |
void |
replaceEntities(Collection<Entity> entities)
Replaces the given entities in this table model
|
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 from
foreignKeyValues , 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.
|
protected Collection<Attribute<?>> |
selectAttributes()
Specifies the attributes to select when querying data.
|
void |
selectByKey(Collection<Key> keys)
Sets the selected entities according to the primary keys in
primaryKeys |
void |
setBatchUpdateEnabled(boolean batchUpdateEnabled) |
void |
setEditable(boolean editable) |
boolean |
setForeignKeyConditionValues(ForeignKey foreignKey,
Collection<Entity> foreignKeyValues)
Sets
foreignKeyValues 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 fetched
|
void |
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 |
setValueAt(Object value,
int rowIndex,
int modelColumnIndex)
Sets the value in the given cell and updates the underlying Entity.
|
void |
setVisibleColumns(Attribute<?>... attributes)
Arranges the column model so that only the given columns are visible and in the given order
|
void |
setVisibleColumns(List<Attribute<?>> attributes)
Arranges the column model so that only the given columns are visible and in the given order
|
ValueObserver<String> |
statusMessageObserver() |
EntityTableConditionModel |
tableConditionModel() |
String |
tableDataAsDelimitedString(char delimiter) |
String |
toString() |
void |
update(List<Entity> entities)
Updates the given entities.
|
protected String |
userPreferencesKey()
Returns the key used to identify user preferences for this table model, that is column positions, widths and such.
|
addClearListener, addDataChangedListener, addFilterListener, addItem, addItems, addItemsAt, addItemsAtSorted, addItemSorted, addItemsSorted, addRefreshFailedListener, addRefreshListener, addRowsRemovedListener, addSortListener, allowSelectionChange, clear, columnFilterModel, columnFilterModels, columnModel, columnSummaryModel, containsItem, filteredItemCount, filteredItems, filterItems, getColumnClass, getColumnClass, getColumnCount, getIncludeCondition, getRowCount, getStringValueAt, getValueAt, indexOf, isAsyncRefresh, isFiltered, isMergeOnRefresh, isVisible, itemAt, items, refresh, refreshingObserver, refreshThen, removeClearListener, removeDataChangedListener, removeFilterListener, removeItem, removeItemAt, removeItems, removeItems, removeRefreshFailedListener, removeRefreshListener, removeRowsRemovedListener, removeSortListener, searchModel, selectedValues, selectionModel, setAsyncRefresh, setIncludeCondition, setItemAt, setMergeOnRefresh, sortItems, sortModel, values, visibleItemCount, visibleItems
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getColumnName, getListeners, getTableModelListeners, removeTableModelListener
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
clear, columnPreferences, getRowCount, refresh, selectionModel
addFilterListener, addRefreshFailedListener, addRefreshListener, containsItem, filteredItemCount, filteredItems, filterItems, getIncludeCondition, isAsyncRefresh, isFiltered, isVisible, items, refreshingObserver, refreshThen, removeFilterListener, removeRefreshFailedListener, removeRefreshListener, setAsyncRefresh, setIncludeCondition, visibleItemCount, visibleItems
addTableModelListener, getColumnName, removeTableModelListener
public SwingEntityTableModel(EntityType entityType, EntityConnectionProvider connectionProvider)
entityType
- the entityTypeconnectionProvider
- the connection providerpublic SwingEntityTableModel(EntityType entityType, EntityConnectionProvider connectionProvider, EntityTableConditionModel tableConditionModel)
entityType
- the entityTypeconnectionProvider
- the connection providertableConditionModel
- the table condition modelpublic SwingEntityTableModel(SwingEntityEditModel editModel)
editModel
- the edit modelpublic SwingEntityTableModel(SwingEntityEditModel editModel, EntityTableConditionModel tableConditionModel)
editModel
- the edit modeltableConditionModel
- the table condition modelpublic final Entities entities()
entities
in interface EntityTableModel<SwingEntityEditModel>
public final EntityDefinition entityDefinition()
entityDefinition
in interface EntityTableModel<SwingEntityEditModel>
public final int getLimit()
EntityTableModel
getLimit
in interface EntityTableModel<SwingEntityEditModel>
public final void setLimit(int limit)
EntityTableModel
setLimit
in interface EntityTableModel<SwingEntityEditModel>
limit
- the fetch countpublic final boolean isQueryHiddenColumns()
EntityTableModel
isQueryHiddenColumns
in interface EntityTableModel<SwingEntityEditModel>
public final void setQueryHiddenColumns(boolean queryHiddenColumns)
setQueryHiddenColumns
in interface EntityTableModel<SwingEntityEditModel>
queryHiddenColumns
- true if the values of hidden columns should be included when querying dataEntityTableModel.QUERY_HIDDEN_COLUMNS
public final boolean isOrderQueryBySortOrder()
EntityTableModel
isOrderQueryBySortOrder
in interface EntityTableModel<SwingEntityEditModel>
public final void setOrderQueryBySortOrder(boolean orderQueryBySortOrder)
EntityTableModel
setOrderQueryBySortOrder
in interface EntityTableModel<SwingEntityEditModel>
orderQueryBySortOrder
- true if the current sort order should be used as a basis for the query order by clausepublic final State queryConditionRequiredState()
EntityTableModel
queryConditionRequiredState
in interface EntityTableModel<SwingEntityEditModel>
public final EntityTableModel.InsertAction getInsertAction()
getInsertAction
in interface EntityTableModel<SwingEntityEditModel>
public final void setInsertAction(EntityTableModel.InsertAction insertAction)
setInsertAction
in interface EntityTableModel<SwingEntityEditModel>
insertAction
- the action to perform when entities are inserted via the associated edit modelpublic final boolean isRemoveDeletedEntities()
isRemoveDeletedEntities
in interface EntityTableModel<SwingEntityEditModel>
public final void setRemoveDeletedEntities(boolean removeDeletedEntities)
setRemoveDeletedEntities
in interface EntityTableModel<SwingEntityEditModel>
removeDeletedEntities
- true if entities that are deleted via the associated edit model
should be automatically removed from this table modelpublic final EntityType entityType()
entityType
in interface EntityTableModel<SwingEntityEditModel>
public final EntityTableConditionModel tableConditionModel()
tableConditionModel
in interface EntityTableModel<SwingEntityEditModel>
EntityTableConditionModel
instance used by this table modelpublic final SwingEntityEditModel editModel()
EntityTableModel
EntityEditModel
associated with this table modeleditModel
in interface EntityTableModel<SwingEntityEditModel>
public final EntityConnectionProvider connectionProvider()
connectionProvider
in interface EntityTableModel<SwingEntityEditModel>
public final boolean isEditable()
isEditable
in interface EntityTableModel<SwingEntityEditModel>
public final void setEditable(boolean editable)
setEditable
in interface EntityTableModel<SwingEntityEditModel>
editable
- true if this table model should be editablepublic final boolean isBatchUpdateEnabled()
isBatchUpdateEnabled
in interface EntityTableModel<SwingEntityEditModel>
public final void setBatchUpdateEnabled(boolean batchUpdateEnabled)
setBatchUpdateEnabled
in interface EntityTableModel<SwingEntityEditModel>
batchUpdateEnabled
- true if this model should enable multiple entities to be updated at a timepublic final boolean isDeleteEnabled()
isDeleteEnabled
in interface EntityTableModel<SwingEntityEditModel>
public final boolean isUpdateEnabled()
isUpdateEnabled
in interface EntityTableModel<SwingEntityEditModel>
public final boolean isReadOnly()
isReadOnly
in interface EntityTableModel<SwingEntityEditModel>
public boolean isCellEditable(int rowIndex, int modelColumnIndex)
rowIndex
and modelColumnIndex
is editable.isCellEditable
in interface TableModel
isCellEditable
in class AbstractTableModel
rowIndex
- the row to editmodelColumnIndex
- the model index of the column to editsetValueAt(Object, int, int)
public final void setValueAt(Object value, int rowIndex, int modelColumnIndex)
setValueAt
in interface TableModel
setValueAt
in class AbstractTableModel
value
- the new valuerowIndex
- the row whose value is to be changedmodelColumnIndex
- the model index of the column to be changedpublic Color backgroundColor(int row, Attribute<?> attribute)
backgroundColor
in interface EntityTableModel<SwingEntityEditModel>
row
- the row for which to retrieve the background colorattribute
- the attribute for which to retrieve the background colorEntityDefinition.Builder#backgroundColorProvider(ColorProvider)
public Color foregroundColor(int row, Attribute<?> attribute)
foregroundColor
in interface EntityTableModel<SwingEntityEditModel>
row
- the row for which to retrieve the foreground colorattribute
- the attribute for which to retrieve the foreground colorEntityDefinition.Builder#foregroundColorProvider(ColorProvider)
public final Entity entityByKey(Key primaryKey)
entityByKey
in interface EntityTableModel<SwingEntityEditModel>
primaryKey
- the primary key to search bypublic final int indexOf(Key primaryKey)
indexOf
in interface EntityTableModel<SwingEntityEditModel>
primaryKey
- the primary keypublic final void addEntities(Collection<Entity> entities)
EntityTableModel
addEntities
in interface EntityTableModel<SwingEntityEditModel>
entities
- the entities to addpublic final void addEntitiesSorted(Collection<Entity> entities)
EntityTableModel
addEntitiesSorted
in interface EntityTableModel<SwingEntityEditModel>
entities
- the entities to addpublic final void addEntitiesAt(int index, Collection<Entity> entities)
EntityTableModel
addEntitiesAt
in interface EntityTableModel<SwingEntityEditModel>
index
- the index at which to addentities
- the entities to addpublic final void addEntitiesAtSorted(int index, Collection<Entity> entities)
EntityTableModel
addEntitiesAtSorted
in interface EntityTableModel<SwingEntityEditModel>
index
- the index at which to addentities
- the entities to addpublic final void replaceEntities(Collection<Entity> entities)
EntityTableModel
replaceEntities
in interface EntityTableModel<SwingEntityEditModel>
entities
- the entities to replacepublic final void refreshEntities(List<Key> keys)
EntityTableModel
refreshEntities
in interface EntityTableModel<SwingEntityEditModel>
keys
- the keys of the entities to refreshpublic boolean setForeignKeyConditionValues(ForeignKey foreignKey, Collection<Entity> foreignKeyValues)
EntityTableModel
foreignKeyValues
as the search condition values for the given foreign key
and refreshes this table model.setForeignKeyConditionValues
in interface EntityTableModel<SwingEntityEditModel>
foreignKey
- the foreign keyforeignKeyValues
- the entities to use as condition valuespublic final void replaceForeignKeyValues(ForeignKey foreignKey, Collection<Entity> foreignKeyValues)
EntityTableModel
foreignKeyValues
, useful when property
values have been changed in the referenced entity that must be reflected in the table model.replaceForeignKeyValues
in interface EntityTableModel<SwingEntityEditModel>
foreignKey
- the foreign keyforeignKeyValues
- the foreign key entitiespublic final void selectByKey(Collection<Key> keys)
EntityTableModel
primaryKeys
selectByKey
in interface EntityTableModel<SwingEntityEditModel>
keys
- the primary keys of the entities to selectpublic final Collection<Entity> entitiesByKey(Collection<Key> keys)
EntityTableModel
keys
entitiesByKey
in interface EntityTableModel<SwingEntityEditModel>
keys
- the primary key values to use as conditionkeys
public final void deleteSelected() throws DatabaseException
EntityTableModel
deleteSelected
in interface EntityTableModel<SwingEntityEditModel>
DatabaseException
- in case of a database exceptionpublic final void update(List<Entity> entities) throws ValidationException, DatabaseException
EntityTableModel
update
in interface EntityTableModel<SwingEntityEditModel>
entities
- the entities to updateValidationException
- in case validation failsDatabaseException
- in case of a database exceptionRecordModifiedException
- in case an entity was modified by another userEntityValidator.validate(Entity)
public final void setVisibleColumns(Attribute<?>... attributes)
EntityTableModel
setVisibleColumns
in interface EntityTableModel<SwingEntityEditModel>
attributes
- the column attributespublic final void setVisibleColumns(List<Attribute<?>> attributes)
EntityTableModel
setVisibleColumns
in interface EntityTableModel<SwingEntityEditModel>
attributes
- the column attributespublic final void savePreferences()
EntityTableModel
EntityModel.USE_CLIENT_PREFERENCES
is set to 'false',
calling this method has no effect.savePreferences
in interface EntityTableModel<SwingEntityEditModel>
public final String tableDataAsDelimitedString(char delimiter)
tableDataAsDelimitedString
in interface EntityTableModel<SwingEntityEditModel>
delimiter
- the delimiterpublic final StateObserver conditionChangedObserver()
conditionChangedObserver
in interface EntityTableModel<SwingEntityEditModel>
public final void addSelectionListener(EventListener listener)
addSelectionListener
in interface EntityTableModel<SwingEntityEditModel>
listener
- notified when the selection changes in the underlying selection modelpublic final ValueObserver<String> statusMessageObserver()
public static List<FilteredTableColumn<Attribute<?>>> createColumns(EntityDefinition definition)
TableColumn
s for all visible properties in the given entity type.definition
- the entity definitionpublic static List<FilteredTableColumn<Attribute<?>>> createColumns(List<Property<?>> properties)
TableColumn
s from the given properties.properties
- the propertiesprotected final <T extends Number> Optional<ColumnSummaryModel.SummaryValueProvider<T>> createColumnValueProvider(Attribute<?> attribute)
DefaultFilteredTableModel
createColumnValueProvider
in class DefaultFilteredTableModel<Entity,Attribute<?>>
T
- the value typeattribute
- the column identifierprotected Collection<Entity> refreshItems()
orderBy()
refreshItems
in class DefaultFilteredTableModel<Entity,Attribute<?>>
queryConditionRequiredState()
,
EntityTableConditionModel.condition()
protected Color getColor(Object color)
Color
instance from the given Object.
Color
instances are returned as-is, but instances of
String
are assumed to be in HEX format (f.ex: #ffff00" or #00ff00)
and are parsed with Color.decode(String)
. Colors parsed from Strings are cached.
Override to support other representations.color
- the object representing the color.Color
instance based on the given ObjectIllegalArgumentException
- in case the representation is not supportedNullPointerException
- in case color is nullprotected OrderBy orderBy()
OrderBy
clause is constructed
according to the sort order of column based attributes, otherwise the order by
clause defined for the underlying entity is returned.setOrderQueryBySortOrder(boolean)
,
EntityDefinition.orderBy()
protected Collection<Attribute<?>> selectAttributes()
isQueryHiddenColumns()
setting into account.isQueryHiddenColumns()
protected String userPreferencesKey()
return getClass().getSimpleName() + "-" + entityType();
Override in case this key is not unique.