1 /*******************************************************************************
2 * Copyright (c) 2000, 2011 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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.internal.ui.filters;
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.core.runtime.IPath;
17 import org.eclipse.core.resources.IFolder;
18 import org.eclipse.core.resources.IProject;
20 import org.eclipse.jface.viewers.Viewer;
21 import org.eclipse.jface.viewers.ViewerFilter;
23 import org.eclipse.jdt.core.IClasspathEntry;
24 import org.eclipse.jdt.core.IJavaProject;
25 import org.eclipse.jdt.core.JavaCore;
29 * Filters out all output folders.
31 * Note: Folder which are direct children of a Java element
32 * are already filtered by the Java Model.
37 public class OutputFolderFilter extends ViewerFilter {
40 * Returns the result of this filter, when applied to the
43 * @param viewer the viewer
44 * @param parent the parent
45 * @param element the element to test
46 * @return <code>true</code> if element should be included
50 public boolean select(Viewer viewer, Object parent, Object element) {
51 if (element instanceof IFolder) {
52 IFolder folder= (IFolder)element;
53 IProject proj= folder.getProject();
55 if (!proj.hasNature(JavaCore.NATURE_ID))
58 IJavaProject jProject= JavaCore.create(folder.getProject());
59 if (jProject == null || !jProject.exists())
62 // Check default output location
63 IPath defaultOutputLocation= jProject.getOutputLocation();
64 IPath folderPath= folder.getFullPath();
65 if (defaultOutputLocation != null && defaultOutputLocation.equals(folderPath))
68 // Check output location for each class path entry
69 IClasspathEntry[] cpEntries= jProject.getRawClasspath();
70 for (int i= 0, length= cpEntries.length; i < length; i++) {
71 IPath outputLocation= cpEntries[i].getOutputLocation();
72 if (outputLocation != null && outputLocation.equals(folderPath))
75 } catch (CoreException ex) {