Package is.codion.swing.framework.model
Class SwingEntityTableModel
java.lang.Object
is.codion.swing.framework.model.SwingEntityTableModel
- All Implemented Interfaces:
FilteredModel<Entity>
,EntityTableModel<SwingEntityEditModel>
,FilteredTableModel<Entity,
,Attribute<?>> TableModel
public class SwingEntityTableModel
extends Object
implements EntityTableModel<SwingEntityEditModel>, FilteredTableModel<Entity,Attribute<?>>
A TableModel implementation for displaying and working with entities.
-
Nested Class Summary
Nested classes/interfaces inherited from interface is.codion.framework.model.EntityTableModel
EntityTableModel.ColumnPreferences, EntityTableModel.OnInsert
Nested classes/interfaces inherited from interface is.codion.common.model.FilteredModel
FilteredModel.AbstractRefresher<T>, FilteredModel.Refresher<T>
Nested classes/interfaces inherited from interface is.codion.swing.common.model.component.table.FilteredTableModel
FilteredTableModel.Builder<R,
C>, FilteredTableModel.ColumnFactory<C>, FilteredTableModel.ColumnValueProvider<R, C> -
Field Summary
Fields inherited from interface is.codion.framework.model.EntityTableModel
ON_INSERT, ORDER_QUERY_BY_SORT_ORDER, QUERY_HIDDEN_COLUMNS
Fields inherited from interface is.codion.common.model.FilteredModel
ASYNC_REFRESH
-
Constructor Summary
ConstructorsConstructorDescriptionSwingEntityTableModel
(EntityType entityType, EntityConnectionProvider connectionProvider) Instantiates a new SwingEntityTableModel.SwingEntityTableModel
(EntityType entityType, EntityConnectionProvider connectionProvider, EntityConditionModelFactory conditionModelFactory) Instantiates a new SwingEntityTableModel.SwingEntityTableModel
(EntityType entityType, EntityConnectionProvider connectionProvider, FilteredTableModel.ColumnFactory<Attribute<?>> columnFactory) Instantiates a new SwingEntityTableModel.SwingEntityTableModel
(EntityType entityType, EntityConnectionProvider connectionProvider, FilteredTableModel.ColumnFactory<Attribute<?>> columnFactory, EntityConditionModelFactory conditionModelFactory) Instantiates a new SwingEntityTableModel.SwingEntityTableModel
(SwingEntityEditModel editModel) Instantiates a new SwingEntityTableModel.SwingEntityTableModel
(SwingEntityEditModel editModel, EntityConditionModelFactory conditionModelFactory) Instantiates a new SwingEntityTableModel.SwingEntityTableModel
(SwingEntityEditModel editModel, FilteredTableModel.ColumnFactory<Attribute<?>> columnFactory) Instantiates a new SwingEntityTableModel.SwingEntityTableModel
(SwingEntityEditModel editModel, FilteredTableModel.ColumnFactory<Attribute<?>> columnFactory, EntityConditionModelFactory conditionModelFactory) Instantiates a new SwingEntityTableModel. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
Adds the given item to the bottom of this table model.final void
final void
addItems
(Collection<Entity> items) Adds the given items to the bottom of this table model.final void
addItemsAt
(int index, Collection<Entity> items) Adds the given items to this table model, non-filtered items are added at the given index.final void
addItemsAtSorted
(int index, Collection<Entity> items) Adds the given items to this table model, non-filtered items are added at the given index.final void
addItemSorted
(Entity item) Adds the given item to the bottom of this table model.final void
addItemsSorted
(Collection<Entity> items) Adds the given items to the bottom of this table model.final void
addTableModelListener
(TableModelListener listener) Returns the ValueSet controlling which attributes are included when selecting entities to populate this model.backgroundColor
(int row, Attribute<?> attribute) final void
clear()
Clears all items from this table modelfinal EventObserver<?>
final FilteredTableColumnModel<Attribute<?>>
final StateObserver
protected boolean
conditionEnabled
(EntityTableConditionModel<Attribute<?>> conditionModel) It can be necessary to prevent the user from selecting too much data, when working with a large dataset.final EntityTableConditionModel<Attribute<?>>
final State
Returns a State controlling whether this table model should display all underlying entities when no query condition has been set.final EntityConnection
Do not cache or keep the connection returned by this method in a long living field, since it may become invalid and thereby unusable.final EntityConnectionProvider
final boolean
containsItem
(Entity item) Returns true if this model contains the given item, visible or filtered.final EventObserver<?>
final Collection<Entity>
Deletes the selected entitiesfinal State
editable()
final State
final <C extends SwingEntityEditModel>
Cfinal Entities
entities()
final EntityDefinition
final EntityType
final boolean
Returns true if this model contains the given item, and it is filtered, that is, is not visiblefinal int
final Collection<Entity>
final void
Filters this model according to the condition specified byFilteredModel.includeCondition()
.final TableConditionModel<Attribute<?>>
find
(Entity.Key primaryKey) Finds the entity in this table model having the given primary keyfinal Collection<Entity>
find
(Collection<Entity.Key> keys) Finds entities in this table model according to the values inkeys
final void
Notifies all listeners that all cell values in the table's rows may have changed.void
fireTableRowsUpdated
(int fromIndex, int toIndex) Notifies all listeners that the given rows have changedforegroundColor
(int row, Attribute<?> attribute) final Class<?>
getColumnClass
(int columnIndex) final Class<?>
getColumnClass
(Attribute<?> columnIdentifier) Returns the class of the column with the given identifierfinal int
final String
getColumnName
(int columnIndex) final int
final String
getStringAt
(int rowIndex, Attribute<?> columnIdentifier) Returns a String representation of the value for the given row and column.final Object
getValueAt
(int rowIndex, int columnIndex) final int
final int
indexOf
(Entity.Key primaryKey) boolean
isCellEditable
(int rowIndex, int modelColumnIndex) Returns true if the cell atrowIndex
andmodelColumnIndex
is editable.final Entity
itemAt
(int rowIndex) final Collection<Entity>
items()
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 null value means all rows should be fetchedfinal State
Note that when merging during refresh, the items are not sorted, since that would cause an empty-selection event, defeating the purpose of merging.final Value<EntityTableModel.OnInsert>
onInsert()
protected OrderBy
orderBy()
The order by clause to use when selecting the data for this model.final State
Specifies whether the current sort order is used as a basis for the query order by clause.final State
Returns whether the values of hidden columns are included when querying datafinal void
refresh()
Refreshes the items in this table model, according to the underlying conditionfinal void
refresh
(Collection<Entity.Key> keys) Refreshes the entities with the given keys by re-selecting them from the underlying database.final FilteredModel.Refresher<Entity>
protected Collection<Entity>
Queries the data used to populate this EntityTableModel when it is refreshed.final void
refreshThen
(Consumer<Collection<Entity>> afterRefresh) Refreshes the data in this filtered model using itsFilteredModel.Refresher
.final State
final void
removeItem
(Entity item) Removes the given item from this table modelfinal Entity
removeItemAt
(int index) Removes from this table model the visible element whose index is between indexremoveItems
(int fromIndex, int toIndex) Removes from this table model all visible elements whose index is between fromIndex, inclusive and toIndex, exclusivefinal void
removeItems
(Collection<Entity> items) Removes the given items from this table modelfinal void
removeTableModelListener
(TableModelListener listener) final void
replace
(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 attribute values have been changed in the referenced entity that must be reflected in the table model.final void
replace
(Collection<Entity> entities) Replaces the given entities in this table modelfinal String
rowsAsDelimitedString
(char delimiter) final void
Saves any user preferences.final FilteredTableSearchModel
final void
select
(Collection<Entity.Key> keys) Selects entities according to the primary keys inprimaryKeys
final <T> Collection<T>
selectedValues
(Attribute<?> columnIdentifier) final EventObserver<?>
final void
Sets the item at the given index.final void
setValueAt
(Object value, int rowIndex, int modelColumnIndex) Sets the value in the given cell and updates the underlying Entity.final void
setVisibleColumns
(Attribute<?>... attributes) Arranges the column model so that only the given columns are visible and in the given orderfinal void
setVisibleColumns
(List<Attribute<?>> attributes) Arranges the column model so that only the given columns are visible and in the given orderfinal void
Sorts the visible items according to theFilteredTableSortModel
, keeping the selected items.final FilteredTableSortModel<Entity,
Attribute<?>> final TableSummaryModel<Attribute<?>>
static SwingEntityTableModel
tableModel
(Collection<Entity> entities, EntityConnectionProvider connectionProvider) protected Color
Returns aColor
instance from the given Object.final String
toString()
protected String
Returns the key used to identify user preferences for this table model, that is column positions, widths and such.final <T> Collection<T>
final boolean
Returns true if this model contains the given item, and it is visible, that is, not filteredfinal int
-
Constructor Details
-
SwingEntityTableModel
Instantiates a new SwingEntityTableModel.- Parameters:
entityType
- the entityTypeconnectionProvider
- the connection provider
-
SwingEntityTableModel
public SwingEntityTableModel(EntityType entityType, EntityConnectionProvider connectionProvider, FilteredTableModel.ColumnFactory<Attribute<?>> columnFactory) Instantiates a new SwingEntityTableModel.- Parameters:
entityType
- the entityTypeconnectionProvider
- the connection providercolumnFactory
- the table column factory
-
SwingEntityTableModel
public SwingEntityTableModel(EntityType entityType, EntityConnectionProvider connectionProvider, EntityConditionModelFactory conditionModelFactory) Instantiates a new SwingEntityTableModel.- Parameters:
entityType
- the entityTypeconnectionProvider
- the connection providerconditionModelFactory
- the table condition model factory
-
SwingEntityTableModel
public SwingEntityTableModel(EntityType entityType, EntityConnectionProvider connectionProvider, FilteredTableModel.ColumnFactory<Attribute<?>> columnFactory, EntityConditionModelFactory conditionModelFactory) Instantiates a new SwingEntityTableModel.- Parameters:
entityType
- the entityTypeconnectionProvider
- the connection providercolumnFactory
- the table column factoryconditionModelFactory
- the table condition model factory
-
SwingEntityTableModel
Instantiates a new SwingEntityTableModel.- Parameters:
editModel
- the edit model
-
SwingEntityTableModel
public SwingEntityTableModel(SwingEntityEditModel editModel, FilteredTableModel.ColumnFactory<Attribute<?>> columnFactory) Instantiates a new SwingEntityTableModel.- Parameters:
editModel
- the edit modelcolumnFactory
- the table column factory
-
SwingEntityTableModel
public SwingEntityTableModel(SwingEntityEditModel editModel, EntityConditionModelFactory conditionModelFactory) Instantiates a new SwingEntityTableModel.- Parameters:
editModel
- the edit modelconditionModelFactory
- the table condition model factory
-
SwingEntityTableModel
public SwingEntityTableModel(SwingEntityEditModel editModel, FilteredTableModel.ColumnFactory<Attribute<?>> columnFactory, EntityConditionModelFactory conditionModelFactory) Instantiates a new SwingEntityTableModel.- Parameters:
editModel
- the edit modelcolumnFactory
- the table column factoryconditionModelFactory
- the table condition model factory
-
-
Method Details
-
entities
- Specified by:
entities
in interfaceEntityTableModel<SwingEntityEditModel>
- Returns:
- the underlying domain entities
-
entityDefinition
- Specified by:
entityDefinition
in interfaceEntityTableModel<SwingEntityEditModel>
- Returns:
- the definition of the underlying entity
-
toString
-
attributes
Description copied from interface:EntityTableModel
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.- Specified by:
attributes
in interfaceEntityTableModel<SwingEntityEditModel>
- Returns:
- the ValueSet controlling the selected attributes
- See Also:
-
limit
Description copied from interface:EntityTableModel
Returns the Value controlling the maximum number of rows to fetch via the underlying query the next time this table model is refreshed, a null value means all rows should be fetched- Specified by:
limit
in interfaceEntityTableModel<SwingEntityEditModel>
- Returns:
- the value controlling the limit
-
queryHiddenColumns
Description copied from interface:EntityTableModel
Returns whether the values of hidden columns are included when querying data- Specified by:
queryHiddenColumns
in interfaceEntityTableModel<SwingEntityEditModel>
- Returns:
- the State controlling whether the values of hidden columns are included when querying data
-
orderQueryBySortOrder
Description copied from interface:EntityTableModel
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.- Specified by:
orderQueryBySortOrder
in interfaceEntityTableModel<SwingEntityEditModel>
- Returns:
- the State controlling whether the current sort order should be used as a basis for the query order by clause
-
conditionRequired
Description copied from interface:EntityTableModel
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.- Specified by:
conditionRequired
in interfaceEntityTableModel<SwingEntityEditModel>
- Returns:
- a State specifying whether this table model requires a query condition
-
onInsert
- Specified by:
onInsert
in interfaceEntityTableModel<SwingEntityEditModel>
- Returns:
- the Value controlling the action to perform when entities are inserted via the associated edit model
- See Also:
-
removeDeleted
- Specified by:
removeDeleted
in interfaceEntityTableModel<SwingEntityEditModel>
- Returns:
- the State controlling whether entities that are deleted via the associated edit model should be automatically removed from this table model
-
editEvents
- Specified by:
editEvents
in interfaceEntityTableModel<SwingEntityEditModel>
- Returns:
- the state controlling whether this table model handles entity edit events, by replacing foreign key values
- See Also:
-
entityType
- Specified by:
entityType
in interfaceEntityTableModel<SwingEntityEditModel>
- Returns:
- the type of the entity this table model is based on
-
conditionModel
- Specified by:
conditionModel
in interfaceEntityTableModel<SwingEntityEditModel>
- Returns:
- the
EntityTableConditionModel
instance used by this table model
-
editModel
- Specified by:
editModel
in interfaceEntityTableModel<SwingEntityEditModel>
- Type Parameters:
C
- the edit model type Returns theEntityEditModel
associated with this table model- Returns:
- the edit model associated with this table model
-
connectionProvider
- Specified by:
connectionProvider
in interfaceEntityTableModel<SwingEntityEditModel>
- Returns:
- the connection provider used by this table model
-
connection
Description copied from interface:EntityTableModel
Do not cache or keep the connection returned by this method in a long living field, since it may become invalid and thereby unusable.- Specified by:
connection
in interfaceEntityTableModel<SwingEntityEditModel>
- Returns:
- the connection used by this table model
-
editable
- Specified by:
editable
in interfaceEntityTableModel<SwingEntityEditModel>
- Returns:
- the State controlling whether this table model is editable
-
isCellEditable
public boolean isCellEditable(int rowIndex, int modelColumnIndex) Returns true if the cell atrowIndex
andmodelColumnIndex
is editable.- Specified by:
isCellEditable
in interfaceTableModel
- Parameters:
rowIndex
- the row to editmodelColumnIndex
- the model index of the column to edit- Returns:
- true if the cell is editable
- See Also:
-
setValueAt
Sets the value in the given cell and updates the underlying Entity.- Specified by:
setValueAt
in interfaceTableModel
- Parameters:
value
- the new valuerowIndex
- the row whose value is to be changedmodelColumnIndex
- the model index of the column to be changed
-
backgroundColor
- Specified by:
backgroundColor
in interfaceEntityTableModel<SwingEntityEditModel>
- 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:
-
foregroundColor
- Specified by:
foregroundColor
in interfaceEntityTableModel<SwingEntityEditModel>
- 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:
-
find
Description copied from interface:EntityTableModel
Finds the entity in this table model having the given primary key- Specified by:
find
in interfaceEntityTableModel<SwingEntityEditModel>
- 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
- Specified by:
indexOf
in interfaceEntityTableModel<SwingEntityEditModel>
- Parameters:
primaryKey
- the primary key- Returns:
- the row index of the entity with the given primary key, -1 if not found
-
replace
Description copied from interface:EntityTableModel
Replaces the given entities in this table model- Specified by:
replace
in interfaceEntityTableModel<SwingEntityEditModel>
- Parameters:
entities
- the entities to replace
-
refresh
Description copied from interface:EntityTableModel
Refreshes the entities with the given keys by re-selecting them from the underlying database.- Specified by:
refresh
in interfaceEntityTableModel<SwingEntityEditModel>
- Parameters:
keys
- the keys of the entities to refresh
-
replace
Description copied from interface:EntityTableModel
For every entity in this table model, replaces the foreign key instance bearing the primary key with the corresponding entity fromforeignKeyValues
, useful when attribute values have been changed in the referenced entity that must be reflected in the table model.- Specified by:
replace
in interfaceEntityTableModel<SwingEntityEditModel>
- Parameters:
foreignKey
- the foreign keyforeignKeyValues
- the foreign key entities
-
select
Description copied from interface:EntityTableModel
Selects entities according to the primary keys inprimaryKeys
- Specified by:
select
in interfaceEntityTableModel<SwingEntityEditModel>
- Parameters:
keys
- the primary keys of the entities to select
-
find
Description copied from interface:EntityTableModel
Finds entities in this table model according to the values inkeys
- Specified by:
find
in interfaceEntityTableModel<SwingEntityEditModel>
- 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
-
deleteSelected
Description copied from interface:EntityTableModel
Deletes the selected entities- Specified by:
deleteSelected
in interfaceEntityTableModel<SwingEntityEditModel>
- Returns:
- the deleted entities
- Throws:
DatabaseException
- in case of a database exception
-
setVisibleColumns
Description copied from interface:EntityTableModel
Arranges the column model so that only the given columns are visible and in the given order- Specified by:
setVisibleColumns
in interfaceEntityTableModel<SwingEntityEditModel>
- Parameters:
attributes
- the column attributes
-
setVisibleColumns
Description copied from interface:EntityTableModel
Arranges the column model so that only the given columns are visible and in the given order- Specified by:
setVisibleColumns
in interfaceEntityTableModel<SwingEntityEditModel>
- Parameters:
attributes
- the column attributes
-
savePreferences
public final void savePreferences()Description copied from interface:EntityTableModel
Saves any user preferences. Note that ifEntityModel.USE_CLIENT_PREFERENCES
is set to 'false', calling this method has no effect.- Specified by:
savePreferences
in interfaceEntityTableModel<SwingEntityEditModel>
-
conditionChanged
- Specified by:
conditionChanged
in interfaceEntityTableModel<SwingEntityEditModel>
- Returns:
- a StateObserver indicating if the search condition has changed since last refresh
-
selectionEvent
- Specified by:
selectionEvent
in interfaceEntityTableModel<SwingEntityEditModel>
- Returns:
- an observer notified when the selection changes in the underlying selection model
-
filterItems
public final void filterItems()Description copied from interface:FilteredModel
Filters this model according to the condition specified byFilteredModel.includeCondition()
. If no include condition is specified this method does nothing. This method does not interfere with the internal ordering of the visible items.- Specified by:
filterItems
in interfaceFilteredModel<Entity>
- See Also:
-
includeCondition
- Specified by:
includeCondition
in interfaceFilteredModel<Entity>
- Returns:
- the include condition value
-
items
- Specified by:
items
in interfaceFilteredModel<Entity>
- Returns:
- an unmodifiable view of all visible and filtered items in this model
- See Also:
-
visibleItems
- Specified by:
visibleItems
in interfaceFilteredModel<Entity>
- Returns:
- an unmodifiable view of the visible items, in the order they appear in the model
-
filteredItems
- Specified by:
filteredItems
in interfaceFilteredModel<Entity>
- Returns:
- an unmodifiable view of the filtered items
-
visibleCount
public final int visibleCount()- Specified by:
visibleCount
in interfaceFilteredModel<Entity>
- Returns:
- the number of currently visible items
-
filteredCount
public final int filteredCount()- Specified by:
filteredCount
in interfaceFilteredModel<Entity>
- Returns:
- the number of currently filtered items
-
containsItem
Description copied from interface:FilteredModel
Returns true if this model contains the given item, visible or filtered.- Specified by:
containsItem
in interfaceFilteredModel<Entity>
- Parameters:
item
- the item- Returns:
- true if this model contains the item
-
visible
Description copied from interface:FilteredModel
Returns true if this model contains the given item, and it is visible, that is, not filtered- Specified by:
visible
in interfaceFilteredModel<Entity>
- Parameters:
item
- the item- Returns:
- true if the given item is visible
-
filtered
Description copied from interface:FilteredModel
Returns true if this model contains the given item, and it is filtered, that is, is not visible- Specified by:
filtered
in interfaceFilteredModel<Entity>
- Parameters:
item
- the item- Returns:
- true if the given item is filtered
-
refresher
- Specified by:
refresher
in interfaceFilteredModel<Entity>
- Returns:
- this models Refresher instance
-
refresh
public final void refresh()Description copied from interface:EntityTableModel
Refreshes the items in this table model, according to the underlying condition- Specified by:
refresh
in interfaceEntityTableModel<SwingEntityEditModel>
- Specified by:
refresh
in interfaceFilteredModel<Entity>
- Specified by:
refresh
in interfaceFilteredTableModel<Entity,
Attribute<?>> - See Also:
-
refreshThen
Description copied from interface:FilteredModel
Refreshes the data in this filtered model using itsFilteredModel.Refresher
. Note that this method only throws exceptions when run synchronously off the user interface thread. UseFilteredModel.Refresher.refreshFailedEvent()
to listen for exceptions that happen during asynchronous refresh.- Specified by:
refreshThen
in interfaceFilteredModel<Entity>
- Specified by:
refreshThen
in interfaceFilteredTableModel<Entity,
Attribute<?>> - Parameters:
afterRefresh
- called after a successful refresh, may be null- See Also:
-
clear
public final void clear()Description copied from interface:EntityTableModel
Clears all items from this table model- Specified by:
clear
in interfaceEntityTableModel<SwingEntityEditModel>
- Specified by:
clear
in interfaceFilteredTableModel<Entity,
Attribute<?>>
-
getRowCount
public final int getRowCount()- Specified by:
getRowCount
in interfaceEntityTableModel<SwingEntityEditModel>
- Specified by:
getRowCount
in interfaceTableModel
- Returns:
- the number of visible rows in this table model
-
indexOf
- Specified by:
indexOf
in interfaceFilteredTableModel<Entity,
Attribute<?>> - Parameters:
item
- the item- Returns:
- the index of the item in the table model
-
itemAt
- Specified by:
itemAt
in interfaceFilteredTableModel<Entity,
Attribute<?>> - Parameters:
rowIndex
- the row index- Returns:
- the item at the given row index in the table model
-
getValueAt
- Specified by:
getValueAt
in interfaceTableModel
-
getStringAt
Description copied from interface:FilteredTableModel
Returns a String representation of the value for the given row and column.- Specified by:
getStringAt
in interfaceFilteredTableModel<Entity,
Attribute<?>> - Parameters:
rowIndex
- the row indexcolumnIdentifier
- the column identifier- Returns:
- the string value
-
addItems
Description copied from interface:FilteredTableModel
Adds the given items to the bottom of this table model.- Specified by:
addItems
in interfaceFilteredTableModel<Entity,
Attribute<?>> - Parameters:
items
- the items to add
-
addItemsSorted
Description copied from interface:FilteredTableModel
Adds the given items to the bottom of this table model. If sorting is enabled this model is sorted after the items have been added.- Specified by:
addItemsSorted
in interfaceFilteredTableModel<Entity,
Attribute<?>> - Parameters:
items
- the items to add
-
addItemsAt
Description copied from interface:FilteredTableModel
Adds the given items to this table model, non-filtered items are added at the given index.- Specified by:
addItemsAt
in interfaceFilteredTableModel<Entity,
Attribute<?>> - Parameters:
index
- the index at which to add the itemsitems
- the items to add
-
addItemsAtSorted
Description copied from interface:FilteredTableModel
Adds the given items to this table model, non-filtered items are added at the given index. If sorting is enabled this model is sorted after the items have been added.- Specified by:
addItemsAtSorted
in interfaceFilteredTableModel<Entity,
Attribute<?>> - Parameters:
index
- the index at which to add the itemsitems
- the items to add- See Also:
-
addItem
Description copied from interface:FilteredTableModel
Adds the given item to the bottom of this table model.- Specified by:
addItem
in interfaceFilteredTableModel<Entity,
Attribute<?>> - Parameters:
item
- the item to add
-
addItemAt
- Specified by:
addItemAt
in interfaceFilteredTableModel<Entity,
Attribute<?>> - Parameters:
index
- the indexitem
- the item to add
-
addItemSorted
Description copied from interface:FilteredTableModel
Adds the given item to the bottom of this table model. If sorting is enabled this model is sorted after the item has been added.- Specified by:
addItemSorted
in interfaceFilteredTableModel<Entity,
Attribute<?>> - Parameters:
item
- the item to add
-
setItemAt
Description copied from interface:FilteredTableModel
Sets the item at the given index. If the item should be filtered calling this method has no effect.- Specified by:
setItemAt
in interfaceFilteredTableModel<Entity,
Attribute<?>> - Parameters:
index
- the indexitem
- the item- See Also:
-
removeItems
Description copied from interface:FilteredTableModel
Removes the given items from this table model- Specified by:
removeItems
in interfaceFilteredTableModel<Entity,
Attribute<?>> - Parameters:
items
- the items to remove from the model
-
removeItem
Description copied from interface:FilteredTableModel
Removes the given item from this table model- Specified by:
removeItem
in interfaceFilteredTableModel<Entity,
Attribute<?>> - Parameters:
item
- the item to remove from the model
-
removeItemAt
Description copied from interface:FilteredTableModel
Removes from this table model the visible element whose index is between index- Specified by:
removeItemAt
in interfaceFilteredTableModel<Entity,
Attribute<?>> - Parameters:
index
- the index of the row to be removed- Returns:
- the removed item
-
removeItems
Description copied from interface:FilteredTableModel
Removes from this table model all visible elements whose index is between fromIndex, inclusive and toIndex, exclusive- Specified by:
removeItems
in interfaceFilteredTableModel<Entity,
Attribute<?>> - Parameters:
fromIndex
- index of first row to be removedtoIndex
- index after last row to be removed- Returns:
- the removed items
-
fireTableDataChanged
public final void fireTableDataChanged()Description copied from interface:FilteredTableModel
Notifies all listeners that all cell values in the table's rows may have changed. The number of rows may also have changed and the JTable should redraw the table from scratch. The structure of the table (as in the order of the columns) is assumed to be the same.- Specified by:
fireTableDataChanged
in interfaceFilteredTableModel<Entity,
Attribute<?>>
-
fireTableRowsUpdated
public void fireTableRowsUpdated(int fromIndex, int toIndex) Description copied from interface:FilteredTableModel
Notifies all listeners that the given rows have changed- Specified by:
fireTableRowsUpdated
in interfaceFilteredTableModel<Entity,
Attribute<?>> - Parameters:
fromIndex
- the from indextoIndex
- the to index
-
columnModel
- Specified by:
columnModel
in interfaceFilteredTableModel<Entity,
Attribute<?>> - Returns:
- the FilteredTableColumnModel used by this TableModel
-
values
- Specified by:
values
in interfaceFilteredTableModel<Entity,
Attribute<?>> - Type Parameters:
T
- the value type- Parameters:
columnIdentifier
- the identifier of the column for which to retrieve the values- Returns:
- the values (including nulls) of the column identified by the given identifier from the visible rows in the table model
-
getColumnClass
Description copied from interface:FilteredTableModel
Returns the class of the column with the given identifier- Specified by:
getColumnClass
in interfaceFilteredTableModel<Entity,
Attribute<?>> - Parameters:
columnIdentifier
- the column identifier- Returns:
- the Class representing the given column
-
selectedValues
- Specified by:
selectedValues
in interfaceFilteredTableModel<Entity,
Attribute<?>> - Type Parameters:
T
- the value type- Parameters:
columnIdentifier
- the identifier of the column for which to retrieve the values- Returns:
- the values (including nulls) of the column identified by the given identifier from the selected rows in the table model
-
rowsAsDelimitedString
- Specified by:
rowsAsDelimitedString
in interfaceFilteredTableModel<Entity,
Attribute<?>> - Parameters:
delimiter
- the delimiter- Returns:
- the table rows as a tab delimited string, with column names as a header
-
mergeOnRefresh
Description copied from interface:FilteredTableModel
Note that when merging during refresh, the items are not sorted, since that would cause an empty-selection event, defeating the purpose of merging.- Specified by:
mergeOnRefresh
in interfaceFilteredTableModel<Entity,
Attribute<?>> - Returns:
- the State controlling whether merge on refresh should be enabled
-
sortItems
public final void sortItems()Description copied from interface:FilteredTableModel
Sorts the visible items according to theFilteredTableSortModel
, keeping the selected items. Calling this method with the sort model disabled has no effect.- Specified by:
sortItems
in interfaceFilteredTableModel<Entity,
Attribute<?>> - See Also:
-
selectionModel
- Specified by:
selectionModel
in interfaceEntityTableModel<SwingEntityEditModel>
- Specified by:
selectionModel
in interfaceFilteredTableModel<Entity,
Attribute<?>> - Returns:
- the
TableSelectionModel
-
sortModel
- Specified by:
sortModel
in interfaceFilteredTableModel<Entity,
Attribute<?>> - Returns:
- the sorting model
-
searchModel
- Specified by:
searchModel
in interfaceFilteredTableModel<Entity,
Attribute<?>> - Returns:
- the search model
-
filterModel
- Specified by:
filterModel
in interfaceFilteredTableModel<Entity,
Attribute<?>> - Returns:
- the filter model used by this table model
-
summaryModel
- Specified by:
summaryModel
in interfaceFilteredTableModel<Entity,
Attribute<?>> - Returns:
- the summary model
-
getColumnCount
public final int getColumnCount()- Specified by:
getColumnCount
in interfaceTableModel
-
getColumnName
- Specified by:
getColumnName
in interfaceTableModel
-
getColumnClass
- Specified by:
getColumnClass
in interfaceTableModel
-
dataChangedEvent
- Specified by:
dataChangedEvent
in interfaceFilteredTableModel<Entity,
Attribute<?>> - Returns:
- an observer notified each time the table data changes
-
clearedEvent
- Specified by:
clearedEvent
in interfaceFilteredTableModel<Entity,
Attribute<?>> - Returns:
- an observer notified each time the table model is cleared
-
addTableModelListener
- Specified by:
addTableModelListener
in interfaceTableModel
-
removeTableModelListener
- Specified by:
removeTableModelListener
in interfaceTableModel
-
tableModel
public static SwingEntityTableModel tableModel(Collection<Entity> entities, EntityConnectionProvider connectionProvider) - Parameters:
entities
- the entities to displayconnectionProvider
- the connection provider- Returns:
- a static
SwingEntityTableModel
instance containing the given entities - Throws:
IllegalArgumentException
- in caseentities
is empty
-
refreshItems
Queries the data used to populate this EntityTableModel when it is refreshed. This method should take into account the where and having conditions (EntityTableConditionModel.where(Conjunction)
,EntityTableConditionModel.having(Conjunction)
), order by clause (orderBy()
), the limit (limit()
) and select attributes (attributes()
) when querying.- Returns:
- entities selected from the database according to the query condition.
- See Also:
-
conditionEnabled
It can be necessary to prevent the user from selecting too much data, when working with a large dataset. This can be done by enabling theconditionRequired()
, which prevents a refresh as long as this method returnsfalse
. This default implementation simply returnsTableConditionModel.enabled()
. Override for a more fine grained control, such as requiring a specific column condition to be enabled.- Parameters:
conditionModel
- the table condition model- Returns:
- true if enough conditions are enabled for a safe refresh
- See Also:
-
toColor
Returns aColor
instance from the given Object.Color
instances are returned as-is, but instances ofString
are assumed to be in HEX format (f.ex: #ffff00" or #00ff00) and are parsed withColor.decode(String)
. Colors parsed from Strings are cached. Override to support other representations.- Parameters:
color
- the object representing the color.- Returns:
- a
Color
instance based on the given Object - Throws:
IllegalArgumentException
- in case the representation is not supportedNullPointerException
- in case color is null
-
orderBy
The order by clause to use when selecting the data for this model. If ordering by sort order is enabled aOrderBy
clause is constructed according to the sort order of column based attributes, otherwise the order by clause defined for the underlying entity is returned.- Returns:
- the order by clause
- See Also:
-
userPreferencesKey
Returns the key used to identify user preferences for this table model, that is column positions, widths and such. The default implementation is:return getClass().getSimpleName() + "-" + entityType();
- Returns:
- the key used to identify user preferences for this table model
-