1 /*******************************************************************************
2 * Copyright (c) 2000, 2004 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.filters;
13 import net.sourceforge.phpdt.core.IJavaElement;
14 import net.sourceforge.phpdt.internal.ui.util.StringMatcher;
16 import org.eclipse.core.resources.IResource;
17 import org.eclipse.core.runtime.IAdaptable;
18 import org.eclipse.jface.viewers.Viewer;
19 import org.eclipse.jface.viewers.ViewerFilter;
22 * The NamePatternFilter selects the elements which
23 * match the given string patterns.
25 * The following characters have special meaning:
32 public class NamePatternFilter extends ViewerFilter {
33 private String[] fPatterns;
34 private StringMatcher[] fMatchers;
37 * Return the currently configured StringMatchers.
39 private StringMatcher[] getMatchers() {
44 * Gets the patterns for the receiver.
46 public String[] getPatterns() {
52 * Method declared on ViewerFilter.
54 public boolean select(Viewer viewer, Object parentElement, Object element) {
55 String matchName= null;
56 if (element instanceof IJavaElement) {
57 matchName= ((IJavaElement) element).getElementName();
58 } else if (element instanceof IAdaptable) {
59 IAdaptable adaptable= (IAdaptable) element;
60 IJavaElement javaElement= (IJavaElement)adaptable.getAdapter(IJavaElement.class);
61 if (javaElement != null)
62 matchName= javaElement.getElementName();
64 IResource resource= (IResource)adaptable.getAdapter(IResource.class);
66 matchName= resource.getName();
69 if (matchName != null) {
70 StringMatcher[] testMatchers= getMatchers();
71 for (int i = 0; i < testMatchers.length; i++) {
72 if (testMatchers[i].match(matchName))
81 * Sets the patterns to filter out for the receiver.
83 * The following characters have special meaning:
88 public void setPatterns(String[] newPatterns) {
89 fPatterns = newPatterns;
90 fMatchers = new StringMatcher[newPatterns.length];
91 for (int i = 0; i < newPatterns.length; i++) {
92 //Reset the matchers to prevent constructor overhead
93 fMatchers[i]= new StringMatcher(newPatterns[i], true, false);