KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > build > JARFileFilter


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