KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > util > FileNameFilter


1 /*******************************************************************************
2  * Copyright (c) 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.util;
12
13 import org.eclipse.core.resources.IContainer;
14 import org.eclipse.core.resources.IFile;
15 import org.eclipse.core.resources.IProject;
16 import org.eclipse.core.resources.IResource;
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.jface.viewers.Viewer;
19 import org.eclipse.jface.viewers.ViewerFilter;
20
21 public class FileNameFilter extends ViewerFilter {
22
23     private String JavaDoc fTargetName;
24
25     public FileNameFilter(String JavaDoc targetName) {
26         fTargetName = targetName;
27     }
28
29     public boolean select(Viewer viewer, Object JavaDoc parent, Object JavaDoc element) {
30         if (element instanceof IFile) {
31             return fTargetName.equals(((IFile)element).getName());
32         }
33
34         if (element instanceof IProject && !((IProject)element).isOpen())
35             return false;
36         
37         if (element instanceof IContainer){ // i.e. IProject, IFolder
38
try {
39                 IResource[] resources = ((IContainer)element).members();
40                 for (int i = 0; i < resources.length; i++){
41                     if (select(viewer, parent, resources[i]))
42                         return true;
43                 }
44             } catch (CoreException e) {
45             }
46         }
47         return false;
48     }
49
50 }
51
Popular Tags