Added filters to the PHp OutlinePage
[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
14 import net.sourceforge.phpdt.core.IClasspathEntry;
15 import net.sourceforge.phpdt.core.IJavaProject;
16 import net.sourceforge.phpdt.core.JavaCore;
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 /** 
28  * Filters out all output folders.
29  * <p>
30  * Note: Folder which are direct children of a Java element
31  * are already filtered by the Java Model.
32  * </p>
33  * 
34  * @since 3.0
35  */
36 public class OutputFolderFilter extends ViewerFilter {
37         
38         /**
39          * Returns the result of this filter, when applied to the
40          * given element.
41          *
42          * @param element the element to test 
43          * @return <code>true</code> if element should be included
44          * @since 3.0
45          */
46         public boolean select(Viewer viewer, Object parent, Object element) {
47                 if (element instanceof IFolder) {
48                         IFolder folder= (IFolder)element;
49                         IProject proj= folder.getProject();
50                         try {
51                                 if (!proj.hasNature(PHPeclipsePlugin.PHP_NATURE_ID))
52                                         return true;
53                                 
54                                 IJavaProject jProject= JavaCore.create(folder.getProject());
55                                 if (jProject == null || !jProject.exists())
56                                         return true;
57                                 
58                                 // Check default output location
59                                 IPath defaultOutputLocation= jProject.getOutputLocation();
60                                 IPath folderPath= folder.getFullPath();
61                                 if (defaultOutputLocation != null && 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 && outputLocation.equals(folderPath))
69                                                 return false;
70                                 }
71                         } catch (CoreException ex) {
72                                 return true;
73                         }
74                 }
75                 return true;
76         }
77 }