01: /*******************************************************************************
02: * Copyright (c) 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.util;
11:
12: import org.eclipse.core.resources.IContainer;
13: import org.eclipse.core.resources.IFile;
14: import org.eclipse.core.resources.IProject;
15: import org.eclipse.core.resources.IResource;
16: import org.eclipse.core.runtime.CoreException;
17: import org.eclipse.jface.viewers.Viewer;
18: import org.eclipse.jface.viewers.ViewerFilter;
19:
20: public class FileNameFilter extends ViewerFilter {
21:
22: private String fTargetName;
23:
24: public FileNameFilter(String targetName) {
25: fTargetName = targetName;
26: }
27:
28: public boolean select(Viewer viewer, Object parent, Object element) {
29: if (element instanceof IFile) {
30: return fTargetName.equals(((IFile) element).getName());
31: }
32:
33: if (element instanceof IProject
34: && !((IProject) element).isOpen())
35: return false;
36:
37: if (element instanceof IContainer) { // i.e. IProject, IFolder
38: try {
39: IResource[] resources = ((IContainer) element)
40: .members();
41: for (int i = 0; i < resources.length; i++) {
42: if (select(viewer, parent, resources[i]))
43: return true;
44: }
45: } catch (CoreException e) {
46: }
47: }
48: return false;
49: }
50:
51: }
|