A massive organize imports and formatting of the sources using default Eclipse code...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / filters / OutputFolderFilter.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.filters;
12
13 import net.sourceforge.phpdt.core.IClasspathEntry;
14 import net.sourceforge.phpdt.core.IJavaProject;
15 import net.sourceforge.phpdt.core.JavaCore;
16 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
17
18 import org.eclipse.core.resources.IFolder;
19 import org.eclipse.core.resources.IProject;
20 import org.eclipse.core.runtime.CoreException;
21 import org.eclipse.core.runtime.IPath;
22 import org.eclipse.jface.viewers.Viewer;
23 import org.eclipse.jface.viewers.ViewerFilter;
24
25 /**
26  * Filters out all output folders.
27  * <p>
28  * Note: Folder which are direct children of a Java element are already filtered
29  * by the Java Model.
30  * </p>
31  * 
32  * @since 3.0
33  */
34 public class OutputFolderFilter extends ViewerFilter {
35
36         /**
37          * Returns the result of this filter, when applied to the given element.
38          * 
39          * @param element
40          *            the element to test
41          * @return <code>true</code> if element should be included
42          * @since 3.0
43          */
44         public boolean select(Viewer viewer, Object parent, Object element) {
45                 if (element instanceof IFolder) {
46                         IFolder folder = (IFolder) element;
47                         IProject proj = folder.getProject();
48                         try {
49                                 if (!proj.hasNature(PHPeclipsePlugin.PHP_NATURE_ID))
50                                         return true;
51
52                                 IJavaProject jProject = JavaCore.create(folder.getProject());
53                                 if (jProject == null || !jProject.exists())
54                                         return true;
55
56                                 // Check default output location
57                                 IPath defaultOutputLocation = jProject.getOutputLocation();
58                                 IPath folderPath = folder.getFullPath();
59                                 if (defaultOutputLocation != null
60                                                 && defaultOutputLocation.equals(folderPath))
61                                         return false;
62
63                                 // Check output location for each class path entry
64                                 IClasspathEntry[] cpEntries = jProject.getRawClasspath();
65                                 for (int i = 0, length = cpEntries.length; i < length; i++) {
66                                         IPath outputLocation = cpEntries[i].getOutputLocation();
67                                         if (outputLocation != null
68                                                         && outputLocation.equals(folderPath))
69                                                 return false;
70                                 }
71                         } catch (CoreException ex) {
72                                 return true;
73                         }
74                 }
75                 return true;
76         }
77 }