Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "FAQ How do I sort the contents of a viewer?"

m
m
Line 1: Line 1:
Structured viewers are sorted by plugging in an instance of <tt>ViewerSorter</tt>, using the <tt>StructuredViewer.setSorter</tt> method.  For simple sorting based on label text, use the generic <tt>ViewerSorter</tt> class itself, optionally supplying  a <tt>java.text.Collator</tt> instance to define how strings are compared.  For more complex  comparisons, you&#146;ll need to subclass <tt>ViewerSorter</tt>. You can override  the <tt>category</tt> method to divide the elements up into an ordered set of categories, leaving the text collator to sort the elements within each category.  For complete customization  of sorting, override the <tt>compare</tt> method, which acts much like the standard  <tt>java.util. Comparator</tt> interface.
+
Structured viewers are sorted by plugging in an instance of <tt>ViewerSorter</tt>, using the <tt>StructuredViewer.setSorter</tt> method.  For simple sorting based on label text, use the generic <tt>ViewerSorter</tt> class itself, optionally supplying  a <tt>java.text.Collator</tt> instance to define how strings are compared.  For more complex  comparisons, you'll need to subclass <tt>ViewerSorter</tt>. You can override  the <tt>category</tt> method to divide the elements up into an ordered set of categories, leaving the text collator to sort the elements within each category.  For complete customization  of sorting, override the <tt>compare</tt> method, which acts much like the standard  <tt>java.util. Comparator</tt> interface.
 
   
 
   
 
== See Also: ==
 
== See Also: ==

Revision as of 14:08, 25 July 2017

Structured viewers are sorted by plugging in an instance of ViewerSorter, using the StructuredViewer.setSorter method. For simple sorting based on label text, use the generic ViewerSorter class itself, optionally supplying a java.text.Collator instance to define how strings are compared. For more complex comparisons, you'll need to subclass ViewerSorter. You can override the category method to divide the elements up into an ordered set of categories, leaving the text collator to sort the elements within each category. For complete customization of sorting, override the compare method, which acts much like the standard java.util. Comparator interface.

See Also:


This FAQ was originally published in Official Eclipse 3.0 FAQs. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the Eclipse Public License v1.0.

Back to the top