eu.webtoolkit.jwt
Class WStandardItem

java.lang.Object
  extended by eu.webtoolkit.jwt.WStandardItem

public class WStandardItem
extends java.lang.Object

An item in a WStandardItemModel.

The item provides access to various data properties: text, icon, CSS style class, tool tip, and check state, and data flags (setFlags() and setCheckable()).

An item may contain a table of children items: the initial geometry may be specified in the constructor, or using the methods setRowCount() and setModelCount(). Unspecified items are 0. You can set or inspect children items using the setChild() and getChild() methods.

It is possible to reimplement this class and specialize the methods for data acess (setData() and getData()), or provide custom sorting functionality by reimplementing

compare().


Constructor Summary
WStandardItem()
          Creates an empty standard item.
WStandardItem(java.lang.CharSequence text)
          Creates an item with a text.
WStandardItem(int rows)
          Creates an item with an initial geometry.
WStandardItem(int rows, int columns)
          Creates an item with an initial geometry.
WStandardItem(java.lang.String iconUri, java.lang.CharSequence text)
          Creates an item with an icon and a text.
 
Method Summary
 void appendColumn(java.util.List<WStandardItem> items)
          Add a single column of items.
 void appendRow(java.util.List<WStandardItem> items)
          Add a single row of items.
 void appendRow(WStandardItem item)
          Appends a row containing one item.
 void appendRows(java.util.List<WStandardItem> items)
          Appends multiple rows containing one item.
 WStandardItem clone()
          Returns a clone of this item.
 CheckState getCheckState()
          Returns the item's check state.
 WStandardItem getChild(int row)
          Returns a child item.
 WStandardItem getChild(int row, int column)
          Returns a child item.
 int getColumn()
          Returns the column index.
 int getColumnCount()
          Returns the column count.
 java.lang.Object getData()
          Returns item data.
 java.lang.Object getData(int role)
          Returns item data.
 java.util.EnumSet<ItemFlag> getFlags()
          Returns the flags.
 java.lang.String getIcon()
          Returns the icon url.
 WModelIndex getIndex()
          Returns the model index for this item.
 java.lang.String getInternalPath()
          Returns the anchor to an internal path.
 WStandardItemModel getModel()
          Returns the model.
 WStandardItem getParent()
          Returns the parent item.
 int getRow()
          Returns the row index.
 int getRowCount()
          Returns the row count.
 WString getStyleClass()
          Returns the item style class.
 WString getText()
          Returns the text.
 WString getToolTip()
          Returns the tool tip.
 java.lang.String getUrl()
          Returns the url referenced by this item.
 boolean hasChildren()
          Returns whether the item has any children.
 void insertColumn(int column, java.util.List<WStandardItem> items)
          Inserts a single column of items.
 void insertColumns(int column, int count)
          Inserts a number of empty columns.
 void insertRow(int row, java.util.List<WStandardItem> items)
          Inserts a single row of items.
 void insertRow(int row, WStandardItem item)
          Inserts a row containing one item.
 void insertRows(int row, int count)
          Inserts a number of empty rows.
 void insertRows(int row, java.util.List<WStandardItem> items)
          Inserts multiple rows containing one item.
 boolean isCheckable()
          Returns whether the item is checkable.
 boolean isChecked()
          Returns whether the item is checked.
 boolean isTristate()
          Returns whether the item is tri-state checkable.
 void removeColumn(int column)
          Removes a single column.
 void removeColumns(int column, int count)
          Removes a number of columns.
 void removeRow(int row)
          Removes a single row.
 void removeRows(int row, int count)
          Removes a number of rows.
 void setCheckable(boolean checkable)
          Makes the item checkable.
 void setChecked(boolean checked)
          Checks or unchecks the item.
 void setCheckState(CheckState state)
          Sets the check state.
 void setChild(int row, int column, WStandardItem item)
          Sets a child item.
 void setChild(int row, WStandardItem item)
          Sets a child item.
 void setColumnCount(int columns)
          Sets the column count.
 void setData(java.lang.Object d)
          Sets item data.
 void setData(java.lang.Object d, int role)
          Sets item data.
 void setFlags(java.util.EnumSet<ItemFlag> flags)
          Sets the flags.
 void setFlags(ItemFlag flag, ItemFlag... flags)
          Sets the flags.
 void setIcon(java.lang.String uri)
          Sets the icon url.
 void setInternalPath(java.lang.String internalpath)
          Sets an anchor to an internal path.
 void setRowCount(int rows)
          Sets the row count.
 void setStyleClass(java.lang.CharSequence styleClass)
          Sets the CSS style class.
 void setText(java.lang.CharSequence text)
          Sets the text.
 void setToolTip(java.lang.CharSequence toolTip)
          Sets a tool tip.
 void setTristate(boolean tristate)
          Makes the item tri-state checkable.
 void setUrl(java.lang.String url)
          Sets an anchor to an external URL.
 void sortChildren(int column, SortOrder order)
          Sorts the children according to a given column and sort order.
 WStandardItem takeChild(int row, int column)
          Takes a child out of the item.
 java.util.List<WStandardItem> takeColumn(int column)
          Takes a column of children out of the item.
 java.util.List<WStandardItem> takeRow(int row)
          Takes a row of children out of the item.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WStandardItem

