Package is.codion.swing.framework.model
Class SwingEntityTableModel
java.lang.Object
is.codion.framework.model.AbstractEntityTableModel<SwingEntityEditModel>
is.codion.swing.framework.model.SwingEntityTableModel
- All Implemented Interfaces:
FilterModel<Entity>
,EntityTableModel<SwingEntityEditModel>
,FilterTableModel<Entity,
,Attribute<?>> TableModel
public class SwingEntityTableModel
extends AbstractEntityTableModel<SwingEntityEditModel>
implements EntityTableModel<SwingEntityEditModel>, FilterTableModel<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.OnInsert
Nested classes/interfaces inherited from interface is.codion.common.model.FilterModel
FilterModel.AbstractRefresher<T>, FilterModel.FilteredItems<T>, FilterModel.Items<T>, FilterModel.Refresher<T>, FilterModel.VisibleItems<T>
Nested classes/interfaces inherited from interface is.codion.swing.common.model.component.table.FilterTableModel
FilterTableModel.Builder<R,
C>, FilterTableModel.Columns<R, C>, FilterTableModel.RefreshStrategy, FilterTableModel.TableSelection<R> -
Field Summary
Fields inherited from interface is.codion.framework.model.EntityTableModel
HANDLE_EDIT_EVENTS, ON_INSERT
Fields inherited from interface is.codion.common.model.FilterModel
ASYNC_REFRESH
-
Constructor Summary
ConstructorDescriptionSwingEntityTableModel
(EntityType entityType, EntityConnectionProvider connectionProvider) Instantiates a new SwingEntityTableModel.SwingEntityTableModel
(EntityType entityType, Collection<Entity> entities, EntityConnectionProvider connectionProvider) Instantiates a new SwingEntityTableModel containing the given entites.SwingEntityTableModel
(EntityConditionModel entityConditionModel) Instantiates a new SwingEntityTableModel.SwingEntityTableModel
(EntityQueryModel queryModel) Instantiates a new SwingEntityTableModel.SwingEntityTableModel
(SwingEntityEditModel editModel) Instantiates a new SwingEntityTableModel.SwingEntityTableModel
(SwingEntityEditModel editModel, EntityQueryModel queryModel) Instantiates a new SwingEntityTableModel.SwingEntityTableModel
(Collection<Entity> entities, EntityConnectionProvider connectionProvider) Instantiates a new SwingEntityTableModel containing the given entites. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
addTableModelListener
(TableModelListener listener) final FilterTableModel.Columns<Entity,
Attribute<?>> columns()
protected final FilterTableModel<Entity,
Attribute<?>> final TableConditionModel<Attribute<?>>
filters()
final void
Notifies all listeners that all cell values in the table's rows may have changed.final void
fireTableRowsUpdated
(int fromIndex, int toIndex) Notifies all listeners that the given rows have changedfinal Class<?>
getColumnClass
(int columnIndex) final Class<?>
getColumnClass
(Attribute<?> attribute) Returns the class of the column with the given identifierfinal int
final String
getColumnName
(int columnIndex) final int
final String
getStringAt
(int rowIndex, Attribute<?> attribute) Returns a String representation of the value for the given row and column.final Object
getValueAt
(int rowIndex, int columnIndex) boolean
isCellEditable
(int rowIndex, int modelColumnIndex) Returns true if the cell atrowIndex
andmodelColumnIndex
is editable.protected final void
onRowsUpdated
(int fromIndex, int toIndex) Notifies all listeners that the given rows have changedfinal void
removeTableModelListener
(TableModelListener listener) final <T> Collection<T>
selectedValues
(Attribute<?> attribute) final void
setValueAt
(Object value, int rowIndex, int modelColumnIndex) Sets the value in the given cell and updates the underlying Entity.final FilterTableSortModel<Entity,
Attribute<?>> sorter()
final <T> Collection<T>
Methods inherited from class is.codion.framework.model.AbstractEntityTableModel
connection, connectionProvider, deleteSelected, editable, editModel, entities, entityDefinition, entityType, handleEditEvents, items, onInsert, queryModel, refresh, refresh, refresh, refresher, removeDeleted, replace, replace, select, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface is.codion.framework.model.EntityTableModel
connection, connectionProvider, deleteSelected, editable, editModel, entities, entityDefinition, entityType, handleEditEvents, onInsert, queryModel, refresh, removeDeleted, replace, replace, select
Methods inherited from interface is.codion.common.model.FilterModel
items, refresher
Methods inherited from interface is.codion.swing.common.model.component.table.FilterTableModel
refresh, refresh
-
Constructor Details
-
SwingEntityTableModel
Instantiates a new SwingEntityTableModel.- Parameters:
entityType
- the entityTypeconnectionProvider
- the connection provider
-
SwingEntityTableModel
public SwingEntityTableModel(Collection<Entity> entities, EntityConnectionProvider connectionProvider) Instantiates a new SwingEntityTableModel containing the given entites.- Parameters:
entities
- the entities to populate with model withconnectionProvider
- the connection provider- Throws:
IllegalArgumentException
- in caseentities
is empty
-
SwingEntityTableModel
public SwingEntityTableModel(EntityType entityType, Collection<Entity> entities, EntityConnectionProvider connectionProvider) Instantiates a new SwingEntityTableModel containing the given entites.- Parameters:
entityType
- the entity typeentities
- the entities to populate with model withconnectionProvider
- the connection provider- Throws:
IllegalArgumentException
- in caseentities
is empty
-
SwingEntityTableModel
Instantiates a new SwingEntityTableModel.- Parameters:
entityConditionModel
- theEntityConditionModel
-
SwingEntityTableModel
Instantiates a new SwingEntityTableModel.- Parameters:
queryModel
- the table query model
-
SwingEntityTableModel
Instantiates a new SwingEntityTableModel.- Parameters:
editModel
- the edit model
-
SwingEntityTableModel
Instantiates a new SwingEntityTableModel.- Parameters:
editModel
- the edit modelqueryModel
- the table query model- Throws:
IllegalArgumentException
- in case the edit model and query model entity type is not the same
-
-
Method Details
-
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
-
getRowCount
public final int getRowCount()- Specified by:
getRowCount
in interfaceTableModel
-
getValueAt
- Specified by:
getValueAt
in interfaceTableModel
-
getStringAt
Description copied from interface:FilterTableModel
Returns a String representation of the value for the given row and column.- Specified by:
getStringAt
in interfaceFilterTableModel<Entity,
Attribute<?>> - Parameters:
rowIndex
- the row indexattribute
- the column identifier- Returns:
- the string value
-
fireTableDataChanged
public final void fireTableDataChanged()Description copied from interface:FilterTableModel
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 interfaceFilterTableModel<Entity,
Attribute<?>>
-
fireTableRowsUpdated
public final void fireTableRowsUpdated(int fromIndex, int toIndex) Description copied from interface:FilterTableModel
Notifies all listeners that the given rows have changed- Specified by:
fireTableRowsUpdated
in interfaceFilterTableModel<Entity,
Attribute<?>> - Parameters:
fromIndex
- the from indextoIndex
- the to index
-
values
- Specified by:
values
in interfaceFilterTableModel<Entity,
Attribute<?>> - Type Parameters:
T
- the value type- Parameters:
attribute
- 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:FilterTableModel
Returns the class of the column with the given identifier- Specified by:
getColumnClass
in interfaceFilterTableModel<Entity,
Attribute<?>> - Parameters:
attribute
- the column identifier- Returns:
- the Class representing the given column
-
selectedValues
- Specified by:
selectedValues
in interfaceFilterTableModel<Entity,
Attribute<?>> - Type Parameters:
T
- the value type- Parameters:
attribute
- 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
-
refreshStrategy
Description copied from interface:FilterTableModel
- Specified by:
refreshStrategy
in interfaceFilterTableModel<Entity,
Attribute<?>> - Returns:
- the
Value
controlling the refresh strategy
-
selection
- Specified by:
selection
in interfaceEntityTableModel<SwingEntityEditModel>
- Specified by:
selection
in interfaceFilterModel<Entity>
- Specified by:
selection
in interfaceFilterTableModel<Entity,
Attribute<?>> - Returns:
- the
MultiItemSelection
instance
-
filters
- Specified by:
filters
in interfaceFilterTableModel<Entity,
Attribute<?>> - Returns:
- the
TableConditionModel
used to filter this table model
-
sorter
- Specified by:
sorter
in interfaceFilterTableModel<Entity,
Attribute<?>> - Returns:
- the sort model
-
getColumnCount
public final int getColumnCount()- Specified by:
getColumnCount
in interfaceTableModel
-
getColumnName
- Specified by:
getColumnName
in interfaceTableModel
-
getColumnClass
- Specified by:
getColumnClass
in interfaceTableModel
-
addTableModelListener
- Specified by:
addTableModelListener
in interfaceTableModel
-
removeTableModelListener
- Specified by:
removeTableModelListener
in interfaceTableModel
-
columns
- Specified by:
columns
in interfaceFilterTableModel<Entity,
Attribute<?>> - Returns:
- the table columns
-
filterModel
- Overrides:
filterModel
in classAbstractEntityTableModel<SwingEntityEditModel>
- Returns:
- the underlying filter model
-
onRowsUpdated
protected final void onRowsUpdated(int fromIndex, int toIndex) Description copied from class:AbstractEntityTableModel
Notifies all listeners that the given rows have changed- Specified by:
onRowsUpdated
in classAbstractEntityTableModel<SwingEntityEditModel>
- Parameters:
fromIndex
- the from indextoIndex
- the to index
-