public void setPattern(String patternString) { super.setPattern(patternString); this.patternString = patternString; }
private FilteredTree createFilteredTree(Group group) { int style = SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER; FilteredTree transfersTree = new FilteredTree(group, style, new PatternFilter(), true) { @Override protected TreeViewer doCreateTreeViewer(Composite parent, int style) { return new CheckboxTreeViewer(parent, style); } }; return transfersTree; }
if (element instanceof TracingComponent) { TracingComponent component = (TracingComponent) element; boolean textMatches = super.isLeafMatch(viewer, component); if (textMatches) { } else { isVisible = super.isElementVisible(viewer, element); visibleTracingComponentsCache.put(component, Boolean.valueOf(isVisible)); } else { isVisible = super.isLeafMatch(viewer, element); if (!isVisible) { isVisible = super.isParentMatch(viewer, 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. * * @param viewer the tree viewer in which the element resides * @param element the element in the tree to check for a match * * @return true if the element matches the filter pattern */ public boolean isElementVisible(Viewer viewer, Object element){ return isParentMatch(viewer, element) || isLeafMatch(viewer, element); }
/** * While the plugin model offers resource bundle localization, some plugins may skip this and use fix text for display. * Wildcard enabled search of the PatternFilter should be available in this case. Only a list of attributes that * are expected to contain resource bundles are evaluated as long as the value doesn't contain a point. On some elements * for example a name attribute can contain an id. Those are skipped though. * * @param attributeValue * @param attributeName * @param searchPattern * @return whether this is a match */ protected boolean isNoneResourceMatch(String attributeValue, String attributeName, String searchPattern) { if (ExtensionsFilterUtil.isAttributeNameMatch(attributeName, ExtensionsFilterUtil.RESOURCE_ATTRIBUTES)) { if (attributeValue.indexOf('.') == -1 && searchPattern.indexOf('.') == -1) { // no ids super.setPattern(searchPattern); boolean match = super.wordMatches(attributeValue); super.setPattern(fSearchPattern); if (match) { return true; } super.setPattern(fSearchPattern); } } return false; }
container.setLayoutData(gd); PatternFilter filter = new PatternFilter(); filter.setIncludeLeadingWildcard(true); FilteredCheckboxTree tree = new FilteredCheckboxTree(container, null, SWT.NONE, filter); fFeatureViewer = tree.getCheckboxTreeViewer();
&& initialText.equals(filterText); if (initial) { filter.setPattern(null); } else if (filterText != null) { filter.setPattern(filterText); if (filter.isElementVisible(tree.getViewer(), element) && filter.isLeafMatch(tree.getViewer(), element)) { return JFaceResources.getFontRegistry().getBold( JFaceResources.DIALOG_FONT);
private void createTableArea(Composite parent) { fFilteredTree = new FilteredCheckboxTree(parent, null); fFilteredTree.getPatternFilter().setIncludeLeadingWildcard(true); fCheckboxTreeViewer = fFilteredTree.getCheckboxTreeViewer(); fCheckboxTreeViewer.setContentProvider(new PluginContentProvider()); fCheckboxTreeViewer.setLabelProvider(new StyledPluginLabelProvider()); fCheckboxTreeViewer.setUseHashlookup(true); fCheckboxTreeViewer.setInput(fPluginProjectList.toArray(new IPluginModelBase[fPluginProjectList.size()])); for (int i = 0; i < fPluginProjectList.size(); i++) { fCheckboxTreeViewer.setChecked(fPluginProjectList.get(i), true); } }
@Override public final boolean select(Viewer viewer, Object parentElement, Object element) { return isElementVisible(viewer, element); }
@Override protected boolean isLeafMatch(Viewer viewer, Object element) { if(element instanceof CommitItem) { CommitItem commitItem = (CommitItem) element; return wordMatches(commitItem.path); } return super.isLeafMatch(viewer, element); } };
@Override protected boolean isParentMatch(Viewer viewer, Object element) { if (viewer instanceof AbstractTreeViewer) { return super.isParentMatch(viewer, element); } return false; }
/** * Return the first item in the tree that matches the filter pattern. * * @param items * @return the first matching TreeItem */ private TreeItem getFirstMatchingItem(TreeItem[] items) { for (TreeItem item : items) { if (patternFilter.isLeafMatch(treeViewer, item.getData()) && patternFilter.isElementSelectable(item.getData())) { return item; } TreeItem treeItem = getFirstMatchingItem(item.getItems()); if (treeItem != null) { return treeItem; } } return null; }
Composite res = new Composite(parent, SWT.NONE); GridLayoutFactory.fillDefaults().numColumns(2).applyTo(res); PatternFilter patternFilter = new PatternFilter(); patternFilter.setIncludeLeadingWildcard(true); FilteredTree filterTree = new FilteredTree(res, SWT.BORDER | SWT.CHECK, patternFilter, true) { @Override
filter.setIncludeLeadingWildcard(true);
/** * Returns true if any of the elements makes it through the filter. * * @param viewer the viewer * @param elements the elements to test * @return <code>true</code> if any of the elements makes it through the filter */ private boolean computeAnyVisible(Viewer viewer, Object[] elements) { boolean elementFound = false; for (int i = 0; i < elements.length && !elementFound; i++) { Object element = elements[i]; elementFound = isElementVisible(viewer, element); } return elementFound; }
String resourceValue = pluginElement.getResourceString(attributeValue); attributeValue = (resourceValue != null && resourceValue.length() > 0) ? resourceValue : attributeValue; super.setPattern(String.valueOf(searchPattern)); boolean match = (super.wordMatches(attributeValue)); super.setPattern(fSearchPattern); if (match) { return true;
@Override protected boolean isLeafMatch(Viewer viewer, Object element) { if (super.isLeafMatch(viewer, element)) return true; return wordMatches(getText(element)); }
protected boolean isParentMatch(Viewer viewer, Object element) { if (patternString == null || patternString.length() == 0) return true; return super.isParentMatch(viewer, element); }
/** * Constructor that creates a tree with preset style bits and a CachedContainerCheckedTreeViewer for the tree. * * @param parent parent composite * @param toolkit optional toolkit to create UI elements with, required if the tree is being created in a form editor */ public FilteredCheckboxTree(Composite parent, FormToolkit toolkit, int treeStyle) { this(parent, toolkit, treeStyle, new PatternFilter()); }
@Override public void setPattern(String patternString) { if (patternString == null || patternString.startsWith("*")) { //$NON-NLS-1$ super.setPattern(patternString); } else { super.setPattern("*" + patternString); //$NON-NLS-1$ } } }