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