public WStandardItem()
Creates an empty standard item.


WStandardItem

public WStandardItem(java.lang.CharSequence text)
Creates an item with a text.

See Also:
setText(CharSequence text)

WStandardItem

public WStandardItem(java.lang.String iconUri,
                     java.lang.CharSequence text)
Creates an item with an icon and a text.

See Also:
setText(CharSequence text), setIcon(String uri)

WStandardItem

public WStandardItem(int rows,
                     int columns)
Creates an item with an initial geometry.

See Also:
setRowCount(int rows), setColumnCount(int columns)

WStandardItem

public WStandardItem(int rows)
Creates an item with an initial geometry.

Calls this(rows, 1)

Method Detail

setText

public void setText(java.lang.CharSequence text)
Sets the text.

The text is stored as DisplayRole data.

The default text is empty ("").

See Also:
getText(), setData(Object d, int role)

getText

public WString getText()
Returns the text.

See Also:
setText(CharSequence text)

setIcon

public void setIcon(java.lang.String uri)
Sets the icon url.

The icon is stored as DecorationRole data.

The default icon url is empty ("").

See Also:
getIcon(), setData(Object d, int role)

getIcon

public java.lang.String getIcon()
Returns the icon url.

See Also:
setIcon(String uri)

setStyleClass

public void setStyleClass(java.lang.CharSequence styleClass)
Sets the CSS style class.

The style class is stored as StyleClassRole data.

The default style class is empty ("").

See Also:
getStyleClass(), setData(Object d, int role)

getStyleClass

public WString getStyleClass()
Returns the item style class.

See Also:
setStyleClass(CharSequence styleClass)

setToolTip

public void setToolTip(java.lang.CharSequence toolTip)
Sets a tool tip.

The tool tip is stored as ToolTipRole data.

The default tool tip is empty ("").

See Also:
getToolTip(), setData(Object d, int role)

getToolTip

public WString getToolTip()
Returns the tool tip.

See Also:
setToolTip(CharSequence toolTip)

setInternalPath

public void setInternalPath(java.lang.String internalpath)
Sets an anchor to an internal path.

The internal path is stored as InternalPathRole data.

See Also:
getInternalPath(), setData(Object d, int role)

getInternalPath

public java.lang.String getInternalPath()
Returns the anchor to an internal path.

See Also:
setInternalPath(String internalpath), setData(Object d, int role)

setUrl

public void setUrl(java.lang.String url)
Sets an anchor to an external URL.

The anchor Url is stored as UrlRole data.

See Also:
setInternalPath(String internalpath), setData(Object d, int role)

getUrl

public java.lang.String getUrl()
Returns the url referenced by this item.

See Also:
setUrl(String url), setData(Object d, int role)

setChecked

public void setChecked(boolean checked)
Checks or unchecks the item.

The value is stored as CheckStateRole data.

By default, an item is not checked.

Note: this requires that the item is checkable (see setCheckable()).

If the item is tri-state, you may consider using setCheckState() instead which supports also setting the third CheckState.PartiallyChecked state.

See Also:
setCheckable(boolean checkable), setCheckState(CheckState state)

isChecked

public boolean isChecked()
Returns whether the item is checked.

See Also:
setChecked(boolean checked)

setCheckState

public void setCheckState(CheckState state)
Sets the check state.

Like setChecked(), this sets the check state, but allows also setting the CheckState.PartiallyChecked state when the item is tri-state checkable.

The value is stored as CheckStateRole data.

See Also:
setCheckable(boolean checkable), setData(Object d, int role)

getCheckState

public CheckState getCheckState()
Returns the item's check state.

See Also:
setCheckState(CheckState state)

setFlags

public void setFlags(java.util.EnumSet<ItemFlag> flags)
Sets the flags.

The default flag value is ItemIsSelectable.

See Also:
ItemFlag, getFlags(), setCheckable(boolean checkable)

