eu.webtoolkit.jwt
Class WBatchEditProxyModel

java.lang.Object
  extended by eu.webtoolkit.jwt.WObject
      extended by eu.webtoolkit.jwt.WAbstractItemModel
          extended by eu.webtoolkit.jwt.WAbstractProxyModel
              extended by eu.webtoolkit.jwt.WBatchEditProxyModel

public class WBatchEditProxyModel
extends WAbstractProxyModel

A proxy model for Wt's item models that provides batch editing.

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:

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
 
Constructor Summary
WBatchEditProxyModel()
          Constructor.
WBatchEditProxyModel(WObject parent)
          Constructor.
 
Method Summary
 void commitAll()
          Commits changes.
 int getColumnCount(WModelIndex parent)
          Returns the number of columns.
 java.lang.Object getData(WModelIndex index, int role)
          Returns 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, java.util.EnumSet<ItemFlag> flags)
          Sets the item flags for items in a newly inserted row.
 void setNewRowFlags(int column, ItemFlag flag, 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, fromRawIndex, getAcceptDropMimeTypes, getMimeType, getSourceModel, shiftModelIndexes, toRawIndex
 
Methods inherited from class eu.webtoolkit.jwt.WAbstractItemModel
beginInsertColumns, beginInsertRows, beginRemoveColumns, beginRemoveRows, collapseColumn, columnsAboutToBeInserted, columnsAboutToBeRemoved, columnsInserted, columnsRemoved, createIndex, dataChanged, endInsertColumns, endInsertRows, endRemoveColumns, endRemoveRows, expandColumn, getColumnCount, getData, getData, getData, getData, getHeaderData, getHeaderData, getHeaderFlags, 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, setItemData, sort
 
Methods inherited from class eu.webtoolkit.jwt.WObject
addChild, getId, getObjectName, remove, setObjectName, tr
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WBatchEditProxyModel

public WBatchEditProxyModel(WObject parent)
Constructor.


WBatchEditProxyModel

public WBatchEditProxyModel()
Constructor.

Calls this((WObject)null)

Method Detail

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 using revertAll().


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.

Calls setNewRowData(column, data, ItemDataRole.DisplayRole)


setNewRowFlags

public void setNewRowFlags(int column,
                           java.util.EnumSet<ItemFlag> flags)
Sets the item flags for items in a newly inserted row.

By default, getFlags() will return ItemIsSelectable.


setNewRowFlags

public final void setNewRowFlags(int column,
                                 ItemFlag flag,
                                 ItemFlag... flags)
Sets the item flags for items in a newly inserted row.

Calls setNewRowFlags(column, EnumSet.of(flag, flags))


setDirtyIndication

public void setDirtyIndication(int role,
                               java.lang.Object data)
Configures data used to indicate a modified item.

This sets data for item data role role to be returned by getData() 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 is ItemDataRole.StyleClassRole, the style class is appended to any style already returned by the source model or set by setNewRowData().

By default there is no dirty indication.


mapFromSource

public WModelIndex mapFromSource(WModelIndex sourceIndex)
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 of mapToSource().

Specified by:
mapFromSource in class WAbstractProxyModel
See Also:
WAbstractProxyModel.mapToSource(WModelIndex proxyIndex)

mapToSource

public WModelIndex mapToSource(WModelIndex proxyIndex)
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 class WAbstractProxyModel
See Also:
WAbstractProxyModel.mapFromSource(WModelIndex sourceIndex)

setSourceModel

public void setSourceModel(WAbstractItemModel model)
Description copied from class: WAbstractProxyModel
Sets the source model.

The source model provides the actual data for the proxy model.

Ownership of the source model is not transferred.

Overrides:
setSourceModel in class WAbstractProxyModel

getColumnCount

public int getColumnCount(WModelIndex parent)
Description copied from class: WAbstractItemModel
Returns the number of columns.

This returns the number of columns at index parent.

Specified by:
getColumnCount in class WAbstractItemModel
See Also:
WAbstractItemModel.getRowCount(WModelIndex parent)

getRowCount

public int getRowCount(WModelIndex parent)
Description copied from class: WAbstractItemModel
Returns the number of rows.

This returns the number of rows at index parent.

Specified by:
getRowCount in class WAbstractItemModel
See Also:
WAbstractItemModel.getColumnCount(WModelIndex parent)

getParent

public WModelIndex getParent(WModelIndex index)
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 class WAbstractItemModel
See Also:
WAbstractItemModel.getIndex(int row, int column, WModelIndex parent)

getIndex

public WModelIndex getIndex(int row,
                            int column,
                            WModelIndex parent)
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 at row and column within parent.

If the location is invalid (out of bounds at the parent), then an invalid index must be returned.

Specified by:
getIndex in class WAbstractItemModel
See Also:
WAbstractItemModel.getParent(WModelIndex index)

getData

public java.lang.Object getData(WModelIndex index,
                                int role)
Description copied from class: WAbstractItemModel
Returns data at a specific model index.

Return data for a given role at a given index.

You should check the role to decide what data to return. Usually a View class will ask for data for several roles which affect not only the contents (ItemDataRole.DisplayRole) but also icons ( ItemDataRole.DecorationRole), URLs (ItemDataRole.LinkRole ), and other visual aspects. If your item does not specify data for a particular role, it should simply return a boost::any().

Overrides:
getData in class WAbstractProxyModel
See Also:
WAbstractItemModel.getFlags(WModelIndex index), WAbstractItemModel.getHeaderData(int section, Orientation orientation, int role), WAbstractItemModel.setData(WModelIndex index, Object value, int role)

setData

public boolean setData(WModelIndex index,
                       java.lang.Object value,
                       int role)
Sets item data.

The default implementation will copy ItemDataRole.EditRole data to ItemDataRole.DisplayRole. You may want to specialize the model to provide a more specialized editing behaviour.

Overrides:
setData in class WAbstractProxyModel
See Also:
WAbstractItemModel.getData(WModelIndex index, int role)

getFlags

public java.util.EnumSet<ItemFlag> getFlags(WModelIndex index)
Description copied from class: WAbstractItemModel
Returns the flags for an item.

The default implementation returns ItemIsSelectable.

Overrides:
getFlags in class WAbstractProxyModel
See Also:
ItemFlag

getHeaderData

public java.lang.Object getHeaderData(int section,
                                      Orientation orientation,
                                      int role)
Description copied from class: WAbstractItemModel
Returns the row or column header data.

When orientation is Horizontal, section is a column number, when orientation is Vertical, section is a row number.

Overrides:
getHeaderData in class WAbstractItemModel
See Also:
WAbstractItemModel.getData(WModelIndex index, int role), WAbstractItemModel.setHeaderData(int section, Orientation orientation, Object value, int role)

insertRows

public boolean insertRows(int row,
                          int count,
                          WModelIndex parent)
Description copied from class: WAbstractItemModel
Inserts one or more rows.

In models that support row insertion, this inserts count rows, starting at row, and returns true if the operation was successful. The new rows are inserted under parent.

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() and endInsertRows() 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 class WAbstractItemModel
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

public boolean removeRows(int row,
                          int count,
                          WModelIndex parent)
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() and endRemoveRows() 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 class WAbstractItemModel
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

public boolean insertColumns(int column,
                             int count,
                             WModelIndex parent)
Description copied from class: WAbstractItemModel
Inserts one or more columns.

In models that support column insertion, this inserts count columns, starting at column, and returns true if the operation was successful. The new columns are inserted under parent.

The default implementation returns false.

The model implementation must call beginInsertColumns() and endInsertColumns() before and after the operation whenever its geometry is changed by inserting columns. This emits signals for views to properly react to these changes.

Overrides:
insertColumns in class WAbstractProxyModel
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

public boolean removeColumns(int column,
                             int count,
                             WModelIndex parent)
Description copied from class: WAbstractItemModel
Removes columns.

Returns true if the operation was successful.

The default implementation returns false.

The model implementation must call beginRemoveColumns() and endRemoveColumns() before and after the operation whenever its geometry is changed by removing columns. This emits signals for views to properly react to these changes.

Overrides:
removeColumns in class WAbstractProxyModel
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

public void sort(int column,
                 SortOrder order)
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 the layoutChanged() signal.

Overrides:
sort in class WAbstractItemModel
See Also:
WAbstractItemModel.layoutAboutToBeChanged(), WAbstractItemModel.layoutChanged()