|
Eclipse Platform 2.0 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.eclipse.jface.viewers.ViewerSorter
A viewer sorter is used by a structured viewer 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.
IStructuredContentProvider
,
StructuredViewer
Field Summary | |
protected Collator |
collator
The collator used to sort strings. |
Constructor Summary | |
protected |
ViewerSorter()
Creates a new viewer sorter, which uses the default collator to sort strings. |
protected |
ViewerSorter(Collator collator)
Creates a new viewer sorter, which uses the given collator 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. |
Collator |
getCollator()
Returns the collator 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 |
Field Detail |
protected Collator collator
Constructor Detail |
protected ViewerSorter()
protected ViewerSorter(Collator collator)
collator
- the collator to use to sort stringsMethod Detail |
public int category(Object element)
The default implementation of this framework method returns
0
. Subclasses may reimplement this method to provide
non-trivial categorization.
element
- the element
public int compare(Viewer viewer, Object e1, Object e2)
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.
viewer
- the viewere1
- the first elemente2
- the second element
0
if the first element is
equal to the second element; and a positive number if the first
element is greater than the second elementpublic Collator getCollator()
public boolean isSorterProperty(Object element, String property)
The default implementation of this method returns false
.
Subclasses may reimplement.
element
- the elementproperty
- the property
true
if the sorting would be affected,
and false
if it would be unaffectedpublic void sort(Viewer viewer, Object[] elements)
The default implementation of this method uses the JDK 1.2
Collections.sort
algorithm on the given array,
calling compare
to compare elements.
Subclasses may reimplement this method to provide a more optimized implementation.
viewer
- the viewerelements
- the elements to sort
|
Eclipse Platform 2.0 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |