eu.webtoolkit.jwt
Class WAggregateProxyModel

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.WAggregateProxyModel

public class WAggregateProxyModel
extends WAbstractProxyModel

A proxy model for Wt's item models that provides column aggregation.

This proxy model does not store data itself, but presents data from a source model, and presents methods to organize columns using aggregation, through which a user may navigate (usually to obtain more detailed results related to a single aggregate quantity).

To use this proxy model, you should provide a source model using setSourceModel(), and define column ranges that can be aggregated using addAggregate().

This example would render like this:

A WTreeView using a WAggregateProxyModel

A WTreeView using a WAggregateProxyModel

Note: This model does not support dynamic changes to the column definition of the source model (i.e. insertions or deletions of source model columns).


Nested Class Summary
 
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WAbstractProxyModel
WAbstractProxyModel.BaseItem
 
Constructor Summary
WAggregateProxyModel()
          Constructor.
WAggregateProxyModel(WObject parent)
          Constructor.
 
Method Summary
 void addAggregate(int parentColumn, int firstColumn, int lastColumn)
          Adds a new column aggregation definition.
 void collapseColumn(int column)
          Collapses a column.
 void expandColumn(int column)
          Expands a column.
 int getColumnCount(WModelIndex parent)
          Returns the number of columns.
 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.
 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.
 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 setHeaderData(int section, Orientation orientation, java.lang.Object value, int role)
          Sets header data for a column or 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, getData, getFlags, getMimeType, getSourceModel, insertColumns, removeColumns, setData, shiftModelIndexes, toRawIndex
 
Methods inherited from class eu.webtoolkit.jwt.WAbstractItemModel
beginInsertColumns, beginInsertRows, beginRemoveColumns, beginRemoveRows, columnsAboutToBeInserted, columnsAboutToBeRemoved, columnsInserted, columnsRemoved, createIndex, dataChanged, endInsertColumns, endInsertRows, endRemoveColumns, endRemoveRows, getColumnCount, getData, getData, getData, getData, getHeaderData, getHeaderData, getHeaderFlags, getIndex, getItemData, 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, 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

WAggregateProxyModel

public WAggregateProxyModel(WObject parent)
Constructor.

Sets up the proxy without aggregation functionality.


WAggregateProxyModel

public WAggregateProxyModel()
Constructor.

Calls this((WObject)null)

Method Detail

addAggregate

public void addAggregate(int parentColumn,
                         int firstColumn,
                         int lastColumn)
Adds a new column aggregation definition.

The parentColumn is the column index in the source model that acts as an aggregate for columns firstColumn to lastColumn. parentColumn must border the range defined by firstColumn to lastColumn:

 parentColumn == firstColumn - 1 || parentColumn == lastColumn + 1 
   
 

Note that column parameters reference column indexes in the source model.

Aggregation definitions can be nested, but should be strictly hierarchical.

The aggregate column will initially be collapsed.

Only one aggregate can be defined per parentColumn.


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

expandColumn

public void expandColumn(int column)
Description copied from class: WAbstractItemModel
Expands a column.

Expands a column. This may only be called by a view when the HeaderFlag.ColumnIsCollapsed flag is set.

The default implementation does nothing.

Overrides:
expandColumn in class WAbstractItemModel
See Also:
WAggregateProxyModel

collapseColumn

public void collapseColumn(int column)
Description copied from class: WAbstractItemModel
Collapses a column.

Collapses a column. This may only be called by a view when the HeaderFlag.ColumnIsExpandedLeft or HeaderFlag.ColumnIsExpandedRight flag is set.

The default implementation does nothing.

Overrides:
collapseColumn in class WAbstractItemModel
See Also:
WAggregateProxyModel

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)

getHeaderFlags

public java.util.EnumSet<HeaderFlag> getHeaderFlags(int section,
                                                    Orientation orientation)
Description copied from class: WAbstractItemModel
Returns the flags for a header.

The default implementation returns no flags set.

Overrides:
getHeaderFlags in class WAbstractItemModel
See Also:
HeaderFlag

setHeaderData

public boolean setHeaderData(int section,
                             Orientation orientation,
                             java.lang.Object value,
                             int role)
Description copied from class: WAbstractItemModel
Sets header data for a column or row.

Returns true if the operation was successful.

Overrides:
setHeaderData in class WAbstractItemModel
See Also:
WAbstractItemModel.getHeaderData(int section, Orientation orientation, int role)

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)

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)

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()