Package is.codion.swing.framework.model
Class SwingEntityTableModel
java.lang.Object
is.codion.framework.model.AbstractEntityTableModel<SwingEntityEditModel,SwingEntityEditor>
is.codion.swing.framework.model.SwingEntityTableModel
- All Implemented Interfaces:
FilterTableModel<Entity,,Attribute<?>> FilterModel<Entity>,EntityTableModel<SwingEntityEditModel,,SwingEntityEditor> SwingFilterTableModel<Entity,,Attribute<?>> TableModel
public class SwingEntityTableModel
extends AbstractEntityTableModel<SwingEntityEditModel,SwingEntityEditor>
implements SwingFilterTableModel<Entity,Attribute<?>>
A TableModel implementation for displaying and working with entities.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA Swing specificEntityTableModel.EntityRowEditorimplementation.Nested classes/interfaces inherited from class is.codion.framework.model.AbstractEntityTableModel
AbstractEntityTableModel.AbstractEntityRowEditor<R extends EntityEditor<R>>Nested classes/interfaces inherited from interface is.codion.framework.model.EntityTableModel
EntityTableModel.Config, EntityTableModel.EntityRowEditor, EntityTableModel.OnInsertNested classes/interfaces inherited from interface is.codion.common.model.filter.FilterModel
FilterModel.ExcludedItems<T>, FilterModel.IncludedItems<T>, FilterModel.IncludePredicate<T>, FilterModel.Items<T>, FilterModel.Refresher<T>, FilterModel.Sort<T>Nested classes/interfaces inherited from interface is.codion.common.model.component.table.FilterTableModel
FilterTableModel.Builder<R,C, B extends FilterTableModel.Builder<R, C, B>>, FilterTableModel.ColumnValues<C>, FilterTableModel.Export<C>, FilterTableModel.TableColumns<R, C> Nested classes/interfaces inherited from interface is.codion.swing.common.model.component.table.SwingFilterTableModel
SwingFilterTableModel.Builder<R,C>, SwingFilterTableModel.RowEditor<R, C> -
Field Summary
Fields inherited from interface is.codion.framework.model.EntityTableModel
ON_INSERT, ORDER_QUERYFields inherited from interface is.codion.common.model.filter.FilterModel
ASYNC, REFRESH_DELAY -
Constructor Summary
ConstructorsConstructorDescriptionSwingEntityTableModel(EntityType entityType, EntityConnection connection) Instantiates a new SwingEntityTableModel.SwingEntityTableModel(EntityType entityType, EntityConnection connection, Consumer<EntityTableModel.Config> config) Instantiates a new SwingEntityTableModel.SwingEntityTableModel(SwingEntityEditModel editModel) Instantiates a new SwingEntityTableModel.SwingEntityTableModel(SwingEntityEditModel editModel, Consumer<EntityTableModel.Config> config) Instantiates a new SwingEntityTableModel. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidaddTableModelListener(TableModelListener listener) protected final SwingFilterTableModel<Entity, Attribute<?>> final voidNotifies all listeners that all cell values in the table's rows may have changed.final voidfireTableRowsUpdated(int fromIndex, int toIndex) Notifies all listeners that the given rows have changedfinal Class<?> getColumnClass(int columnIndex) final intfinal StringgetColumnName(int columnIndex) final intgetValueAt(int rowIndex, int columnIndex) final booleanisCellEditable(int rowIndex, int modelColumnIndex) Returns true if the cell atrowIndexandmodelColumnIndexis editable.static SwingEntityTableModelof(EntityType entityType, Collection<Entity> entities, EntityConnection connection) Returns a table model of the given entities, without an item source or query conditions: refreshing its items does nothing.static SwingEntityTableModelof(Collection<Entity> entities, EntityConnection connection) Returns a table model of the given entities, without an item source or query conditions: refreshing its items does nothing.protected final voidonRowsUpdated(int fromIndex, int toIndex) Notifies all listeners that the given rows have changedfinal voidrefresh(Collection<Entity.Key> keys) Refreshes the entities with the given keys by re-selecting them from the underlying database.final voidremoveTableModelListener(TableModelListener listener) final FilterListSelection<Entity> final voidsetValueAt(@Nullable Object value, int rowIndex, int modelColumnIndex) Sets the value in the given cell and updates the underlying Entity.Methods inherited from class is.codion.framework.model.AbstractEntityTableModel
columns, connection, editModel, editor, entities, entityDefinition, entityType, export, filters, items, itemValidator, onInsert, orderQuery, query, removeDeleted, replace, restore, select, sort, store, tableColumns, toString, valuesMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface is.codion.common.model.filter.FilterModel
items
-
Constructor Details
-
SwingEntityTableModel
Instantiates a new SwingEntityTableModel.- Parameters:
entityType- the entityTypeconnection- the connection
-
SwingEntityTableModel
public SwingEntityTableModel(EntityType entityType, EntityConnection connection, Consumer<EntityTableModel.Config> config) Instantiates a new SwingEntityTableModel.- Parameters:
entityType- the entityTypeconnection- the connectionconfig- the table model configuration
-
SwingEntityTableModel
Instantiates a new SwingEntityTableModel.- Parameters:
editModel- the edit model
-
SwingEntityTableModel
public SwingEntityTableModel(SwingEntityEditModel editModel, Consumer<EntityTableModel.Config> config) Instantiates a new SwingEntityTableModel.- Parameters:
editModel- the edit modelconfig- the table model configuration
-
-
Method Details
-
isCellEditable
public final boolean isCellEditable(int rowIndex, int modelColumnIndex) Returns true if the cell atrowIndexandmodelColumnIndexis editable.- Specified by:
isCellEditablein interfaceTableModel- Parameters:
rowIndex- the row to editmodelColumnIndex- the model index of the column to edit- Returns:
- true if the cell is editable
-
setValueAt
Sets the value in the given cell and updates the underlying Entity.- Specified by:
setValueAtin 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:
getRowCountin interfaceTableModel
-
getValueAt
- Specified by:
getValueAtin interfaceTableModel
-
fireTableDataChanged
public final void fireTableDataChanged()Description copied from interface:SwingFilterTableModelNotifies 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:
fireTableDataChangedin interfaceSwingFilterTableModel<Entity,Attribute<?>>
-
fireTableRowsUpdated
public final void fireTableRowsUpdated(int fromIndex, int toIndex) Description copied from interface:SwingFilterTableModelNotifies all listeners that the given rows have changed- Specified by:
fireTableRowsUpdatedin interfaceSwingFilterTableModel<Entity,Attribute<?>> - Parameters:
fromIndex- the from indextoIndex- the to index
-
selection
- Specified by:
selectionin interfaceFilterModel<Entity>- Specified by:
selectionin interfaceFilterTableModel<Entity,Attribute<?>> - Specified by:
selectionin interfaceSwingFilterTableModel<Entity,Attribute<?>> - Returns:
- the
FilterListSelectioninstance used by this table model
-
getColumnCount
public final int getColumnCount()- Specified by:
getColumnCountin interfaceTableModel
-
getColumnName
- Specified by:
getColumnNamein interfaceTableModel
-
getColumnClass
- Specified by:
getColumnClassin interfaceTableModel
-
addTableModelListener
- Specified by:
addTableModelListenerin interfaceTableModel
-
removeTableModelListener
- Specified by:
removeTableModelListenerin interfaceTableModel
-
rowEditor
- Specified by:
rowEditorin interfaceEntityTableModel<SwingEntityEditModel,SwingEntityEditor> - Specified by:
rowEditorin interfaceSwingFilterTableModel<Entity,Attribute<?>> - Returns:
- the
SwingFilterTableModel.RowEditorproviding the row editing functionality
-
refresh
Description copied from interface:EntityTableModelRefreshes the entities with the given keys by re-selecting them from the underlying database.- Specified by:
refreshin interfaceEntityTableModel<SwingEntityEditModel,SwingEntityEditor> - Parameters:
keys- the keys of the entities to refresh
-
of
Returns a table model of the given entities, without an item source or query conditions: refreshing its items does nothing. The items still change viaAbstractEntityTableModel.items(), and via its edit model on insert, update and delete.- Parameters:
entities- the entities, of the same typeconnection- the connection- Returns:
- a new SwingEntityTableModel of the given entities
- Throws:
IllegalArgumentException- in caseentitiesis empty- See Also:
-
of
public static SwingEntityTableModel of(EntityType entityType, Collection<Entity> entities, EntityConnection connection) Returns a table model of the given entities, without an item source or query conditions: refreshing its items does nothing. The items still change viaAbstractEntityTableModel.items(), and via its edit model on insert, update and delete.- Parameters:
entityType- the entity typeentities- the entities, possibly noneconnection- the connection- Returns:
- a new SwingEntityTableModel of the given entities
-
filterModel
- Overrides:
filterModelin classAbstractEntityTableModel<SwingEntityEditModel,SwingEntityEditor> - Returns:
- the underlying model
-
onRowsUpdated
protected final void onRowsUpdated(int fromIndex, int toIndex) Description copied from class:AbstractEntityTableModelNotifies all listeners that the given rows have changed- Specified by:
onRowsUpdatedin classAbstractEntityTableModel<SwingEntityEditModel,SwingEntityEditor> - Parameters:
fromIndex- the from indextoIndex- the to index
-