Class WAbstractProxyModel
- Direct Known Subclasses:
WAggregateProxyModel
,WBatchEditProxyModel
,WIdentityProxyModel
,WReadOnlyProxyModel
,WSortFilterProxyModel
public abstract class WAbstractProxyModel extends WAbstractItemModel
A proxy model does not store data, but presents data from a source model in another way. It may provide filtering, sorting, or other computed changes to the source model. A proxy model may be a fully functional model, that also allows modification of the underlying model.
This abstract proxy model may be used as a starting point for implementing a custom proxy
model, when WSortFilterProxyModel
is not adequate. It implements data access and
manipulation using the a virtual mapping method (mapToSource()
) to access and manipulate
the underlying getSourceModel()
.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
WAbstractProxyModel.BaseItem
A base class for an item modeling a source index parent.Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData
-
Constructor Summary
Constructors Constructor Description WAbstractProxyModel()
Constructor.WAbstractProxyModel(WObject parent)
Constructor. -
Method Summary
Modifier and Type Method Description protected WModelIndex
createSourceIndex(int row, int column, java.lang.Object ptr)
Create a source model index.void
dropEvent(WDropEvent e, DropAction action, int row, int column, WModelIndex parent)
Handles a drop event.protected void
endShiftModelIndexes(WModelIndex sourceParent, int start, int count, java.util.SortedMap<WModelIndex,WAbstractProxyModel.BaseItem> items)
WModelIndex
fromRawIndex(java.lang.Object rawIndex)
Converts a raw pointer to a model index.java.util.List<java.lang.String>
getAcceptDropMimeTypes()
Returns a list of mime-types that could be accepted for a drop event.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.java.util.EnumSet<HeaderFlag>
getHeaderFlags(int section, Orientation orientation)
Returns the flags for a header.java.lang.String
getMimeType()
Returns a mime-type for dragging a set of indexes.WAbstractItemModel
getSourceModel()
Returns the source model.boolean
insertColumns(int column, int count, WModelIndex parent)
Inserts one or more columns.abstract WModelIndex
mapFromSource(WModelIndex sourceIndex)
Maps a source model index to the proxy model.abstract WModelIndex
mapToSource(WModelIndex proxyIndex)
Maps a proxy model index to the source model.boolean
removeColumns(int column, int count, WModelIndex parent)
Removes columns.boolean
setData(WModelIndex index, java.lang.Object value, int role)
Sets the data at the given model index.boolean
setItemData(WModelIndex index, java.util.SortedMap<java.lang.Integer,java.lang.Object> values)
Sets the data at the given model index.void
setSourceModel(WAbstractItemModel sourceModel)
Sets the source model.protected void
startShiftModelIndexes(WModelIndex sourceParent, int start, int count, java.util.SortedMap<WModelIndex,WAbstractProxyModel.BaseItem> items)
Utility methods to shift items in an item map.java.lang.Object
toRawIndex(WModelIndex index)
Converts a model index to a raw pointer that remains valid while the model's layout is changed.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, getColumnCount, getData, getData, getData, getData, getHeaderData, getHeaderData, getHeaderFlags, getIndex, getIndex, getItemData, getParent, getRowCount, getRowCount, hasChildren, hasIndex, hasIndex, headerDataChanged, insertColumn, insertColumn, insertColumns, insertRow, insertRow, insertRows, insertRows, layoutAboutToBeChanged, layoutChanged, match, modelReset, removeColumn, removeColumn, removeColumns, removeRow, removeRow, removeRows, removeRows, reset, rowsAboutToBeInserted, rowsAboutToBeRemoved, rowsInserted, rowsRemoved, setData, setData, setData, setData, setHeaderData, setHeaderData, setHeaderData, sort, 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
-
WAbstractProxyModel
Constructor. -
WAbstractProxyModel
public WAbstractProxyModel()Constructor.Calls
this((WObject)null)
-
-
Method Details
-
mapFromSource
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()
.- See Also:
mapToSource(WModelIndex proxyIndex)
-
mapToSource
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
.- See Also:
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.
Note that the source model's signals are not forwarded to the proxy model by default, but some specializations, like
WBatchEditProxyModel
andWSortFilterProxyModel
do. If you want to reimplementgetData()
with no changes to row or column indices, consider the use ofWIdentityProxyModel
. -
getSourceModel
Returns the source model. -
getData
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. -
getHeaderData
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()
. -
setData
Sets the data at the given model index.The default proxy implementation calls
getSourceModel()
.setData(mapToSource(index), value, role)- Overrides:
setData
in classWAbstractItemModel
- See Also:
WAbstractItemModel.getData(WModelIndex index, int role)
-
setItemData
public boolean setItemData(WModelIndex index, java.util.SortedMap<java.lang.Integer,java.lang.Object> values)Sets the data at the given model index.The default proxy implementation calls
getSourceModel()
.setData(mapToSource(index), values)- Overrides:
setItemData
in classWAbstractItemModel
- See Also:
WAbstractItemModel.setData(WModelIndex index, Object value, int role)
-
getFlags
Returns the flags for an item.The default proxy implementation calls
getSourceModel()
.flags(mapToSource(index))- Overrides:
getFlags
in classWAbstractItemModel
- See Also:
ItemFlag
-
getHeaderFlags
Returns the flags for a header.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()
.getHeaderFlags()
depends on how theWModelIndex
is transformed withmapToSource()
.- Overrides:
getHeaderFlags
in classWAbstractItemModel
- See Also:
HeaderFlag
-
insertColumns
Inserts one or more columns.The default proxy implementation calls
getSourceModel()
.insertColumns(column, count, parent)- Overrides:
insertColumns
in classWAbstractItemModel
- 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
Removes columns.The default proxy implementation calls
getSourceModel()
.removeColumns(column, count, parent)- Overrides:
removeColumns
in classWAbstractItemModel
- 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()
-
getMimeType
public java.lang.String getMimeType()Returns a mime-type for dragging a set of indexes.The default proxy implementation calls
getSourceModel()
.getMimeType()
- Overrides:
getMimeType
in classWAbstractItemModel
- See Also:
WAbstractItemModel.getAcceptDropMimeTypes()
-
getAcceptDropMimeTypes
public java.util.List<java.lang.String> getAcceptDropMimeTypes()Returns a list of mime-types that could be accepted for a drop event.The default proxy implementation calls
getSourceModel()
.getAcceptDropMimeTypes()
- Overrides:
getAcceptDropMimeTypes
in classWAbstractItemModel
- See Also:
WAbstractItemModel.getMimeType()
-
dropEvent
Handles a drop event.The default proxy implementation maps the given row and parent to the row and parent in the source model, and forwards the dropEvent call to the source model.
- Overrides:
dropEvent
in classWAbstractItemModel
- See Also:
WAbstractItemModel.getMimeType()
,WItemSelectionModel
-
toRawIndex
Converts a model index to a raw pointer that remains valid while the model's layout is changed.The default proxy implementation calls
getSourceModel()
.toRawIndex(mapToSource(index)) -
fromRawIndex
Converts a raw pointer to a model index.The default proxy implementation calls mapFromSource(
getSourceModel()
.fromRawIndex(rawIndex))- Overrides:
fromRawIndex
in classWAbstractItemModel
- See Also:
WAbstractItemModel.toRawIndex(WModelIndex index)
-
createSourceIndex
Create a source model index.This is a utility function that allows you to create indexes in the source model. In this way, you can reuse the internal pointers of the source model in proxy model indexes, and convert a proxy model index back to the source model index using this method.
-
startShiftModelIndexes
protected void startShiftModelIndexes(WModelIndex sourceParent, int start, int count, java.util.SortedMap<WModelIndex,WAbstractProxyModel.BaseItem> items)Utility methods to shift items in an item map.You can use this method to adjust an item map after the source model has inserted or removed rows. When removing rows (count < 0), items may possibly be removed and deleted.
-
endShiftModelIndexes
protected void endShiftModelIndexes(WModelIndex sourceParent, int start, int count, java.util.SortedMap<WModelIndex,WAbstractProxyModel.BaseItem> items)
-