eu.webtoolkit.jwt
Class WItemModel<Item>

java.lang.Object
  extended by eu.webtoolkit.jwt.WObject
      extended by eu.webtoolkit.jwt.WAbstractItemModel
          extended by eu.webtoolkit.jwt.WItemModel<Item>

public abstract class WItemModel<Item>
extends WAbstractItemModel

An item model for use with Wt's view classes.

The item model specializes WAbstractItemModel for hierarchical data (i.e. a model with a tree-like data structure and one or more columns).

It cannot be used directly but must be subclassed. Subclassed models must at least implement getChildItems() to return a list of items for a parent, getData() to return data and getColumnCount() to return the number of columns. When providing a value for fetchSize, the model will attempt to fetch a node's children in blocks minimally the size of the provided value, if this value is not provided or the value is -1, all the node's children are fetched at once.


Constructor Summary
WItemModel()
          Creates a new WItemModel.
WItemModel(int fetchSize)
          Creates a new WItemModel.
 
Method Summary
 int getChildCount(Item item)
          Returns the number of children for item.
abstract  java.util.List<Item> getChildItems(Item parent, int from, int count)
          Returns the list of child items for a parent item.
 WModelIndex getIndex(int row, int column, WModelIndex parent)
          Returns the child index for the given row and column.
 Item getItem(WModelIndex index)
          Returns the Item for the WModelIndex index.
 WModelIndex getParent(WModelIndex index)
          Returns the parent for a model index.
 int getRowCount(WModelIndex index)
          Returns the number of rows.
 
Methods inherited from class eu.webtoolkit.jwt.WAbstractItemModel
beginInsertColumns, beginInsertRows, beginRemoveColumns, beginRemoveRows, collapseColumn, columnsAboutToBeInserted, columnsAboutToBeRemoved, columnsInserted, columnsRemoved, createIndex, dataChanged, dropEvent, endInsertColumns, endInsertRows, endRemoveColumns, endRemoveRows, expandColumn, fromRawIndex, getAcceptDropMimeTypes, getColumnCount, getColumnCount, getData, getData, getData, getData, getData, getFlags, getHeaderData, getHeaderData, getHeaderData, getHeaderFlags, getHeaderFlags, getIndex, getItemData, getMimeType, getRowCount, hasChildren, hasIndex, hasIndex, headerDataChanged, insertColumn, insertColumn, insertColumns, insertColumns, insertRow, insertRow, insertRows, insertRows, layoutAboutToBeChanged, layoutChanged, match, modelReset, removeColumn, removeColumn, removeColumns, removeColumns, removeRow, removeRow, removeRows, removeRows, reset, rowsAboutToBeInserted, rowsAboutToBeRemoved, rowsInserted, rowsRemoved, setData, setData, setData, setData, setData, setHeaderData, setHeaderData, setHeaderData, setItemData, sort, sort, toRawIndex
 
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

WItemModel

public WItemModel()
Creates a new WItemModel. Calls this(-1)


WItemModel

public WItemModel(int fetchSize)
Creates a new WItemModel. The model will attempt to fetch a node's children in blocks minimally the size of the provided value, if this value is -1, all the node's children are fetched at once.

Method Detail

getRowCount

public int getRowCount(WModelIndex index)
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)

getChildCount

public int getChildCount(Item item)
Returns the number of children for item.

This returns the number of children for item. When the item is null, this method should return the number of top level items. The default implementation returns the size of the list returned, by invoking getChildItems(item, 0, -1). When providing a fetchSize to the constructor, you need to override this method with a proper implementation.


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)

getItem

public Item getItem(WModelIndex index)
Returns the Item for the WModelIndex index.

This returns the Item for the WModelIndex index.


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)

getChildItems

public abstract java.util.List<Item> getChildItems(Item parent,
                                                   int from,
                                                   int count)
Returns the list of child items for a parent item.

This returns the list of child items for a parent item. When the parent item is null, this method should return all top level items. When you provided a fetchSize value, this method should only return a slice specified by from and count of the total list of items, if not count will be -1 and all items should be returned at once. When the item has no children, you should return an empty List.