setFlags

public final void setFlags(ItemFlag flag,
                           ItemFlag... flags)
Sets the flags.

Calls setFlags(EnumSet.of(flag, flags))


getFlags

public java.util.EnumSet<ItemFlag> getFlags()
Returns the flags.

See Also:
setFlags(EnumSet flags)

setCheckable

public void setCheckable(boolean checkable)
Makes the item checkable.

Adds ItemIsUserCheckable to the item's flags.

See Also:
setFlags(EnumSet flags), setChecked(boolean checked)

isCheckable

public boolean isCheckable()
Returns whether the item is checkable.

See Also:
setCheckable(boolean checkable)

setTristate

public void setTristate(boolean tristate)
Makes the item tri-state checkable.

When tristate is true, the item is checkable with three states: CheckState.Unchecked, CheckState.Checked, and CheckState.PartiallyChecked.

This requires that the item is also checkable (see setCheckable())

See Also:
setCheckable(boolean checkable)

isTristate

public boolean isTristate()
Returns whether the item is tri-state checkable.

See Also:
setTristate(boolean tristate)

setData

public void setData(java.lang.Object d,
                    int role)
Sets item data.

Sets item data for the given role.

See Also:
getData(int role)

setData

public final void setData(java.lang.Object d)
Sets item data.

Calls setData(d, ItemDataRole.UserRole)


getData

public java.lang.Object getData(int role)
Returns item data.

Returns item data for the given role.

See Also:
getData(int role)

getData

public final java.lang.Object getData()
Returns item data.

Returns getData(ItemDataRole.UserRole)


hasChildren

public boolean hasChildren()
Returns whether the item has any children.

This is a convenience method and checks whether getRowCount() and getColumnCount() differ both from 0.

See Also:
getRowCount(), getColumnCount()

setRowCount

public void setRowCount(int rows)
Sets the row count.

If rows is bigger than the current row count, empty rows are appended.

If rows is smaller than the current row count, rows are deleted at the end.

Note: If rows > 0, and getColumnCount() == 0, columnCount is first increased to 1 using setColumnCount(1).

See Also:
setColumnCount(int columns), getRowCount()

getRowCount

public int getRowCount()
Returns the row count.

See Also:
setRowCount(int rows)

setColumnCount

public void setColumnCount(int columns)
Sets the column count.

If columns is bigger than the current column count, empty columns are appended.

If columns is smaller than the current column count, columns are deleted at the end.

See Also:
setRowCount(int rows), getColumnCount()

getColumnCount

public int getColumnCount()
Returns the column count.

See Also:
setRowCount(int rows)

appendColumn

public void appendColumn(java.util.List<WStandardItem> items)
Add a single column of items.

Appends a single column of items. If necessary, the row count is increased.

Equivalent to:

 insertColumn(columnCount(), items);
 

See Also:
insertColumn(int column, List items), appendRow(List items)

insertColumn

public void insertColumn(int column,
                         java.util.List<WStandardItem> items)
Inserts a single column of items.

Inserts a single column of items at column column. If necessary, the row count is increased.

See Also:
insertRow(int row, List items)

appendRow

public void appendRow(java.util.List<WStandardItem> items)
Add a single row of items.

Appends a single row of items. If necessary, the column count is increased.

Equivalent to:

 insertRow(rowCount(), items);
 

See Also:
insertRow(int row, List items), appendColumn(List items)

insertRow

public void insertRow(int row,
                      java.util.List<WStandardItem> items)
Inserts a single row of items.

Inserts a single row of items at row row. If necessary, the column count is increased.

See Also:
insertColumn(int column, List items)

insertColumns

public void insertColumns(int column,
                          int count)
Inserts a number of empty columns.

Inserts count empty columns at position column.

See Also:
insertRows(int row, int count)

insertRows

public void insertRows(int row,
                       int count)
Inserts a number of empty rows.

Inserts count empty rows at position row.

See Also:
insertColumns(int column, int count)

appendRow

public void appendRow(WStandardItem item)
Appends a row containing one item.

This is a convenience method for nodes with a single column (for example for tree nodes). This adds a row with a single item, and is equivalent to:

 insertRow(rowCount(), item);
 

See Also:
insertRow(int row, WStandardItem item)

insertRow

public void insertRow(int row,
                      WStandardItem item)
Inserts a row containing one item.

This is a convenience method for nodes with a single column (for example for tree nodes). This inserts a row with a single item, and is equivalent to:

 List<WStandardItem> r;
 r.add(item);
 insertRow(row, r);
 

See Also:
insertRow(int row, List items)

