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.IFolder;
13: import org.eclipse.core.resources.IProject;
14: import org.eclipse.core.runtime.CoreException;
15: import org.eclipse.core.runtime.IPath;
16:
17: import org.eclipse.jface.viewers.Viewer;
18: import org.eclipse.jface.viewers.ViewerFilter;
19:
20: import org.eclipse.jdt.core.IClasspathEntry;
21: import org.eclipse.jdt.core.IJavaProject;
22: import org.eclipse.jdt.core.JavaCore;
23:
24: /**
25: * Filters out all output folders.
26: * <p>
27: * Note: Folder which are direct children of a Java element
28: * are already filtered by the Java Model.
29: * </p>
30: *
31: * @since 3.0
32: */
33: public class OutputFolderFilter extends ViewerFilter {
34:
35: /**
36: * Returns the result of this filter, when applied to the
37: * given element.
38: *
39: * @param element the element to test
40: * @return <code>true</code> if element should be included
41: * @since 3.0
42: */
43: public boolean select(Viewer viewer, Object parent, Object element) {
44: if (element instanceof IFolder) {
45: IFolder folder = (IFolder) element;
46: IProject proj = folder.getProject();
47: try {
48: if (!proj.hasNature(JavaCore.NATURE_ID))
49: return true;
50:
51: IJavaProject jProject = JavaCore.create(folder
52: .getProject());
53: if (jProject == null || !jProject.exists())
54: return true;
55:
56: // Check default output location
57: IPath defaultOutputLocation = jProject
58: .getOutputLocation();
59: IPath folderPath = folder.getFullPath();
60: if (defaultOutputLocation != null
61: && defaultOutputLocation.equals(folderPath))
62: return false;
63:
64: // Check output location for each class path entry
65: IClasspathEntry[] cpEntries = jProject
66: .getRawClasspath();
67: for (int i = 0, length = cpEntries.length; i < length; i++) {
68: IPath outputLocation = cpEntries[i]
69: .getOutputLocation();
70: if (outputLocation != null
71: && outputLocation.equals(folderPath))
72: return false;
73: }
74: } catch (CoreException ex) {
75: return true;
76: }
77: }
78: return true;
79: }
80: }
|