Eclipse Platform
Release 3.2

org.eclipse.ui.navigator
Class CommonViewerSorter

java.lang.Object
  extended byorg.eclipse.jface.viewers.ViewerSorter
      extended byorg.eclipse.ui.navigator.TreeViewerSorter
          extended byorg.eclipse.ui.navigator.CommonViewerSorter

public final class CommonViewerSorter
extends TreeViewerSorter

Provides an implementation of TreeViewerSorter that uses the given parent to determine the correct sort order based on the defined org.eclipse.ui.navigator.navigatorContent/navigatorContent/commonSorter elements available in the set of visible content extensions.

The CommonViewerSorter must be assigned to a CommonViewer. This is required so that the sorter has the correct content service and sorting service available to guide it in sorting the elements from the viewer. No guarantees are made for uses of this sorter class outside of a CommonViewer.

A CommonViewerSorter may not be attached to more than one CommonViewer.

Clients may not 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
CommonViewerSorter()
           
 
Method Summary
 int category(Object element)
          Returns the category of the given element.
 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.
protected  void setContentService(org.eclipse.ui.internal.navigator.NavigatorContentService aContentService)
          Create a sorter service attached to the given content service.
 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
compare, getCollator, isSorterProperty, sort
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommonViewerSorter

public CommonViewerSorter()
Method Detail

setContentService

protected void setContentService(org.eclipse.ui.internal.navigator.NavigatorContentService aContentService)
Create a sorter service attached to the given content service.

Parameters:
aContentService - The content service used by the viewer that will use this sorter service.

category

public int category(Object element)
Description copied from class: ViewerSorter
Returns 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.

Overrides:
category in class ViewerSorter
Parameters:
element - the element
Returns:
the category

sort

public void sort(Viewer viewer,
                 Object parent,
                 Object[] elements)
Description copied from class: TreeViewerSorter
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.

Overrides:
sort in class TreeViewerSorter
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)
Description copied from class: TreeViewerSorter
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.

Overrides:
compare in class TreeViewerSorter
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.