Class WModelIndex

java.lang.Object
eu.webtoolkit.jwt.WModelIndex
All Implemented Interfaces:
java.lang.Comparable<WModelIndex>

public class WModelIndex
extends java.lang.Object
implements java.lang.Comparable<WModelIndex>
An index to a data item in a data model.

Indexes are used to indicate a particular item in a WAbstractItemModel. An index points to the item by identifying its row and column location within a parent model index. Indexes are immutable.

The null index identifies the parent of top level indexes. Thus, a model that specifies only a list or table of data (but no hierarchical data) would have as indexes only indexes that specify the null as parent.

Valid indexes are created by the model, within the protected WAbstractItemModel.createIndex(int, int, Object) method. In this way, models can define an internal pointer or suitable for identifying items in the model.

See Also:
WAbstractItemModel
  • Method Summary

    Modifier and Type Method Description
    int compareTo​(WModelIndex i2)
    Implements Comparable.compareTo(Object).
    WModelIndex decodeFromRawIndex()
    Decodes a raw index (after a layout change).
    static java.util.SortedSet<WModelIndex> decodeFromRawIndexes​(java.util.SortedSet<WModelIndex> encodedIndexes)
    Utility method to decode an entire set of raw indexes.
    void encodeAsRawIndex()
    Encodes to raw index (before a layout change).
    static void encodeAsRawIndexes​(java.util.SortedSet<WModelIndex> indexes)
    Utility method for converting an entire set of indexes to raw.
    boolean equals​(java.lang.Object other)
    Indicates whether some other object is "equal to" this one.
    WModelIndex getChild​(int row, int column)
    Returns a model index for a child item.
    int getColumn()
    Returns the column.
    java.lang.Object getData()
    Returns the data in the model associated at this index.
    java.lang.Object getData​(int role)
    Returns the data in the model associated at this index.
    java.util.EnumSet<ItemFlag> getFlags()
    Returns the item flags for the item at this index.
    int getInternalId()  
    java.lang.Object getInternalPointer()
    Returns the internal pointer.
    WAbstractItemModel getModel()
    Returns the model.
    WModelIndex getParent()
    Returns the parent index.
    int getRow()
    Returns the row.
    int hashCode()
    Returns a hash code value for the object.
    static boolean isAncestor​(WModelIndex i1, WModelIndex i2)
    Returns whether i2 is an ancestor of i1.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getParent

      public WModelIndex getParent()
      Returns the parent index.
      Returns:
      the parent index, which may be null if the index is a top-level index.
    • getRow

      public int getRow()
      Returns the row.
      Returns:
      the row.
    • getColumn

      public int getColumn()
      Returns the column.
      Returns:
      the column.
    • getInternalPointer

      public java.lang.Object getInternalPointer()
      Returns the internal pointer.

      The internal pointer is used by a specific model implementation to uniquely identify (in conjunction with getRow() and getColumn()) the item to which this index points.

      Usually the internal pointer therefore identifies the parent for hierarchical models, or is simply null for tabular models.

      Returns:
      the internal pointer.
    • getModel

      public WAbstractItemModel getModel()
      Returns the model.
      Returns:
      the model that created this index.
    • getData

      public java.lang.Object getData​(int role)
      Returns the data in the model associated at this index. This is a convenience method for WAbstractItemModel.getData(WModelIndex, int).
      Parameters:
      role - the ItemDataRole role.
      Returns:
      the data, or null if no data was available for this role.
    • getData

      public java.lang.Object getData()
      Returns the data in the model associated at this index. Calls getData(ItemDataRole.DisplayRole).
    • getChild

      public WModelIndex getChild​(int row, int column)
      Returns a model index for a child item.

      This is a convenience method for WAbstractItemModel.getIndex(int, int, WModelIndex).

    • equals

      public boolean equals​(java.lang.Object other)
      Indicates whether some other object is "equal to" this one.
      Overrides:
      equals in class java.lang.Object
    • hashCode

      public int hashCode()
      Returns a hash code value for the object.
      Overrides:
      hashCode in class java.lang.Object
    • compareTo

      public int compareTo​(WModelIndex i2)
      Implements Comparable.compareTo(Object).

      Creates a topological ordering of model indexes.

      The topological order follows the order in which the indexes would be displayed in a tree table view, from top to bottom followed by left to right.

      Specified by:
      compareTo in interface java.lang.Comparable<WModelIndex>
    • getFlags

      public java.util.EnumSet<ItemFlag> getFlags()
      Returns the item flags for the item at this index. This is a convenience method for WAbstractItemModel.getFlags(WModelIndex).
    • encodeAsRawIndex

      public void encodeAsRawIndex()
      Encodes to raw index (before a layout change). Use this method to encode an index for which you want to recover an index after the layout change to the same item (which may still be in the model, but at a different location). An index that has been encoded as a raw index cannot be used for anything but #decodeFromRawIndex() at a later point.
      See Also:
      WAbstractItemModel.toRawIndex(WModelIndex), WAbstractItemModel.layoutAboutToBeChanged(), decodeFromRawIndex()
    • decodeFromRawIndex

      public WModelIndex decodeFromRawIndex()
      Decodes a raw index (after a layout change). A raw index can be decoded, within the context of a model that has been re-layed out. This method returns a new index that points to the same item, or null if the underlying model did not support encoding to raw indexes, or, if the item to which the index previously pointed, is no longer part of the model.
      See Also:
      WAbstractItemModel.fromRawIndex(Object), WAbstractItemModel.layoutChanged(), encodeAsRawIndex()
    • encodeAsRawIndexes

      public static void encodeAsRawIndexes​(java.util.SortedSet<WModelIndex> indexes)
      Utility method for converting an entire set of indexes to raw.
      Parameters:
      indexes -
      See Also:
      encodeAsRawIndex()
    • decodeFromRawIndexes

      public static java.util.SortedSet<WModelIndex> decodeFromRawIndexes​(java.util.SortedSet<WModelIndex> encodedIndexes)
      Utility method to decode an entire set of raw indexes.
      See Also:
      decodeFromRawIndex()
    • isAncestor

      public static boolean isAncestor​(WModelIndex i1, WModelIndex i2)
      Returns whether i2 is an ancestor of i1.
    • getInternalId

      public int getInternalId()