eu.webtoolkit.jwt
Class WStringListModel

java.lang.Object
  extended by eu.webtoolkit.jwt.WObject
      extended by eu.webtoolkit.jwt.WAbstractItemModel
          extended by eu.webtoolkit.jwt.WAbstractListModel
              extended by eu.webtoolkit.jwt.WStringListModel

public class WStringListModel
extends WAbstractListModel

An model that manages a list of strings.

This model only manages a unidimensional list of strings. It is used as the default model for view classes that show a list.

The model only presents DisplayRole data of a single column of data, but otherwise provides support for all standard features of a model, including editing and addition and removal of data rows.

You can populate the model by passing a list of strings to its consructor, or by using the setStringList() method. You can set or retrieve data using the setData() and getData() methods, and add or remove data using the insertRows() and removeRows() methods.

See Also:
WComboBox, WSelectionBox

Constructor Summary
WStringListModel()
          Creates a new empty string list model.
WStringListModel(java.util.List<WString> strings)
          Creates a new string list model.
WStringListModel(java.util.List<WString> strings, WObject parent)
          Creates a new string list model.
WStringListModel(WObject parent)
          Creates a new empty string list model.
 
Method Summary
 void addString(java.lang.CharSequence string)
          Adds a string.
 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.
 int getRowCount(WModelIndex parent)
          Returns the number of rows.
 java.util.List<WString> getStringList()
          Returns the string list.
 boolean insertRows(int row, int count, WModelIndex parent)
          Inserts one or more rows.
 void insertString(int row, java.lang.CharSequence string)
          Inserts a string.
 boolean removeRows(int row, int count, WModelIndex parent)
          Removes rows.
 boolean setData(WModelIndex index, java.lang.Object value, int role)
          Sets data at the given model index.
 void setStringList(java.util.List<WString> strings)
          Sets a new string list.
 void sort(int column, SortOrder order)
          Sorts the model according to a particular column.
 
Methods inherited from class eu.webtoolkit.jwt.WAbstractListModel
getColumnCount, getIndex, getParent
 
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, getData, getData, getData, getData, getHeaderData, getHeaderData, getHeaderData, getHeaderFlags, getHeaderFlags, getIndex, getItemData, getMimeType, getRowCount, hasChildren, hasIndex, hasIndex, headerDataChanged, insertColumn, insertColumn, insertColumns, insertColumns, insertRow, insertRow, insertRows, layoutAboutToBeChanged, layoutChanged, match, modelReset, removeColumn, removeColumn, removeColumns, removeColumns, removeRow, removeRow, removeRows, reset, rowsAboutToBeInserted, rowsAboutToBeRemoved, rowsInserted, rowsRemoved, setData, setData, setData, setData, setHeaderData, setHeaderData, setHeaderData, setItemData, 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

WStringListModel

public WStringListModel(WObject parent)
Creates a new empty string list model.


WStringListModel

public WStringListModel()
Creates a new empty string list model.

Calls this((WObject)null)


WStringListModel

public WStringListModel(java.util.List<WString> strings,
                        WObject parent)
Creates a new string list model.


WStringListModel

public WStringListModel(java.util.List<WString> strings)
Creates a new string list model.

Calls this(strings, (WObject)null)

Method Detail

setStringList

public void setStringList(java.util.List<WString> strings)
Sets a new string list.

Replaces the current string list with a new list.

See Also:
WAbstractItemModel.dataChanged(), addString(CharSequence string)

insertString

public void insertString(int row,
                         java.lang.CharSequence string)
Inserts a string.

See Also:
setStringList(List strings)

addString

public void addString(java.lang.CharSequence string)
Adds a string.

See Also:
setStringList(List strings)

getStringList

public java.util.List<WString> getStringList()
Returns the string list.

See Also:
setStringList(List strings)

getFlags

public java.util.EnumSet<ItemFlag> getFlags(WModelIndex index)
Returns the flags for an item.

This method is reimplemented to return ItemIsSelectable | ItemIsEditable.

Overrides:
getFlags in class WAbstractItemModel
See Also:
ItemFlag

setData

public boolean setData(WModelIndex index,
                       java.lang.Object value,
                       int role)
Description copied from class: WAbstractItemModel
Sets data at the given model index.

Returns true if the operation was successful.

The default implementation returns false.

The model implementation must emit the dataChanged() signal after data was changed.

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

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

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

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)

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

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