01: /*******************************************************************************
02: * Copyright (c) 2000, 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.jdt.internal.ui.filters;
11:
12: import org.eclipse.core.resources.IProject;
13: import org.eclipse.core.resources.IResource;
14: import org.eclipse.core.resources.IStorage;
15:
16: import org.eclipse.jface.viewers.Viewer;
17: import org.eclipse.jface.viewers.ViewerFilter;
18:
19: import org.eclipse.jdt.core.IJavaElement;
20:
21: /**
22: * Filters out all non-Java elements.
23: */
24: public class NonJavaElementFilter extends ViewerFilter {
25:
26: /**
27: * Returns the result of this filter, when applied to the
28: * given inputs.
29: *
30: * @return Returns true if element should be included in filtered set
31: */
32: public boolean select(Viewer viewer, Object parent, Object element) {
33: if (element instanceof IJavaElement)
34: return true;
35:
36: if (element instanceof IResource) {
37: IProject project = ((IResource) element).getProject();
38: return project == null || !project.isOpen();
39: }
40:
41: // Exclude all IStorage elements which are neither Java elements nor resources
42: if (element instanceof IStorage)
43: return false;
44:
45: return true;
46: }
47: }
|