Class WBatchEditProxyModel
This proxy model presents data from a source model, and caches any editing operation without
affecting the underlying source model, until commitAll()
or revertAll() is called. In this way, you can commit
all the editing in batch to the underlying source model, only when the user confirms the changes.
All editing operations are supported:
- changing data (setData())
- inserting and removing rows (
insertRows()andremoveRows()) - inserting and removing columns (
insertColumns()andremoveColumns())
The model supports both simple tabular models, as well as hierarchical (tree-like / treetable-like) models, with children under items in the first column.
Default values for a newly inserted row can be set using setNewRowData()
and flags for its items using setNewRowFlags().
-
Nested Class Summary
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WAbstractProxyModel
WAbstractProxyModel.BaseItemNested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidCommits changes.intgetColumnCount(WModelIndex parent) Returns the number of columns.getData(WModelIndex index, ItemDataRole role) Returns the data at a specific model index.getFlags(WModelIndex index) Returns the flags for an item.getHeaderData(int section, Orientation orientation, ItemDataRole role) Returns the row or column header data.getIndex(int row, int column, WModelIndex parent) Returns the child index for the given row and column.getParent(WModelIndex index) Returns the parent for a model index.intgetRowCount(WModelIndex parent) Returns the number of rows.booleaninsertColumns(int column, int count, WModelIndex parent) Inserts one or more columns.booleaninsertRows(int row, int count, WModelIndex parent) Inserts one or more rows.booleanisDirty()Returns whether changes have not yet been committed.mapFromSource(WModelIndex sourceIndex) Maps a source model index to the proxy model.mapToSource(WModelIndex proxyIndex) Maps a proxy model index to the source model.booleanremoveColumns(int column, int count, WModelIndex parent) Removes columns.booleanremoveRows(int row, int count, WModelIndex parent) Removes rows.voidReverts changes.booleansetData(WModelIndex index, Object value, ItemDataRole role) Sets item data.voidsetDirtyIndication(ItemDataRole role, Object data) Configures data used to indicate a modified item.final voidsetNewRowData(int column, Object data) Sets default data for a newly inserted row.voidsetNewRowData(int column, Object data, ItemDataRole role) Sets default data for a newly inserted row.final voidsetNewRowFlags(int column, ItemFlag flag, ItemFlag... flags) Sets the item flags for items in a newly inserted row.voidsetNewRowFlags(int column, EnumSet<ItemFlag> flags) Sets the item flags for items in a newly inserted row.voidsetSourceModel(WAbstractItemModel model) Sets the source model.voidSorts the model according to a particular column.Methods inherited from class eu.webtoolkit.jwt.WAbstractProxyModel
createSourceIndex, dropEvent, endShiftModelIndexes, fromRawIndex, getAcceptDropMimeTypes, getHeaderFlags, getMimeType, getSourceModel, setItemData, startShiftModelIndexes, toRawIndexMethods inherited from class eu.webtoolkit.jwt.WAbstractItemModel
beginInsertColumns, beginInsertRows, beginRemoveColumns, beginRemoveRows, collapseColumn, columnsAboutToBeInserted, columnsAboutToBeRemoved, columnsInserted, columnsRemoved, copyData, createIndex, createIndex, dataChanged, dropEvent, endInsertColumns, endInsertRows, endRemoveColumns, endRemoveRows, expandColumn, getColumnCount, getData, getData, getData, getData, getHeaderData, getHeaderData, getHeaderFlags, getIndex, getItemData, getRowCount, hasChildren, hasIndex, hasIndex, headerDataChanged, insertColumn, insertColumn, insertColumns, insertRow, insertRow, insertRows, layoutAboutToBeChanged, layoutChanged, match, modelReset, removeColumn, removeColumn, removeColumns, removeRow, removeRow, removeRows, reset, rowsAboutToBeInserted, rowsAboutToBeRemoved, rowsInserted, rowsRemoved, setData, setData, setData, setData, setHeaderData, setHeaderData, setHeaderData, sortMethods inherited from class eu.webtoolkit.jwt.WObject
getId, getObjectName, remove, setFormData, setObjectName, tr
-
Constructor Details
-
WBatchEditProxyModel
public WBatchEditProxyModel()Constructor.
-
-
Method Details
-
isDirty
public boolean isDirty()Returns whether changes have not yet been committed.Returns whether have been made to the proxy model, which could be committed using
commitAll()or reverted usingrevertAll(). -
commitAll
public void commitAll()Commits changes.This commits all changes to the source model.
- See Also:
-
revertAll
public void revertAll()Reverts changes.This reverts all changes.
- See Also:
-
setNewRowData
Sets default data for a newly inserted row.You can use this method to initialize data for a newly inserted row.
-
setNewRowData
Sets default data for a newly inserted row. -
setNewRowFlags
Sets the item flags for items in a newly inserted row.By default,
getFlags()will returnItemFlag.Selectable. -
setNewRowFlags
Sets the item flags for items in a newly inserted row. -
setDirtyIndication
Configures data used to indicate a modified item.This sets
datafor item data roleroleto be returned by data() for an item that is dirty (e.g. because it belongs to a newly inserted row/column, or because new data has been set for it.When
roleisItemDataRole.StyleClass, the style class is appended to any style already returned by the source model or set bysetNewRowData().By default there is no dirty indication.
-
mapFromSource
Description copied from class:WAbstractProxyModelMaps a source model index to the proxy model.This method returns a model index in the proxy model that corresponds to the model index
sourceIndexin the source model. This method must only be implemented for source model indexes that are mapped and thus are the result ofmapToSource().- Specified by:
mapFromSourcein classWAbstractProxyModel- See Also:
-
mapToSource
Description copied from class:WAbstractProxyModelMaps a proxy model index to the source model.This method returns a model index in the source model that corresponds to the proxy model index
proxyIndex.- Specified by:
mapToSourcein classWAbstractProxyModel- See Also:
-
setSourceModel
Sets the source model.The source model provides the actual data for the proxy model.
Ownership of the source model is not transferred.
All signals of the source model are propagated to the proxy model.
- Overrides:
setSourceModelin classWAbstractProxyModel
-
getColumnCount
Description copied from class:WAbstractItemModelReturns the number of columns.This returns the number of columns at index
parent.- Specified by:
getColumnCountin classWAbstractItemModel- See Also:
-
getRowCount
Description copied from class:WAbstractItemModelReturns the number of rows.This returns the number of rows at index
parent.- Specified by:
getRowCountin classWAbstractItemModel- See Also:
-
getParent
Description copied from class:WAbstractItemModelReturns the parent for a model index.An implementation should use
createIndex()to create a model index that corresponds to the parent of a given index.Note that the index itself may be stale (referencing a row/column within the parent that is outside the model geometry), but its parent (identified by the
WModelIndex.getInternalPointer()) is referencing an existing parent. A stale index can only be used while the model geometry is being updated, i.e. during the emission of the corresponding [rows/columns](Being)[Removed/Inserted]() signals.- Specified by:
getParentin classWAbstractItemModel- See Also:
-
getIndex
Description copied from class:WAbstractItemModelReturns the child index for the given row and column.When implementing this method, you can use
createIndex()to create an index that corresponds to the item atrowandcolumnwithinparent.If the location is invalid (out of bounds at the parent), then an invalid index must be returned.
- Specified by:
getIndexin classWAbstractItemModel- See Also:
-
getData
Description copied from class:WAbstractProxyModelReturns the data at a specific model index.The default proxy implementation translates the index to the source model, and calls
getSourceModel().data() with this index. -
setData
Sets item data.The default implementation will copy
ItemDataRole.Editdata toItemDataRole.Display. You may want to specialize the model to provide a more specialized editing behaviour.- Overrides:
setDatain classWAbstractProxyModel- See Also:
-
getFlags
Description copied from class:WAbstractProxyModelReturns the flags for an item.The default proxy implementation calls
getSourceModel().flags(mapToSource(index))- Overrides:
getFlagsin classWAbstractProxyModel- See Also:
-
getHeaderData
Description copied from class:WAbstractProxyModelReturns the row or column header data.The default proxy implementation constructs a dummy
WModelIndexwith the row set to 0 and column set tosectionif the orientation isOrientation.Horizontal, or with the row set tosectionand the column set to 0 if the orientation isOrientation.Vertical.The resulting section that is forwarded to
getSourceModel().getHeaderData()depends on how theWModelIndexis transformed withmapToSource(). -
insertRows
Description copied from class:WAbstractItemModelInserts one or more rows.In models that support row insertion, this inserts
countrows, starting atrow, and returnstrueif the operation was successful. The new rows are inserted underparent.If parent had no children, then a single column is added with
countrows.The default implementation returns
false.The model implementation must call
beginInsertRows()andendInsertRows()before and after the operation whenever its geometry is changed by inserting rows. This emits signals for views to properly react to these changes.- Overrides:
insertRowsin classWAbstractItemModel- See Also:
-
removeRows
Description copied from class:WAbstractItemModelRemoves rows.Returns
trueif the operation was successful.The default implementation returns
false.The model implementation must call
beginRemoveRows()andendRemoveRows()before and after the operation whenever its geometry is changed by removing rows. This emits signals for views to properly react to these changes.- Overrides:
removeRowsin classWAbstractItemModel- See Also:
-
insertColumns
Description copied from class:WAbstractProxyModelInserts one or more columns.The default proxy implementation calls
getSourceModel().insertColumns(column, count, parent)- Overrides:
insertColumnsin classWAbstractProxyModel- See Also:
-
removeColumns
Description copied from class:WAbstractProxyModelRemoves columns.The default proxy implementation calls
getSourceModel().removeColumns(column, count, parent)- Overrides:
removeColumnsin classWAbstractProxyModel- See Also:
-
sort
Description copied from class:WAbstractItemModelSorts the model according to a particular column.If the model supports sorting, then it should emit the
layoutAboutToBeChanged()signal, rearrange its items, and afterwards emit thelayoutChanged()signal.- Overrides:
sortin classWAbstractItemModel- See Also:
-