Class PatternFilter

java.lang.Object
org.eclipse.jface.viewers.ViewerFilter
org.eclipse.e4.ui.dialogs.filteredtree.PatternFilter

public class PatternFilter extends ViewerFilter
Based on org.eclipse.ui.dialogs.PatternFilter.
Since:
1.2
  • Constructor Details

    • PatternFilter

      public PatternFilter()
    • PatternFilter

      public PatternFilter(boolean includeLeadingWildcard)
      Constructor to specify the includeLeadingWildcard flag.
      Parameters:
      includeLeadingWildcard - flag
      Since:
      1.1.0
  • Method Details

    • filter

      public final Object[] filter(Viewer viewer, Object parent, Object[] elements)
      Description copied from class: ViewerFilter
      Filters the given elements for the given viewer. The input array is not modified.

      The default implementation of this method calls select on each element in the array, and returns only those elements for which select returns true.

      Overrides:
      filter in class ViewerFilter
      Parameters:
      viewer - the viewer
      parent - the parent element
      elements - the elements to filter
      Returns:
      the filtered elements
    • select

      public final boolean select(Viewer viewer, Object parentElement, Object element)
      Description copied from class: ViewerFilter
      Returns whether the given element makes it through this filter.
      Specified by:
      select in class ViewerFilter
      Parameters:
      viewer - the viewer
      parentElement - the parent element
      element - the element
      Returns:
      true if element is included in the filtered set, and false if excluded
    • 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(String patternString)
      The pattern string for which this filter should select elements in the viewer.
    • isElementSelectable

      public boolean isElementSelectable(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.
      Returns:
      true if this element is eligible for automatic selection
    • isElementVisible

      public boolean isElementVisible(Viewer viewer, 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(Viewer viewer, 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

      protected boolean isLeafMatch(Viewer viewer, 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(String text)
      Return whether or not if any of the words in text satisfy the match criteria.
      Parameters:
      text - the text to match
      Returns:
      boolean true if one of the words in text satisfies the match criteria.