KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > launcher > ArchiveFileFilter


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.jdt.internal.debug.ui.launcher;
12
13 import java.util.Arrays JavaDoc;
14 import java.util.List 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.jdt.internal.debug.ui.JDIDebugUIPlugin;
22 import org.eclipse.jface.viewers.Viewer;
23 import org.eclipse.jface.viewers.ViewerFilter;
24
25 /**
26  * Viewer filter for archive selection dialogs.
27  * Archives are files with file extension 'jar' and 'zip'.
28  * The filter is not case sensitive.
29  */

30 public class ArchiveFileFilter extends ViewerFilter {
31
32     private static final String JavaDoc[] fgArchiveExtensions= { "jar", "zip" }; //$NON-NLS-1$ //$NON-NLS-2$
33

34     private List JavaDoc fExcludes;
35     
36     /**
37      * @param excludedFiles Excluded files will not pass the filter.
38      * <code>null</code> is allowed if no files should be excluded.
39      */

40     public ArchiveFileFilter(IFile[] excludedFiles) {
41         if (excludedFiles != null) {
42             fExcludes= Arrays.asList(excludedFiles);
43         } else {
44             fExcludes= null;
45         }
46     }
47     
48     /*
49      * @see ViewerFilter#select
50      */

51     public boolean select(Viewer viewer, Object JavaDoc parent, Object JavaDoc element) {
52         if (element instanceof IFile) {
53             if (fExcludes != null && fExcludes.contains(element)) {
54                 return false;
55             }
56             return isArchivePath(((IFile)element).getFullPath());
57         } else if (element instanceof IContainer) { // IProject, IFolder
58
try {
59                 IResource[] resources= ((IContainer)element).members();
60                 for (int i= 0; i < resources.length; i++) {
61                     // recursive! Only show containers that contain an archive
62
if (select(viewer, parent, resources[i])) {
63                         return true;
64                     }
65                 }
66             } catch (CoreException e) {
67                 JDIDebugUIPlugin.log(e.getStatus());
68             }
69         }
70         return false;
71     }
72     
73     public static boolean isArchivePath(IPath path) {
74         String JavaDoc ext= path.getFileExtension();
75         if (ext != null && ext.length() != 0) {
76             for (int i= 0; i < fgArchiveExtensions.length; i++) {
77                 if (ext.equalsIgnoreCase(fgArchiveExtensions[i])) {
78                     return true;
79                 }
80             }
81         }
82         return false;
83     }
84     
85             
86 }
87
Popular Tags