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 java.util.Locale;
13:
14: import org.eclipse.core.resources.IContainer;
15: import org.eclipse.core.resources.IFile;
16: import org.eclipse.core.resources.IProject;
17: import org.eclipse.core.resources.IResource;
18: import org.eclipse.core.runtime.CoreException;
19: import org.eclipse.jface.viewers.Viewer;
20: import org.eclipse.jface.viewers.ViewerFilter;
21:
22: public class FileExtensionFilter extends ViewerFilter {
23:
24: private String fTargetExtension;
25:
26: public FileExtensionFilter(String targetExtension) {
27: fTargetExtension = targetExtension;
28: }
29:
30: public boolean select(Viewer viewer, Object parent, Object element) {
31: if (element instanceof IFile) {
32: return ((IFile) element).getName().toLowerCase(
33: Locale.ENGLISH).endsWith("." + fTargetExtension); //$NON-NLS-1$
34: }
35:
36: if (element instanceof IProject
37: && !((IProject) element).isOpen())
38: return false;
39:
40: if (element instanceof IContainer) { // i.e. IProject, IFolder
41: try {
42: IResource[] resources = ((IContainer) element)
43: .members();
44: for (int i = 0; i < resources.length; i++) {
45: if (select(viewer, parent, resources[i]))
46: return true;
47: }
48: } catch (CoreException e) {
49: }
50: }
51: return false;
52: }
53:
54: }
|