Class PatternFilter

java.lang.Object
org.eclipse.jface.viewers.ViewerFilter
org.eclipse.nebula.widgets.xviewer.util.internal.PatternFilter
Direct Known Subclasses:
XViewerPatternFilter

public class PatternFilter
extends org.eclipse.jface.viewers.ViewerFilter
A filter used in conjunction with FilteredTree. In order to determine if a node should be filtered it uses the content and label provider of the tree to do pattern matching on its children. This causes the entire tree structure to be realized. Note that the label provider must implement ILabelProvider.
Since:
3.2
See Also:
FilteredTree
  • Constructor Summary

    Constructors 
    Constructor Description
    PatternFilter()  
  • Method Summary

    Modifier and Type Method Description
    void clearCaches()
    Clears the caches used for optimizing this filter.
    java.lang.Object[] filter​(org.eclipse.jface.viewers.Viewer viewer, java.lang.Object parent, java.lang.Object[] elements)  
    boolean isElementSelectable​(java.lang.Object element)
    Answers whether the given element is a valid selection in the filtered tree.
    boolean isElementVisible​(org.eclipse.jface.viewers.Viewer viewer, java.lang.Object element)
    Answers whether the given element in the given viewer matches the filter pattern.
    boolean isLeafMatch​(org.eclipse.jface.viewers.Viewer viewer, java.lang.Object element)
    Check if the current (leaf) element is a match with the filter text.
    protected boolean isParentMatch​(org.eclipse.jface.viewers.Viewer viewer, java.lang.Object element)
    Check if the parent (category) is a match to the filter text.
    boolean select​(org.eclipse.jface.viewers.Viewer viewer, java.lang.Object parentElement, java.lang.Object element)  
    void setIncludeLeadingWildcard​(boolean includeLeadingWildcard)
    Sets whether a leading wildcard should be attached to each pattern string.
    void setPattern​(java.lang.String patternString)
    The pattern string for which this filter should select elements in the viewer.
    void setUseCache​(boolean useCache)
    Can be called by the filtered tree to turn on caching.
    protected boolean wordMatches​(java.lang.String text)
    Return whether or not if any of the words in text satisfy the match critera.

    Methods inherited from class org.eclipse.jface.viewers.ViewerFilter

    filter, isFilterProperty

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • filter

      public final java.lang.Object[] filter​(org.eclipse.jface.viewers.Viewer viewer, java.lang.Object parent, java.lang.Object[] elements)
      Overrides:
      filter in class org.eclipse.jface.viewers.ViewerFilter
      See Also:
      ViewerFilter.filter(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object[])
    • select

      public final boolean select​(org.eclipse.jface.viewers.Viewer viewer, java.lang.Object parentElement, java.lang.Object element)
      Specified by:
      select in class org.eclipse.jface.viewers.ViewerFilter
      See Also:
      ViewerFilter.select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
    • setIncludeLeadingWildcard

      public final void setIncludeLeadingWildcard​(boolean includeLeadingWildcard)
      Sets whether a leading wildcard should be attached to each pattern string.
      Parameters:
      includeLeadingWildcard - Whether a leading wildcard should be added.
    • setPattern

      public void setPattern​(java.lang.String patternString)
      The pattern string for which this filter should select elements in the viewer.
      Parameters:
      patternString -
    • clearCaches

      public void clearCaches()
      Clears the caches used for optimizing this filter. Needs to be called whenever the tree content changes.
    • isElementSelectable

      public boolean isElementSelectable​(java.lang.Object element)
      Answers whether the given element is a valid selection in the filtered tree. For example, if a tree has items that are categorized, the category itself may not be a valid selection since it is used merely to organize the elements.
      Parameters:
      element -
      Returns:
      true if this element is eligible for automatic selection
    • isElementVisible

      public boolean isElementVisible​(org.eclipse.jface.viewers.Viewer viewer, java.lang.Object element)
      Answers whether the given element in the given viewer matches the filter pattern. This is a default implementation that will show a leaf element in the tree based on whether the provided filter text matches the text of the given element's text, or that of it's children (if the element has any). Subclasses may override this method.
      Parameters:
      viewer - the tree viewer in which the element resides
      element - the element in the tree to check for a match
      Returns:
      true if the element matches the filter pattern
    • isParentMatch

      protected boolean isParentMatch​(org.eclipse.jface.viewers.Viewer viewer, java.lang.Object element)
      Check if the parent (category) is a match to the filter text. The default behavior returns true if the element has at least one child element that is a match with the filter text. Subclasses may override this method.
      Parameters:
      viewer - the viewer that contains the element
      element - the tree element to check
      Returns:
      true if the given element has children that matches the filter text
    • isLeafMatch

      public boolean isLeafMatch​(org.eclipse.jface.viewers.Viewer viewer, java.lang.Object element)
      Check if the current (leaf) element is a match with the filter text. The default behavior checks that the label of the element is a match. Subclasses should override this method.
      Parameters:
      viewer - the viewer that contains the element
      element - the tree element to check
      Returns:
      true if the given element's label matches the filter text
    • wordMatches

      protected boolean wordMatches​(java.lang.String text)
      Return whether or not if any of the words in text satisfy the match critera.
      Parameters:
      text - the text to match
      Returns:
      boolean true if one of the words in text satisifes the match criteria.
    • setUseCache

      public void setUseCache​(boolean useCache)
      Can be called by the filtered tree to turn on caching.
      Parameters:
      useCache - The useCache to set.