KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > filters > JavaFileFilter


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.ui.filters;
12
13 import org.eclipse.jface.viewers.Viewer;
14 import org.eclipse.jface.viewers.ViewerFilter;
15
16 import org.eclipse.jdt.core.IClassFile;
17 import org.eclipse.jdt.core.ICompilationUnit;
18 import org.eclipse.jdt.core.IPackageFragment;
19 import org.eclipse.jdt.core.JavaModelException;
20
21
22 /**
23  * Filters out all compilation units and class files elements.
24  */

25 public class JavaFileFilter extends ViewerFilter {
26     
27     /**
28      * Returns the result of this filter, when applied to the
29      * given inputs.
30      *
31      * @return Returns true if element should be included in filtered set
32      */

33     public boolean select(Viewer viewer, Object JavaDoc parent, Object JavaDoc element) {
34         if (element instanceof ICompilationUnit)
35             return false;
36         if (element instanceof IClassFile)
37             return false;
38             
39         if (element instanceof IPackageFragment)
40             try {
41                 return ((IPackageFragment)element).getNonJavaResources().length > 0;
42             } catch (JavaModelException ex) {
43                 return true;
44             }
45         return true;
46     }
47 }
48
Popular Tags