Class WBatchEditProxyModel
public class WBatchEditProxyModel extends WAbstractProxyModel
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.BaseItem
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData
-
Constructor Summary
Constructors Constructor Description WBatchEditProxyModel()
Constructor.WBatchEditProxyModel(WObject parent)
Constructor. -
Method Summary
Modifier and Type Method Description void
commitAll()
Commits changes.int
getColumnCount(WModelIndex parent)
Returns the number of columns.java.lang.Object
getData(WModelIndex index, int role)
Returns the data at a specific model index.java.util.EnumSet<ItemFlag>
getFlags(WModelIndex index)
Returns the flags for an item.java.lang.Object
getHeaderData(int section, Orientation orientation, int role)
Returns the row or column header data.WModelIndex
getIndex(int row, int column, WModelIndex parent)
Returns the child index for the given row and column.WModelIndex
getParent(WModelIndex index)
Returns the parent for a model index.int
getRowCount(WModelIndex parent)
Returns the number of rows.boolean
insertColumns(int column, int count, WModelIndex parent)
Inserts one or more columns.boolean
insertRows(int row, int count, WModelIndex parent)
Inserts one or more rows.boolean
isDirty()
Returns whether changes have not yet been committed.WModelIndex
mapFromSource(WModelIndex sourceIndex)
Maps a source model index to the proxy model.WModelIndex
mapToSource(WModelIndex proxyIndex)
Maps a proxy model index to the source model.boolean
removeColumns(int column, int count, WModelIndex parent)
Removes columns.boolean
removeRows(int row, int count, WModelIndex parent)
Removes rows.void
revertAll()
Reverts changes.boolean
setData(WModelIndex index, java.lang.Object value, int role)
Sets item data.void
setDirtyIndication(int role, java.lang.Object data)
Configures data used to indicate a modified item.void
setNewRowData(int column, java.lang.Object data)
Sets default data for a newly inserted row.void
setNewRowData(int column, java.lang.Object data, int role)
Sets default data for a newly inserted row.void
setNewRowFlags(int column, ItemFlag flag, ItemFlag... flags)
Sets the item flags for items in a newly inserted row.void
setNewRowFlags(int column, java.util.EnumSet<ItemFlag> flags)
Sets the item flags for items in a newly inserted row.void
setSourceModel(WAbstractItemModel model)
Sets the source model.void
sort(int column, SortOrder order)
Sorts 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, toRawIndex
Methods inherited from class eu.webtoolkit.jwt.WAbstractItemModel
beginInsertColumns, beginInsertRows, beginRemoveColumns, beginRemoveRows, collapseColumn, columnsAboutToBeInserted, columnsAboutToBeRemoved, columnsInserted, columnsRemoved, createIndex, createIndex, dataChanged, 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, sort
Methods inherited from class eu.webtoolkit.jwt.WObject
addChild, getId, getObjectName, remove, setFormData, setObjectName, tr
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
WBatchEditProxyModel
Constructor. -
WBatchEditProxyModel
public WBatchEditProxyModel()Constructor.Calls
this((WObject)null)
-
-
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()
-
revertAll
public void revertAll()Reverts changes.This reverts all changes.
- See Also:
commitAll()
-
setNewRowData
public void setNewRowData(int column, java.lang.Object data, int role)Sets default data for a newly inserted row.You can use this method to initialize data for a newly inserted row.
-
setNewRowData
public final void setNewRowData(int column, java.lang.Object data)Sets default data for a newly inserted row. -
setNewRowFlags
Sets the item flags for items in a newly inserted row.By default,
getFlags()
will return ItemIsSelectable. -
setNewRowFlags
Sets the item flags for items in a newly inserted row. -
setDirtyIndication
public void setDirtyIndication(int role, java.lang.Object data)Configures data used to indicate a modified item.This sets
data
for item data rolerole
to be returned bygetData()
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
role
isItemDataRole.StyleClassRole
, 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:WAbstractProxyModel
Maps a source model index to the proxy model.This method returns a model index in the proxy model that corresponds to the model index
sourceIndex
in the source model. This method must only be implemented for source model indexes that are mapped and thus are the result ofmapToSource()
.- Specified by:
mapFromSource
in classWAbstractProxyModel
- See Also:
WAbstractProxyModel.mapToSource(WModelIndex proxyIndex)
-
mapToSource
Description copied from class:WAbstractProxyModel
Maps 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:
mapToSource
in classWAbstractProxyModel
- See Also:
WAbstractProxyModel.mapFromSource(WModelIndex sourceIndex)
-
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:
setSourceModel
in classWAbstractProxyModel
-
getColumnCount
Description copied from class:WAbstractItemModel
Returns the number of columns.This returns the number of columns at index
parent
.- Specified by:
getColumnCount
in classWAbstractItemModel
- See Also:
WAbstractItemModel.getRowCount(WModelIndex parent)
-
getRowCount
Description copied from class:WAbstractItemModel
Returns the number of rows.This returns the number of rows at index
parent
.- Specified by:
getRowCount
in classWAbstractItemModel
- See Also:
WAbstractItemModel.getColumnCount(WModelIndex parent)
-
getParent
Description copied from class:WAbstractItemModel
Returns 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:
getParent
in classWAbstractItemModel
- See Also:
WAbstractItemModel.getIndex(int row, int column, WModelIndex parent)
-
getIndex
Description copied from class:WAbstractItemModel
Returns 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 atrow
andcolumn
withinparent
.If the location is invalid (out of bounds at the parent), then an invalid index must be returned.
- Specified by:
getIndex
in classWAbstractItemModel
- See Also:
WAbstractItemModel.getParent(WModelIndex index)
-
getData
Description copied from class:WAbstractProxyModel
Returns the data at a specific model index.The default proxy implementation translates the index to the source model, and calls
getSourceModel()
.getData()
with this index. -
setData
Sets item data.The default implementation will copy
ItemDataRole.EditRole
data toItemDataRole.DisplayRole
. You may want to specialize the model to provide a more specialized editing behaviour.- Overrides:
setData
in classWAbstractProxyModel
- See Also:
WAbstractItemModel.getData(WModelIndex index, int role)
-
getFlags
Description copied from class:WAbstractProxyModel
Returns the flags for an item.The default proxy implementation calls
getSourceModel()
.flags(mapToSource(index))- Overrides:
getFlags
in classWAbstractProxyModel
- See Also:
ItemFlag
-
getHeaderData
Description copied from class:WAbstractProxyModel
Returns the row or column header data.The default proxy implementation constructs a dummy
WModelIndex
with the row set to 0 and column set tosection
if the orientation isOrientation.Horizontal
, or with the row set tosection
and the column set to 0 if the orientation isOrientation.Vertical
.The resulting section that is forwarded to
getSourceModel()
.getHeaderData()
depends on how theWModelIndex
is transformed withmapToSource()
. -
insertRows
Description copied from class:WAbstractItemModel
Inserts one or more rows.In models that support row insertion, this inserts
count
rows, starting atrow
, and returnstrue
if the operation was successful. The new rows are inserted underparent
.If parent had no children, then a single column is added with
count
rows.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:
insertRows
in classWAbstractItemModel
- See Also:
WAbstractItemModel.insertColumns(int column, int count, WModelIndex parent)
,WAbstractItemModel.removeRows(int row, int count, WModelIndex parent)
,WAbstractItemModel.beginInsertRows(WModelIndex parent, int first, int last)
,WAbstractItemModel.endInsertRows()
-
removeRows
Description copied from class:WAbstractItemModel
Removes rows.Returns
true
if 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:
removeRows
in classWAbstractItemModel
- See Also:
WAbstractItemModel.removeColumns(int column, int count, WModelIndex parent)
,WAbstractItemModel.insertRows(int row, int count, WModelIndex parent)
,WAbstractItemModel.beginRemoveRows(WModelIndex parent, int first, int last)
,WAbstractItemModel.endRemoveRows()
-
insertColumns
Description copied from class:WAbstractProxyModel
Inserts one or more columns.The default proxy implementation calls
getSourceModel()
.insertColumns(column, count, parent)- Overrides:
insertColumns
in classWAbstractProxyModel
- See Also:
WAbstractItemModel.insertRows(int row, int count, WModelIndex parent)
,WAbstractItemModel.removeColumns(int column, int count, WModelIndex parent)
,WAbstractItemModel.beginInsertColumns(WModelIndex parent, int first, int last)
,WAbstractItemModel.endInsertColumns()
-
removeColumns
Description copied from class:WAbstractProxyModel
Removes columns.The default proxy implementation calls
getSourceModel()
.removeColumns(column, count, parent)- Overrides:
removeColumns
in classWAbstractProxyModel
- See Also:
WAbstractItemModel.removeRows(int row, int count, WModelIndex parent)
,WAbstractItemModel.insertColumns(int column, int count, WModelIndex parent)
,WAbstractItemModel.beginRemoveColumns(WModelIndex parent, int first, int last)
,WAbstractItemModel.endRemoveColumns()
-
sort
Description copied from class:WAbstractItemModel
Sorts 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:
sort
in classWAbstractItemModel
- See Also:
WAbstractItemModel.layoutAboutToBeChanged()
,WAbstractItemModel.layoutChanged()
-