Package org.eclipse.ui.dialogs
Class PatternFilter
- java.lang.Object
-
- org.eclipse.jface.viewers.ViewerFilter
-
- org.eclipse.ui.dialogs.PatternFilter
-
public class PatternFilter extends ViewerFilter
A filter used in conjunction withFilteredTree
. 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Object[]
filter(Viewer viewer, Object parent, Object[] elements)
Filters the given elements for the given viewer.boolean
isElementSelectable(Object element)
Answers whether the given element is a valid selection in the filtered tree.boolean
isElementVisible(Viewer viewer, Object element)
Answers whether the given element in the given viewer matches the filter pattern.protected boolean
isLeafMatch(Viewer viewer, Object element)
Check if the current (leaf) element is a match with the filter text.protected boolean
isParentMatch(Viewer viewer, Object element)
Check if the parent (category) is a match to the filter text.boolean
select(Viewer viewer, Object parentElement, Object element)
Returns whether the given element makes it through this filter.void
setIncludeLeadingWildcard(boolean includeLeadingWildcard)
Sets whether a leading wildcard should be attached to each pattern string.void
setPattern(String patternString)
The pattern string for which this filter should select elements in the viewer.protected boolean
wordMatches(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
-
-
-
-
Method Detail
-
filter
public 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 whichselect
returnstrue
.- Overrides:
filter
in classViewerFilter
- Parameters:
viewer
- the viewerparent
- the parent elementelements
- 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 classViewerFilter
- Parameters:
viewer
- the viewerparentElement
- the parent elementelement
- the element- Returns:
true
if element is included in the filtered set, andfalse
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.- Parameters:
patternString
- the pattern string.
-
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.- Parameters:
element
- the element to check- 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 resideselement
- 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 elementelement
- 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 elementelement
- 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 critera.- Parameters:
text
- the text to match- Returns:
- boolean
true
if one of the words in text satisifes the match criteria.
-
-