01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 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.editor.build;
11:
12: import java.util.HashSet;
13:
14: import org.eclipse.core.resources.IContainer;
15: import org.eclipse.core.resources.IFile;
16: import org.eclipse.core.resources.IResource;
17: import org.eclipse.core.runtime.CoreException;
18: import org.eclipse.core.runtime.IPath;
19: import org.eclipse.jface.viewers.Viewer;
20: import org.eclipse.jface.viewers.ViewerFilter;
21: import org.eclipse.pde.internal.ui.PDEPlugin;
22:
23: public class JARFileFilter extends ViewerFilter {
24: private final static String jarExt = "jar"; //$NON-NLS-1$
25: private HashSet fPaths;
26:
27: public JARFileFilter() {
28: fPaths = new HashSet();
29: }
30:
31: public JARFileFilter(HashSet names) {
32: fPaths = names;
33: }
34:
35: public boolean select(Viewer viewer, Object parent, Object element) {
36: if (element instanceof IFile)
37: return isFileValid(((IFile) element)
38: .getProjectRelativePath());
39:
40: if (element instanceof IContainer) { // i.e. IProject, IFolder
41: try {
42: if (!((IContainer) element).isAccessible())
43: return false;
44: IResource[] resources = ((IContainer) element)
45: .members();
46: for (int i = 0; i < resources.length; i++) {
47: if (select(viewer, parent, resources[i]))
48: return true;
49: }
50: } catch (CoreException e) {
51: PDEPlugin.logException(e);
52: }
53: }
54: return false;
55: }
56:
57: public boolean isFileValid(IPath path) {
58: String ext = path.getFileExtension();
59: if (isPathValid(path) && ext != null && ext.length() != 0)
60: return ext.equals(jarExt);
61: return false;
62: }
63:
64: public boolean isPathValid(IPath path) {
65: return !fPaths.contains(path);
66: }
67: }
|