Class WStandardItem
public class WStandardItem
extends java.lang.Object
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
Constructors Constructor Description WStandardItem()
Creates an empty standard item.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.CharSequence text)
Creates an item with a text.WStandardItem(java.lang.String iconUri, java.lang.CharSequence text)
Creates an item with an icon and a text. -
Method Summary
Modifier and Type Method Description void
appendColumn(java.util.List<WStandardItem> items)
Add a single column of items.void
appendRow(WStandardItem item)
Appends a row containing one item.void
appendRow(java.util.List<WStandardItem> items)
Add a single row of items.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()
Deprecated.WLink
getLink()
Returns a link.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()
Deprecated.UsegetLink()
instead.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, WStandardItem item)
Inserts a row containing one item.void
insertRow(int row, java.util.List<WStandardItem> items)
Inserts a single row of items.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(ItemFlag flag, ItemFlag... flags)
Sets the flags.void
setFlags(java.util.EnumSet<ItemFlag> flags)
Sets the flags.void
setIcon(java.lang.String uri)
Sets the icon url.void
setInternalPath(java.lang.String internalpath)
Deprecated.UsesetLink()
instead.void
setLink(WLink link)
Sets a link.protected void
setModel(WStandardItemModel model)
Set the model for thisWStandardItem
and its children.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)
Deprecated.UsesetLink()
instead.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 Details
-
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 Details
-
setText
public void setText(java.lang.CharSequence text)Sets the text.The text is stored as
ItemDataRole.DisplayRole
data.The default text is empty ("").
- See Also:
getText()
,setData(Object d, int role)
-
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
ItemDataRole.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
ItemDataRole.StyleClassRole
data.The default style class is empty ("").
- See Also:
getStyleClass()
,setData(Object d, int role)
-
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
ItemDataRole.ToolTipRole
data.The default tool tip is empty ("").
- See Also:
getToolTip()
,setData(Object d, int role)
-
getToolTip
Returns the tool tip.- See Also:
setToolTip(CharSequence toolTip)
-
setLink
Sets a link.The link is stored as
ItemDataRole.LinkRole
data.- See Also:
setData(Object d, int role)
-
getLink
Returns a link.- See Also:
setLink(WLink link)
-
setInternalPath
public void setInternalPath(java.lang.String internalpath)Deprecated.UsesetLink()
instead.Sets a link to an internal path (deprecated).The internal path is stored as
ItemDataRole.LinkRole
data.. -
getInternalPath
public java.lang.String getInternalPath()Deprecated.UsegetLink()
instead.Returns the link to an internal path (deprecated).- See Also:
setInternalPath(String internalpath)
-
setUrl
public void setUrl(java.lang.String url)Deprecated.UsesetLink()
instead.Sets a link to a URL (deprecated).The URL is stored as
ItemDataRole.LinkRole
data. -
getUrl
public java.lang.String getUrl()Deprecated.UsegetLink()
instead.Returns the linked URL (deprecated).- See Also:
setUrl(String url)
-
setChecked
public void setChecked(boolean checked)Checks or unchecks the item.The value is stored as
ItemDataRole.CheckStateRole
data.By default, an item is not checked.
Note: the checkbox will only be enabled if the item is checkable (see
setCheckable()
).If the item is tri-state, you may consider using
setCheckState()
instead which supports also setting the thirdCheckState.PartiallyChecked
state. -
isChecked
public boolean isChecked()Returns whether the item is checked.- See Also:
setChecked(boolean checked)
-
setCheckState
Sets the check state.Like
setChecked()
, this sets the check state, but allows also setting theCheckState.PartiallyChecked
state when the item is tri-state checkable.The value is stored as
ItemDataRole.CheckStateRole
data. -
getCheckState
Returns the item's check state.- See Also:
setCheckState(CheckState state)
-
setFlags
Sets the flags.The default flag value is
ItemFlag.ItemIsSelectable
.- See Also:
ItemFlag
,getFlags()
,setCheckable(boolean checkable)
-
setFlags
Sets the flags. -
getFlags
Returns the flags.- See Also:
setFlags(EnumSet flags)
-
setCheckable
public void setCheckable(boolean checkable)Makes the item checkable.Adds
ItemFlag.ItemIsUserCheckable
to the item's flags. -
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
istrue
, the item is checkable with three states:CheckState.Unchecked
,CheckState.Checked
, andCheckState.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. -
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()
andgetColumnCount()
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, andgetColumnCount()
== 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
Add a single column of items.Appends a single column of
items
. If necessary, the row count is increased.Equivalent to:
insertColumn(columnCount(), items);
-
insertColumn
Inserts a single column of items.Inserts a single column of
items
at columncolumn
. If necessary, the row count is increased.- See Also:
insertRow(int row, List items)
-
appendRow
Add a single row of items.Appends a single row of
items
. If necessary, the column count is increased.Equivalent to:
insertRow(rowCount(), items);
-
insertRow
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
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
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);
-
appendRows
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);
-
insertRows
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
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 thegetColumnCount()
is increased.- See Also:
getChild(int row, int column)
-
setChild
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);
-
getChild
Returns a child item.Returns the child item at position (row,
column
). This may benull
if an item was not previously set, or if the position is out of bounds. -
getChild
Returns a child item.Returns
getChild(row, 0)
-
takeChild
Takes a child out of the item.Returns the child item at position (row,
column
), and removes it (by settingnull
instead). Ownership of the item is transferred to the caller. -
takeColumn
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
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);
-
removeColumns
public void removeColumns(int column, int count)Removes a number of columns.Removes
count
columns from the model (reducing the column count bycount
). -
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 bycount
). -
getIndex
Returns the model index for this item. -
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
Returns the parent item.Returns the parent 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
Returns a clone of this item.- Overrides:
clone
in classjava.lang.Object
- See Also:
WStandardItemModel.setItemPrototype(WStandardItem item)
-
sortChildren
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()
andWAbstractItemModel.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)
-
setModel
Set the model for thisWStandardItem
and its children.You may override this method if you want to change its behaviour.
-
getLink()
instead.