Package org.eclipse.handly.ui.viewer

## Class LabelComparator

- java.lang.Object
- - org.eclipse.jface.viewers.ViewerComparator
  - - org.eclipse.handly.ui.viewer.LabelComparator

-     public class LabelComparator
      extends org.eclipse.jface.viewers.ViewerComparator

  Compares elements based on the strings obtained from the content viewer's label provider.

  This class supports label providers besides `ILabelProvider`, such as `DelegatingStyledCellLabelProvider.IStyledLabelProvider` and `DelegatingStyledCellLabelProvider`.

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `LabelComparator()` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `int` | `compare​(org.eclipse.jface.viewers.Viewer viewer, java.lang.Object e1, java.lang.Object e2)` | Returns a negative, zero, or positive number depending on whether the first element is less than, equal to, or greater than the second element.
    `protected java.lang.String` | `getLabel​(org.eclipse.jface.viewers.Viewer viewer, java.lang.Object element)` | Returns the label string for the given viewer element to use for sorting the viewer's contents.

    - ### Methods inherited from class org.eclipse.jface.viewers.ViewerComparator

      `category, getComparator, isSorterProperty, sort`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### LabelComparator

          public LabelComparator()

  - ### Method Detail

    - #### compare

          public int compare​(org.eclipse.jface.viewers.Viewer viewer,
                             java.lang.Object e1,
                             java.lang.Object e2)

      Returns a negative, zero, or positive number depending on whether the first element is less than, equal to, or greater than the second element.

      This implementation is based on comparing the elements' categories as computed by the `ViewerComparator.category(Object)` method. Elements within the same category are further subjected to comparing their label strings as computed by the `getLabel(Viewer, Object)` method. The label strings are compared using the comparator provided by the `ViewerComparator.getComparator()` method.

      Overrides:
        `compare` in class `org.eclipse.jface.viewers.ViewerComparator`

    - #### getLabel

          protected java.lang.String getLabel​(org.eclipse.jface.viewers.Viewer viewer,
                                              java.lang.Object element)

      Returns the label string for the given viewer element to use for sorting the viewer's contents.

      This implementation returns the label string obtained from the content viewer's label provider.

      Parameters:
        `viewer` - the viewer
        `element` - the element
      Returns:
        the label string for the given viewer element, or `null` if no label can be obtained