appendRows

public void appendRows(java.util.List<WStandardItem> items)
Appends multiple rows containing one item.

This is a convenience method for nodes with a single column (for example for tree nodes). This adds a number of rows, each containing a single item, and is equivalent to:

 insertRows(rowCount(), items);
 

See Also:
insertRows(int row, List items)

insertRows

public void insertRows(int row,
                       java.util.List<WStandardItem> items)
Inserts multiple rows containing one item.

This is a convenience method for nodes with a single column (for example for tree nodes). This inserts a number of rows at row row, each containing a single item, and is equivalent to:

See Also:
insertRow(int row, WStandardItem item)

setChild

public void setChild(int row,
                     int column,
                     WStandardItem item)
Sets a child item.

Sets a child item item at position (row, column). If an item was previously set, it is deleted first.

If necessary, the getRowCount() and/or the getColumnCount() is increased.

See Also:
getChild(int row, int column)

setChild

public void setChild(int row,
                     WStandardItem item)
Sets a child item.

This is a convenience method for nodes with a single column (e.g. tree nodes), and is equivalent to:

 setChild(row, 0, item);
 

See Also:
setChild(int row, int column, WStandardItem item)

getChild

public WStandardItem getChild(int row,
                              int column)
Returns a child item.

Returns the child item at position (row, column). This may be null if an item was not previously set, or if the position is out of bounds.

See Also:
setChild(int row, int column, WStandardItem item)

getChild

public final WStandardItem getChild(int row)
Returns a child item.

Returns getChild(row, 0)


takeChild

public WStandardItem takeChild(int row,
                               int column)
Takes a child out of the item.

Returns the child item at position (row, column), and removes it (by setting null instead). Ownership of the item is transferred to the caller.

See Also:
getChild(int row, int column), setChild(int row, int column, WStandardItem item)

takeColumn

public java.util.List<WStandardItem> takeColumn(int column)
Takes a column of children out of the item.

Returns the column column, and removes the column from the model (reducing the column count by one). Ownership of all items is transferred to the caller.

See Also:
takeRow(int row), removeColumn(int column)

takeRow

public java.util.List<WStandardItem> takeRow(int row)
Takes a row of children out of the item.

Returns the row row, and removes the row from the model (reducing the row count by one). Ownership of all items is transferred to the caller.

See Also:
takeColumn(int column), removeRow(int row)

removeColumn

public void removeColumn(int column)
Removes a single column.

Removes the column column from the model (reducing the column count by one). Is equivalent to:

 removeColumns(column, 1);
 

See Also:
removeColumns(int column, int count), takeColumn(int column)

removeColumns

public void removeColumns(int column,
                          int count)
Removes a number of columns.

Removes count columns from the model (reducing the column count by count).

See Also:
removeColumn(int column), removeRows(int row, int count)

removeRow

public void removeRow(int row)
Removes a single row.

Removes the row row from the model (reducing the row count by one). Is equivalent to:

 removeRows(row, 1);
 

See Also:
removeRows(int row, int count), takeRow(int row)

removeRows

public void removeRows(int row,
                       int count)
Removes a number of rows.

Removes count rows from the model (reducing the row count by count).

See Also:
removeRow(int row), removeColumns(int column, int count)

getIndex

public WModelIndex getIndex()
Returns the model index for this item.

See Also:
WStandardItemModel.indexFromItem(WStandardItem item)

getModel

public WStandardItemModel getModel()
Returns the model.

This is the model that this item belongs to, or 0 if the item is not associated with a model.


getParent

public WStandardItem getParent()
Returns the parent item.

Returns the parent item.

See Also:
setChild(int row, int column, WStandardItem item)

getRow

public int getRow()
Returns the row index.

Returns the row index of this item in the parent.

See Also:
getColumn()

getColumn

public int getColumn()
Returns the column index.

Returns the column index of this item in the parent.

See Also:
getColumn()

clone

public WStandardItem clone()
Returns a clone of this item.

Overrides:
clone in class java.lang.Object
See Also:
WStandardItemModel.setItemPrototype(WStandardItem item)

sortChildren

public void sortChildren(int column,
                         SortOrder order)
Sorts the children according to a given column and sort order.

Children of this item, and all children items are sorted recursively. Existing model indexes will be invalidated by the operation (will point to other items).

The WAbstractItemModel#layoutAboutToBeChanged() and WAbstractItemModel#layoutChanged() signals are emitted before and after the operation so that you get a chance to invalidate or update model indexes.

See Also:
compare(WStandardItem other), WStandardItemModel.setSortRole(int role)