Interface Sortable<T>

All Known Subinterfaces:
GroupsSortableModel<D>
All Known Implementing Classes:
DefaultTreeModel, GroupsModelArray, ListModelArray, ListModelList, ListModelMap, ListModelSet, SimpleGroupsModel, SimpleListModel

public interface Sortable<T>
Indicate a data model that supports sorting. It is typically used with ListModel

If the implementation also implements Selectable interface, it is up to the particular implementation to decide what the selections remains in order after sorted.

Since:
6.0.0
Author:
tomyeh
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the sort direction of this model for the given comparator.
    default void
    Sort the data model by default or assigned comparator.
    void
    sort(Comparator<T> cmpr, boolean ascending)
    It called when the associated component (such as Listbox) has to sort the content.
  • Method Details

    • sort

      void sort(Comparator<T> cmpr, boolean ascending)
      It called when the associated component (such as Listbox) has to sort the content.

      After sorting, this model shall notify the component abort the result. For example, if this interface is used with ListModel, then it might do the following to notify all registered listeners ListDataListener (registered by ListModel.addListDataListener(org.zkoss.zul.event.ListDataListener)) to update the content:

      new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, -1, -1)

      The comparator assigned to, say, Listheader.setSortAscending(java.util.Comparator) is passed to method as the cmpr argument. Thus, developers could use it as a tag to know which column or what kind of order to sort. Notice that the comparator is capable to sort under the order specified in the ascending parameter. In other words, you could ignore the ascending parameter (which is used only for providing additional information)

      Parameters:
      cmpr - the comparator assigned to Listheader.setSortAscending(java.util.Comparator) and other relative methods. If developers didn't assign any one, the default comparator is used. Notice that it is capable to sort the data in the correct order, you could ignore the ascending parameter.
      ascending - whether to sort in the ascending order (or in the descending order, if false). Notice that it is used only to provide additional information. To sort the data correctly, you could count on the cmpr parameter only.
    • sort

      default void sort()
      Sort the data model by default or assigned comparator. Notice that the default implementation does nothing, the model which implements Sortable need to implement this method.
      Since:
      9.6.0
      See Also:
    • getSortDirection

      String getSortDirection(Comparator<T> cmpr)
      Returns the sort direction of this model for the given comparator. It must be one of "ascending", "descending" and "natural".

      Default: "natural".

      Since:
      6.0.0