]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-before/ui/org/eclipse/jdt/internal/ui/filters/OutputFolderFilter.java
Some talks, mostly identical.
[ifi-stolz-refaktor.git] / case-study / jdt-before / ui / org / eclipse / jdt / internal / ui / filters / OutputFolderFilter.java
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
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package org.eclipse.jdt.internal.ui.filters;
12
13
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.core.runtime.IPath;
16
17 import org.eclipse.core.resources.IFolder;
18 import org.eclipse.core.resources.IProject;
19
20 import org.eclipse.jface.viewers.Viewer;
21 import org.eclipse.jface.viewers.ViewerFilter;
22
23 import org.eclipse.jdt.core.IClasspathEntry;
24 import org.eclipse.jdt.core.IJavaProject;
25 import org.eclipse.jdt.core.JavaCore;
26
27
28 /**
29  * Filters out all output folders.
30  * <p>
31  * Note: Folder which are direct children of a Java element
32  * are already filtered by the Java Model.
33  * </p>
34  *
35  * @since 3.0
36  */
37 public class OutputFolderFilter extends ViewerFilter {
38
39         /**
40          * Returns the result of this filter, when applied to the
41          * given element.
42          *
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
47          * @since 3.0
48          */
49         @Override
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();
54                         try {
55                                 if (!proj.hasNature(JavaCore.NATURE_ID))
56                                         return true;
57
58                                 IJavaProject jProject= JavaCore.create(folder.getProject());
59                                 if (jProject == null || !jProject.exists())
60                                         return true;
61
62                                 // Check default output location
63                                 IPath defaultOutputLocation= jProject.getOutputLocation();
64                                 IPath folderPath= folder.getFullPath();
65                                 if (defaultOutputLocation != null && defaultOutputLocation.equals(folderPath))
66                                         return false;
67
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))
73                                                 return false;
74                                 }
75                         } catch (CoreException ex) {
76                                 return true;
77                         }
78                 }
79                 return true;
80         }
81 }