5.1.3. Viewer sortersA viewer sorter (see Figure 5-5 for the ViewerSorter hierarchy) is used to sort the elements provided by the content provider (see Figure 5-1). If a viewer does not have a viewer sorter, the elements are shown in the order returned by the content provider. A viewer sorter is associated with a viewer using the setSorter() method. Figure 5-5. ViewerSorter hierarchy.
The default sorting algorithm uses a two-step process. First, it groups elements into categories (ranked 0 through n); and second, it sorts each category based on the text labels returned by the label provider. By default, all items are in the same category, so all the items are sorted relative to their text labels. Your application can override the default categorization as well as the default comparison routine to use some criteria other than the item's text label. Useful APIs defined by ViewerSorter include:
For an example of viewer sorters, see Section 5.1.6, ListViewer class, on page 192. |