Class 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 Detail

      • 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​(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 java.lang.Object getData()
        Returns the data in the model associated at this index. Calls getData(ItemDataRole.Display).
      • 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>
      • 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.Set<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()
      • decodeFromRawIndexes

        public static java.util.HashSet<WModelIndex> decodeFromRawIndexes​(java.util.HashSet<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()