Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 


Eclipse Platform
Release 3.5

org.eclipse.jface.viewers
Class ViewerComparator


java.lang.Object
  extended by 
org.eclipse.jface.viewers.ViewerComparator
Direct Known Subclasses:
ContributionComparator, ResourceComparator, ViewerSorter, WorkbenchViewerComparator

public class ViewerComparator
extends Object

A viewer comparator is used by a 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 is based on a case insensitive compare of the strings obtained from the content viewer's label provider via ILabelProvider.getText.

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:
IStructuredContentProvider, StructuredViewer

Constructor Summary
ViewerComparator ()
          Creates a new ViewerComparator, which uses the default comparator to sort strings.
ViewerComparator ( Comparator comparator)
          Creates a new ViewerComparator, which uses the given comparator to sort strings.
 
Method Summary
 int category ( Object element)
          Returns the category of the given element.
 int compare ( Viewer viewer, 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   Comparator getComparator ()
          Returns the comparator used to sort strings.
 boolean isSorterProperty ( Object element, String property)
          Returns whether this viewer sorter would be affected by a change to the given property of the given element.
 void sort ( Viewer viewer, Object[] elements)
          Sorts the given elements in-place, modifying the given array.
 
Methods inherited from class java.lang. Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ViewerComparator

public ViewerComparator()
Creates a new ViewerComparator, which uses the default comparator to sort strings.


ViewerComparator

public ViewerComparator(
Comparator comparator)
Creates a new ViewerComparator, which uses the given comparator to sort strings.

Parameters:
comparator -
Method Detail

getComparator

protected 
Comparator getComparator()
Returns the comparator used to sort strings.

Returns:
the comparator used to sort strings

category

public int category(
Object element)
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.

Parameters:
element - the element
Returns:
the category

compare

public int compare(
Viewer viewer,
                   
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
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

isSorterProperty

public boolean isSorterProperty(
Object element,
                                
String property)
Returns 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:
true if the sorting would be affected, and false if it would be unaffected

sort

public void sort(
Viewer viewer,
                 
Object[] elements)
Sorts the given elements in-place, 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.

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

Parameters:
viewer - the viewer
elements - the elements to sort

Eclipse Platform
Release 3.5

Guidelines for using Eclipse APIs.

Copyright (c) Eclipse contributors and others 2000, 2008. All rights reserved.


 
 
  Published under the terms of the Eclipse Public License Version 1.0 ("EPL") Design by Interspire