public class SwingEntityTableModel extends AbstractFilteredTableModel<Entity,Property> implements EntityTableModel<SwingEntityEditModel>
String entityId = "some.entity"; String clientTypeId = "JavadocDemo"; User user = new User("scott", "tiger"); EntityConnectionProvider connectionProvider = EntityConnectionProviders.createConnectionProvider(user, clientTypeId); SwingEntityTableModel tableModel = new SwingEntityTableModel(entityId, connectionProvider); SwingEntityEditModel editModel = ...; tableModel.setEditModel(editModel); EntityTablePanel panel = new EntityTablePanel(model);
Modifier and Type | Class and Description |
---|---|
static class |
SwingEntityTableModel.DefaultEntityTableSortModel
A default sort model implementation based on Entity
|
AbstractFilteredTableModel.DefaultColumnValueProvider
EntityTableModel.InsertAction
PREFERENCES_COLUMN_INDEX, PREFERENCES_COLUMN_VISIBLE, PREFERENCES_COLUMN_WIDTH, PREFERENCES_COLUMNS
Constructor and Description |
---|
SwingEntityTableModel(java.lang.String entityId,
EntityConnectionProvider connectionProvider)
Instantiates a new DefaultEntityTableModel with default column and condition models.
|
SwingEntityTableModel(java.lang.String entityId,
EntityConnectionProvider connectionProvider,
TableSortModel<Entity,Property,javax.swing.table.TableColumn> sortModel,
EntityTableConditionModel conditionModel)
Instantiates a new DefaultEntityTableModel.
|
Modifier and Type | Method and Description |
---|---|
void |
addEntities(java.util.List<Entity> entities,
boolean atTop,
boolean sortAfterAdding)
Adds the given entities to 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.
|
void |
addSelectionChangedListener(EventListener listener) |
protected void |
bindEditModelEvents()
Override to bind events using the edit model, called after the edit model has been set
|
protected ColumnSummaryModel.ColumnValueProvider |
createColumnValueProvider(Property property)
Creates a ColumnValueProvider for the given column
|
void |
deleteSelected()
Deletes the selected entities
|
protected void |
doRefresh()
Refreshes the data in this table model.
|
ColumnSummaryModel |
getColumnSummaryModel(java.lang.String propertyId)
Returns the
ColumnSummaryModel associated with the property identified by propertyId |
EntityTableConditionModel |
getConditionModel() |
EntityConnectionProvider |
getConnectionProvider() |
Domain |
getDomain() |
SwingEntityEditModel |
getEditModel()
Returns the
EntityEditModel associated with this table model |
java.util.Collection<Entity> |
getEntitiesByKey(java.util.Collection<Entity.Key> keys)
Finds entities according to the values in
keys |
Entity |
getEntityByKey(Entity.Key primaryKey) |
Entity.Definition |
getEntityDefinition() |
java.lang.String |
getEntityId() |
int |
getFetchCount()
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
|
EntityTableModel.InsertAction |
getInsertAction() |
protected Entity.OrderBy |
getOrderBy()
The order by clause to use when selecting the data for this model,
by default the order by clause defined for the underlying entity
|
java.awt.Color |
getPropertyBackgroundColor(int row,
Property property) |
int |
getPropertyColumnIndex(java.lang.String propertyId) |
State |
getQueryConditionRequiredState()
Returns a State controlling whether this table model should display all underlying entities
when no query condition has been set.
|
protected java.lang.String |
getSearchValueAt(int rowIndex,
javax.swing.table.TableColumn column)
Returns the value to use when searching through the table.
|
java.util.Iterator<Entity> |
getSelectedEntitiesIterator()
Returns an Iterator which iterates through the selected entities
|
java.lang.String |
getStatusMessage() |
java.lang.String |
getTableDataAsDelimitedString(char delimiter) |
protected java.lang.String |
getUserPreferencesKey()
Returns the key used to identify user preferences for this table model, that is column positions, widths and such.
|
protected java.lang.Object |
getValue(Entity entity,
Property property)
Return the value to display in a table cell for the given property of the given entity.
|
java.lang.Object |
getValueAt(int rowIndex,
int modelColumnIndex)
Returns the value for the cell at
modelColumnIndex and rowIndex . |
protected void |
handleDelete(EntityEditModel.DeleteEvent event) |
boolean |
hasEditModel() |
int |
indexOf(Entity.Key primaryKey) |
boolean |
isBatchUpdateAllowed() |
boolean |
isCellEditable(int rowIndex,
int modelColumnIndex)
Returns true if the cell at
rowIndex and modelColumnIndex
is editable. |
boolean |
isDeleteAllowed() |
boolean |
isReadOnly() |
boolean |
isRefreshOnForeignKeyConditionValuesSet() |
boolean |
isRemoveEntitiesOnDelete() |
boolean |
isUpdateAllowed() |
protected java.util.List<Entity> |
performQuery()
Queries for the data used to populate this EntityTableModel when it is refreshed,
using the order by clause returned by
getOrderBy() |
void |
refreshEntities(java.util.List<Entity.Key> keys)
Refreshes the entities with the given keys by re-selecting them from the underlying database.
|
void |
replaceEntities(java.util.Collection<Entity> entities)
Replaces the given entities in this table model
|
void |
replaceForeignKeyValues(java.lang.String foreignKeyEntityId,
java.util.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
|
SwingEntityTableModel |
setBatchUpdateAllowed(boolean batchUpdateAllowed) |
void |
setColumns(java.lang.String... propertyIds)
Arranges the column model so that only the given columns are visible and in the given order
|
void |
setEditModel(SwingEntityEditModel editModel)
Associates the given
EntityEditModel with this EntityTableModel , this enables delete/update
functionality via this table model as well as enabling it to
react to delete events in the edit model. |
SwingEntityTableModel |
setFetchCount(int fetchCount)
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 |
setForeignKeyConditionValues(ForeignKeyProperty foreignKeyProperty,
java.util.Collection<Entity> foreignKeyValues)
Sets
foreignKeyValues as the search condition values for the given foreignKeyProperty
and refreshes this table model. |
SwingEntityTableModel |
setInsertAction(EntityTableModel.InsertAction insertAction) |
SwingEntityTableModel |
setRefreshOnForeignKeyConditionValuesSet(boolean value) |
SwingEntityTableModel |
setRemoveEntitiesOnDelete(boolean value) |
void |
setSelectedByKey(java.util.Collection<Entity.Key> keys)
Sets the selected entities according to the primary keys in
primaryKeys |
void |
setSortingDirective(java.lang.String propertyId,
SortingDirective directive,
boolean addColumnToSort)
A convenience method for setting the sorting directive for the given property
|
void |
setValueAt(java.lang.Object value,
int rowIndex,
int modelColumnIndex)
Sets the value in the cell at
columnIndex and
rowIndex to aValue . |
java.lang.String |
toString() |
void |
update(java.util.List<Entity> entities)
Updates the given entities.
|
addFilteringListener, addItems, addItems, addRefreshDoneListener, addRefreshStartedListener, addRowsDeletedListener, addSortingListener, addTableDataChangedListener, addTableModelClearedListener, allowSelectionChange, clear, contains, filterContents, findNextItemCoordinate, findNextItemCoordinate, getAllItems, getColumnClass, getColumnCount, getColumnModel, getColumnSummaryModel, getFilterCondition, getFilteredItemCount, getFilteredItems, getItemAt, getRowCount, getSearchCondition, getSelectionModel, getSortModel, getValues, getVisibleItemCount, getVisibleItems, indexOf, isFiltered, isRegularExpressionSearch, isVisible, refresh, removeFilteringListener, removeItem, removeItems, removeItems, removeRefreshDoneListener, removeRefreshStartedListener, removeRowsDeletedListener, removeSortingListener, removeTableDataChangedListener, removeTableModelClearedListener, setFilterCondition, setRegularExpressionSearch, sortContents
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getColumnName, getListeners, getTableModelListeners, removeTableModelListener
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getAllItems, getRowCount, getSelectionModel
addFilteringListener, contains, filterContents, getFilterCondition, getFilteredItemCount, getFilteredItems, getVisibleItemCount, getVisibleItems, isFiltered, isVisible, removeFilteringListener, setFilterCondition
clear, refresh
public SwingEntityTableModel(java.lang.String entityId, EntityConnectionProvider connectionProvider)
entityId
- the entity IDconnectionProvider
- the db providerpublic SwingEntityTableModel(java.lang.String entityId, EntityConnectionProvider connectionProvider, TableSortModel<Entity,Property,javax.swing.table.TableColumn> sortModel, EntityTableConditionModel conditionModel)
entityId
- the entity IDconnectionProvider
- the db providerconditionModel
- the condition modelsortModel
- the sort modeljava.lang.NullPointerException
- in case conditionModel is nulljava.lang.IllegalArgumentException
- if conditionModel
entityId does not match the one supplied as parameterpublic final Domain getDomain()
getDomain
in interface EntityTableModel<SwingEntityEditModel>
public final Entity.Definition getEntityDefinition()
getEntityDefinition
in interface EntityTableModel<SwingEntityEditModel>
public final java.lang.String toString()
toString
in class java.lang.Object
public final void setEditModel(SwingEntityEditModel editModel)
EntityEditModel
with this EntityTableModel
, this enables delete/update
functionality via this table model as well as enabling it to
react to delete events in the edit model.
Throws a RuntimeException in case the edit model has been previously setsetEditModel
in interface EntityTableModel<SwingEntityEditModel>
editModel
- the edit model to associate with this table modelEntityTableModel.deleteSelected()
,
EntityTableModel.update(java.util.List)
public final boolean hasEditModel()
hasEditModel
in interface EntityTableModel<SwingEntityEditModel>
EntityTableModel
contains a EntityEditModel
public final int getFetchCount()
getFetchCount
in interface EntityTableModel<SwingEntityEditModel>
public final SwingEntityTableModel setFetchCount(int fetchCount)
setFetchCount
in interface EntityTableModel<SwingEntityEditModel>
fetchCount
- the fetch countpublic final State getQueryConditionRequiredState()
getQueryConditionRequiredState
in interface EntityTableModel<SwingEntityEditModel>
public final EntityTableModel.InsertAction getInsertAction()
getInsertAction
in interface EntityTableModel<SwingEntityEditModel>
public final SwingEntityTableModel 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 isRemoveEntitiesOnDelete()
isRemoveEntitiesOnDelete
in interface EntityTableModel<SwingEntityEditModel>
public final SwingEntityTableModel setRemoveEntitiesOnDelete(boolean value)
setRemoveEntitiesOnDelete
in interface EntityTableModel<SwingEntityEditModel>
value
- true if entities that are deleted via the associated edit model
should be automatically removed from this table modelEntityTableModel
instancepublic final java.lang.String getEntityId()
getEntityId
in interface EntityDataProvider
public final EntityTableConditionModel getConditionModel()
getConditionModel
in interface EntityTableModel<SwingEntityEditModel>
EntityTableConditionModel
instance used by this table modelpublic final SwingEntityEditModel getEditModel()
EntityEditModel
associated with this table modelgetEditModel
in interface EntityTableModel<SwingEntityEditModel>
EntityTableModel.setEditModel(EntityEditModel)
public final EntityConnectionProvider getConnectionProvider()
getConnectionProvider
in interface EntityDataProvider
public final boolean isBatchUpdateAllowed()
isBatchUpdateAllowed
in interface EntityTableModel<SwingEntityEditModel>
public final SwingEntityTableModel setBatchUpdateAllowed(boolean batchUpdateAllowed)
setBatchUpdateAllowed
in interface EntityTableModel<SwingEntityEditModel>
batchUpdateAllowed
- true if this model should allow multiple entities to be updated at a timeEntityTableModel
instancepublic final SwingEntityTableModel setRefreshOnForeignKeyConditionValuesSet(boolean value)
setRefreshOnForeignKeyConditionValuesSet
in interface EntityTableModel<SwingEntityEditModel>
value
- true if this table model should automatically refresh when foreign key condition values are setEntityTableModel
instanceEntityTableModel.setForeignKeyConditionValues(ForeignKeyProperty, Collection)
public final boolean isRefreshOnForeignKeyConditionValuesSet()
isRefreshOnForeignKeyConditionValuesSet
in interface EntityTableModel<SwingEntityEditModel>
EntityTableModel.setForeignKeyConditionValues(ForeignKeyProperty, Collection)
public final boolean isDeleteAllowed()
isDeleteAllowed
in interface EntityTableModel<SwingEntityEditModel>
EntityTableModel.hasEditModel()
,
EntityTableModel.setEditModel(EntityEditModel)
public final boolean isUpdateAllowed()
isUpdateAllowed
in interface EntityTableModel<SwingEntityEditModel>
EntityTableModel.hasEditModel()
,
EntityTableModel.setEditModel(EntityEditModel)
public final boolean isReadOnly()
isReadOnly
in interface EntityTableModel<SwingEntityEditModel>
EntityEditModel
or if that edit model is read onlyEntityTableModel.hasEditModel()
,
EntityTableModel.setEditModel(EntityEditModel)
public final int getPropertyColumnIndex(java.lang.String propertyId)
getPropertyColumnIndex
in interface EntityTableModel<SwingEntityEditModel>
propertyId
- the propertyIdpublic boolean isCellEditable(int rowIndex, int modelColumnIndex)
rowIndex
and modelColumnIndex
is editable. Otherwise, setValueAt
on the cell will not change the value of that cell.isCellEditable
in interface javax.swing.table.TableModel
isCellEditable
in class javax.swing.table.AbstractTableModel
rowIndex
- the row whose value to be queriedmodelColumnIndex
- the column whose value to be queriedsetValueAt(java.lang.Object, int, int)
public final java.lang.Object getValueAt(int rowIndex, int modelColumnIndex)
modelColumnIndex
and rowIndex
. *getValueAt
in interface javax.swing.table.TableModel
rowIndex
- the row whose value is to be queriedmodelColumnIndex
- the column whose value is to be queriedpublic void setValueAt(java.lang.Object value, int rowIndex, int modelColumnIndex)
columnIndex
and
rowIndex
to aValue
.setValueAt
in interface javax.swing.table.TableModel
setValueAt
in class javax.swing.table.AbstractTableModel
value
- the new valuerowIndex
- the row whose value is to be changedmodelColumnIndex
- the model index of the column to be changedpublic final void setSortingDirective(java.lang.String propertyId, SortingDirective directive, boolean addColumnToSort)
propertyId
- the property IDdirective
- the directiveaddColumnToSort
- if true then the column is added to the sorting stateTableSortModel.setSortingDirective(Object, SortingDirective, boolean)
public java.awt.Color getPropertyBackgroundColor(int row, Property property)
getPropertyBackgroundColor
in interface EntityTableModel<SwingEntityEditModel>
row
- the row for which to retrieve the background colorproperty
- the property for which to retrieve the background colorEntity.Definition.Builder#setColorProvider(Entity.ColorProvider)
public final Entity getEntityByKey(Entity.Key primaryKey)
getEntityByKey
in interface EntityTableModel<SwingEntityEditModel>
primaryKey
- the primary key to search bypublic final int indexOf(Entity.Key primaryKey)
indexOf
in interface EntityTableModel<SwingEntityEditModel>
primaryKey
- the primary keypublic final java.lang.String getStatusMessage()
getStatusMessage
in interface EntityTableModel<SwingEntityEditModel>
public final void addEntities(java.util.List<Entity> entities, boolean atTop, boolean sortAfterAdding)
addEntities
in interface EntityTableModel<SwingEntityEditModel>
entities
- the entities to addatTop
- if true then items are added at the top of the table model, else at the bottomsortAfterAdding
- if true and sorting is enabled then the model is sorted after addingTableSortModel.isSortingEnabled()
public final void replaceEntities(java.util.Collection<Entity> entities)
replaceEntities
in interface EntityTableModel<SwingEntityEditModel>
entities
- the entities to replacepublic final void refreshEntities(java.util.List<Entity.Key> keys)
refreshEntities
in interface EntityTableModel<SwingEntityEditModel>
keys
- the keys of the entities to refreshpublic void setForeignKeyConditionValues(ForeignKeyProperty foreignKeyProperty, java.util.Collection<Entity> foreignKeyValues)
foreignKeyValues
as the search condition values for the given foreignKeyProperty
and refreshes this table model.setForeignKeyConditionValues
in interface EntityTableModel<SwingEntityEditModel>
foreignKeyProperty
- the ID of the foreign key propertyforeignKeyValues
- the entities to use as condition valuespublic final void replaceForeignKeyValues(java.lang.String foreignKeyEntityId, java.util.Collection<Entity> foreignKeyValues)
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>
foreignKeyEntityId
- the entity ID of the foreign key valuesforeignKeyValues
- the foreign key entitiespublic final void setSelectedByKey(java.util.Collection<Entity.Key> keys)
primaryKeys
setSelectedByKey
in interface EntityTableModel<SwingEntityEditModel>
keys
- the primary keys of the entities to selectpublic final java.util.Collection<Entity> getEntitiesByKey(java.util.Collection<Entity.Key> keys)
keys
getEntitiesByKey
in interface EntityTableModel<SwingEntityEditModel>
keys
- the primary key values to use as conditionkeys
public final void deleteSelected() throws DatabaseException
deleteSelected
in interface EntityTableModel<SwingEntityEditModel>
DatabaseException
- in case of a database exceptionpublic final void update(java.util.List<Entity> entities) throws ValidationException, DatabaseException
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 userEntity.Validator.validate(java.util.Collection)
public final ColumnSummaryModel getColumnSummaryModel(java.lang.String propertyId)
ColumnSummaryModel
associated with the property identified by propertyId
getColumnSummaryModel
in interface EntityTableModel<SwingEntityEditModel>
propertyId
- the ID of the propertyColumnSummaryModel
for the given property IDpublic final java.util.Iterator<Entity> getSelectedEntitiesIterator()
getSelectedEntitiesIterator
in interface EntityTableModel<SwingEntityEditModel>
public final void setColumns(java.lang.String... propertyIds)
setColumns
in interface EntityTableModel<SwingEntityEditModel>
propertyIds
- the column identifierspublic final void savePreferences()
savePreferences
in interface EntityTableModel<SwingEntityEditModel>
public final java.lang.String getTableDataAsDelimitedString(char delimiter)
getTableDataAsDelimitedString
in interface EntityTableModel<SwingEntityEditModel>
delimiter
- the delimiterpublic final void addSelectionChangedListener(EventListener listener)
addSelectionChangedListener
in interface EntityTableModel<SwingEntityEditModel>
listener
- notified when the selection changes in the underlying selection modelprotected final ColumnSummaryModel.ColumnValueProvider createColumnValueProvider(Property property)
createColumnValueProvider
in class AbstractFilteredTableModel<Entity,Property>
property
- the column identifiercolumnIdentifier
protected final void doRefresh()
protected java.util.List<Entity> performQuery()
getOrderBy()
getQueryConditionRequiredState()
,
EntityTableConditionModel.getCondition()
protected java.lang.Object getValue(Entity entity, Property property)
entity
- the entityproperty
- the propertyjava.lang.NullPointerException
- in case entity or property is nullprotected final java.lang.String getSearchValueAt(int rowIndex, javax.swing.table.TableColumn column)
getSearchValueAt
in class AbstractFilteredTableModel<Entity,Property>
rowIndex
- the row indexcolumn
- the columnAbstractFilteredTableModel.findNextItemCoordinate(int, boolean, String)
protected Entity.OrderBy getOrderBy()
Entity.Definition#getOrderBy()
protected void handleDelete(EntityEditModel.DeleteEvent event)
protected void bindEditModelEvents()
protected java.lang.String getUserPreferencesKey()
return getClass().getSimpleName() + "-" + getEntityId();
Override in case this key is not unique.