Skip to main content
summaryrefslogtreecommitdiffstats
blob: 8fd6e6ac82ee7b2074e7e2a365eaa08595084e11 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*******************************************************************************
* Copyright (c) 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
* 
* Contributors:
*     Oracle - initial API and implementation
*******************************************************************************/
package org.eclipse.jpt.jaxb.ui.internal.filters;

import org.eclipse.core.resources.IContainer;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;

/**
 * Filters out all non Container and all JavaProject 
 * with name not equals to the given projectName.
 */
public class NonContainerFilter extends ViewerFilter
{
	final private String projectName;

	public NonContainerFilter(String projectName) {
		this.projectName = projectName;
	}

	@Override
	public boolean select(Viewer viewer, Object parent, Object element) {
		boolean isContainer = element instanceof IContainer;
		int type;
		if( ! isContainer && element instanceof IJavaElement) {
			type = ((IJavaElement)element).getElementType();
			isContainer = (type == IJavaElement.JAVA_MODEL
						|| type == IJavaElement.JAVA_PROJECT
						|| type == IJavaElement.PACKAGE_FRAGMENT
						|| type ==IJavaElement.PACKAGE_FRAGMENT_ROOT);
		}
		if(isContainer && (element instanceof IJavaElement)) {
			type = ((IJavaElement)element).getElementType();
			if(type == IJavaElement.JAVA_PROJECT) {
				String projectName = ((IJavaProject)element).getElementName();
				return projectName.equals(this.projectName);
			}
		}
		return isContainer;
	}

	@Override
	public String toString() {
		return "Filter out Non-Containers"; //$NON-NLS-1$
	}
}

Back to the top