Eclipse Platform
Release 3.2

org.eclipse.ui.navigator
Class TreeViewerSorter

java.lang.Object
  extended byorg.eclipse.jface.viewers.ViewerSorter
      extended byorg.eclipse.ui.navigator.TreeViewerSorter
Direct Known Subclasses:
CommonViewerSorter

public class TreeViewerSorter
extends ViewerSorter

Provides context sensitive sorting of elements based on their parent in the tree.

Clients may extend this class.

EXPERIMENTAL. This class or interface has been added as part of a work in progress. There is a guarantee neither that this API will work nor that it will remain the same. Please do not use this API without consulting with the Platform/UI team.

Since:
3.2

Field Summary
 
Fields inherited from class org.eclipse.jface.viewers.ViewerSorter
collator
 
Constructor Summary
TreeViewerSorter()
           
 
Method Summary
 int compare(Viewer viewer, Object parent, Object e1, 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.
 void sort(Viewer viewer, Object parent, Object[] elements)
          Sorts the given elements in-place taking into account the parent of the elements, modifying the given array.
 
Methods inherited from class org.eclipse.jface.viewers.ViewerSorter
category, compare, getCollator, isSorterProperty, sort
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TreeViewerSorter

public TreeViewerSorter()
Method Detail

sort

public void sort(Viewer viewer,
                 Object parent,
                 Object[] elements)
Sorts the given elements in-place taking into account the parent of the elements, modifying the given array.

The default implementation of this method uses the java.util.Arrays#sort algorithm on the given array, calling compare to compare elements, and the parent does not affect sorting algorithm.

Subclasses may reimplement this method to provide a more optimized implementation.

Parameters:
viewer - the viewer
parent - The parent element in the tree of both children.
elements - the elements to sort

compare

public int compare(Viewer viewer,
                   Object parent,
                   Object e1,
                   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.

The default implementation of this method is based on comparing the elements' categories as computed by the category framework 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 their toString values in other cases. Subclasses may override.

Parameters:
viewer - the viewer
parent - The parent element in the tree of both children.
e1 - the first element
e2 - the second element
Returns:
a negative number if the first element is less than the second element; the value 0 if the first element is equal to the second element; and a positive number if the first element is greater than the second element

Eclipse Platform
Release 3.2

Guidelines for using Eclipse APIs.

Copyright (c) IBM Corp. and others 2000, 2005. All rights reserved.