Class WModelIndex

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

public class WModelIndex extends Object implements 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:
  • 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 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 Object getData(ItemDataRole 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 Object getData()
      Returns the data in the model associated at this index. Calls getData(ItemDataRole.Display).
    • 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(Object other)
      Indicates whether some other object is "equal to" this one.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Returns a hash code value for the object.
      Overrides:
      hashCode in class 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 Comparable<WModelIndex>
    • getFlags

      public 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:
    • 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:
    • encodeAsRawIndexes

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

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

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

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

      public int getInternalId()