Class ViewerComparator
- Direct Known Subclasses:
- ContributionComparator,- ResourceComparator,- TableComparator,- ViewerSorter,- WorkbenchViewerComparator
StructuredViewer to
 reorder the elements provided by its content provider.
 
 The default compare method compares elements using two steps.
 The first step uses the values returned from category.
 By default, all elements are in the same category.
 The second level uses strings obtained from the content viewer's label
 provider via ILabelProvider.getText().
 The strings are compared using a comparator from Policy.getComparator()
 which by default does a case sensitive string comparison.
 
 Subclasses may implement the isSorterProperty method;
 they may reimplement the category method to provide
 categorization; and they may override the compare methods
 to provide a totally different way of sorting elements.
 
- Since:
- 3.2
- See Also:
- 
Constructor SummaryConstructorsConstructorDescriptionCreates a newViewerComparator, which uses the default comparator to sort strings.ViewerComparator(Comparator<? super String> comparator) Creates a newViewerComparator, which uses the given comparator to sort strings.
- 
Method SummaryModifier and TypeMethodDescriptionintReturns the category of the given element.intReturns a negative, zero, or positive number depending on whether the first element is less than, equal to, or greater than the second element.protected Comparator<? super String> Returns the comparator used to sort strings.booleanisSorterProperty(Object element, String property) Returns whether this viewer sorter would be affected by a change to the given property of the given element.voidSorts the given elements in-place, modifying the given array.
- 
Constructor Details- 
ViewerComparatorpublic ViewerComparator()Creates a newViewerComparator, which uses the default comparator to sort strings.
- 
ViewerComparatorCreates a newViewerComparator, which uses the given comparator to sort strings. The default implementation ofcompare(Viewer, Object, Object)expects this comparator to be able to compare theStrings provided by the viewer's label provider.- Parameters:
- comparator- the comparator to use
 
 
- 
- 
Method Details- 
getComparatorReturns the comparator used to sort strings.- Returns:
- the comparator used to sort strings
 
- 
categoryReturns the category of the given element. The category is a number used to allocate elements to bins; the bins are arranged in ascending numeric order. The elements within a bin are arranged via a second level sort criterion.The default implementation of this framework method returns 0. Subclasses may reimplement this method to provide non-trivial categorization.- Parameters:
- element- the element
- Returns:
- the category
 
- 
compareReturns a negative, zero, or positive number depending on whether the first element is less than, equal to, or greater than the second element.The default implementation of this method is based on comparing the elements' categories as computed by the categoryframework method. Elements within the same category are further subjected to a case insensitive compare of their label strings, either as computed by the content viewer's label provider, or theirtoStringvalues in other cases. Subclasses may override.- Parameters:
- viewer- the viewer
- e1- the first element
- e2- the second element
- Returns:
- a negative number if the first element is less  than the
  second element; the value 0if the first element is equal to the second element; and a positive number if the first element is greater than the second element
 
- 
isSorterPropertyReturns whether this viewer sorter would be affected by a change to the given property of the given element.The default implementation of this method returns false. Subclasses may reimplement.- Parameters:
- element- the element
- property- the property
- Returns:
- trueif the sorting would be affected, and- falseif it would be unaffected
 
- 
sortSorts the given elements in-place, modifying the given array.The default implementation of this method uses the Arrays.sort(Object[], Comparator)algorithm on the given array, callingcompare(Viewer, Object, Object)to compare elements.Subclasses may reimplement this method to provide a more optimized implementation. - Parameters:
- viewer- the viewer
- elements- the elements to sort
 
 
-