Jump to: navigation, search

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

 
m
 
Line 1: Line 1:
You do this with a <tt>ViewerFilter</tt>.
+
You do this with a <tt>ViewerFilter</tt>. <tt>ViewerFilter</tt>s are added to a structured viewer by using the <tt>addFilter</tt> method. When a filter is added, it defines a subset of the original elements to be shown.   Writing your own filter is trivial: Subclass <tt>ViewerFilter</tt> and override the method <tt>select</tt>. This method returns <tt>true</tt> if the element should be shown and <tt>false</tt> if it should be hidden. If more than one filter is added, the viewer will show only their intersection; that is, all filters must return <tt>true</tt> in their <tt>select</tt> method for the element to be shown.   
<tt>ViewerFilter</tt>s are added to a structured viewer by using the  
+
<tt>addFilter</tt> method.
+
When a filter is added, it defines a subset of the original elements to be shown.
+
Writing your own filter is trivial: Subclass <tt>ViewerFilter</tt> and override  
+
the method <tt>select</tt>. This method returns <tt>true</tt> if the element  
+
should be shown and <tt>false</tt> if it should be hidden.
+
If more than one filter is added, the viewer will show only their intersection;
+
that is, all filters must return <tt>true</tt> in their <tt>select</tt> method for
+
the element to be shown.   
+
 
+
 
+
 
+
One final tidbit of useful information: <tt>StructuredViewer</tt>
+
has a convenience method, <tt>resetFilters</tt>, for removing all of a viewer&#146;s
+
filters.  This is more efficient than removing filters one at a time as each time
+
a filter is added or removed, the entire viewer needs to be refreshed.
+
 
+
 
+
 
+
  
 +
One final tidbit of useful information: <tt>StructuredViewer</tt> has a convenience method, <tt>resetFilters</tt>, for removing all of a viewer&#146;s filters.  This is more efficient than removing filters one at a time as each time a filter is added or removed, the entire viewer needs to be refreshed.
  
 
== See Also: ==
 
== See Also: ==
 +
*[[FAQ What is a viewer?]]
 +
*[[FAQ How do I use properties to optimize a viewer?]]
  
 
+
{{Template:FAQ_Tagline}}
[[FAQ_What_is_a_viewer%3F]]
+
 
+
 
+
[[FAQ_How_do_I_use_properties_to_optimize_a_viewer%3F]]
+
 
+
<hr><font size=-2>This FAQ was originally published in [http://www.eclipsefaq.org Official Eclipse 3.0 FAQs]. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the [http://www.eclipse.org/legal/epl-v10.html Eclipse Public License v1.0].</font>
+

Latest revision as of 21:46, 29 May 2006

You do this with a ViewerFilter. ViewerFilters are added to a structured viewer by using the addFilter method. When a filter is added, it defines a subset of the original elements to be shown. Writing your own filter is trivial: Subclass ViewerFilter and override the method select. This method returns true if the element should be shown and false if it should be hidden. If more than one filter is added, the viewer will show only their intersection; that is, all filters must return true in their select method for the element to be shown.

One final tidbit of useful information: StructuredViewer has a convenience method, resetFilters, for removing all of a viewer’s filters. This is more efficient than removing filters one at a time as each time a filter is added or removed, the entire viewer needs to be refreshed.

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.