Class ObjectViewerComparator


  • public class ObjectViewerComparator
    extends org.eclipse.jface.viewers.ViewerComparator
    The ObjectViewerComparator allows to rotate between three sorting states:
    1. no sorting
    2. ascending
    3. descending
    To sort the objects, the comparator applies the configured sorting function to the given objects.
    Since:
    1.20
    Author:
    Lucas Koehler
    • Constructor Summary

      Constructors 
      Constructor Description
      ObjectViewerComparator​(TriFunction<java.lang.Integer,​java.lang.Integer,​java.lang.Object,​java.lang.Object> compareFunction)
      Creates a new instance.
    • 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)  
      int getDirection()
      Get the current sorting direction as an SWT constant.
      void toggleDirection()
      Toggles through the sorting directions: NONE -> UP (ascending) -> DOWN (descending) -> NONE.
      • 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

      • ObjectViewerComparator

        public ObjectViewerComparator​(TriFunction<java.lang.Integer,​java.lang.Integer,​java.lang.Object,​java.lang.Object> compareFunction)
        Creates a new instance.
        Parameters:
        compareFunction - The function used to compare objects of the viewer. This tri-function accepts the sorting direction as its first argument and the objects to compare as the following arguments. The sorting directions are: 0 = none, 1 = ascending, 2 = descending
    • Method Detail

      • toggleDirection

        public void toggleDirection()
        Toggles through the sorting directions: NONE -> UP (ascending) -> DOWN (descending) -> NONE.
      • getDirection

        public int getDirection()
        Get the current sorting direction as an SWT constant.
        Returns:
        SWT.NONE, SWT.UP (ascending), or SWT.DOWN (descending)
      • compare

        public int compare​(org.eclipse.jface.viewers.Viewer viewer,
                           java.lang.Object e1,
                           java.lang.Object e2)
        Overrides:
        compare in class org.eclipse.jface.viewers.ViewerComparator