]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
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.jarpackager; | |
12 | ||
13 | import org.eclipse.core.resources.IContainer; | |
14 | ||
15 | import org.eclipse.jface.viewers.Viewer; | |
16 | import org.eclipse.jface.viewers.ViewerFilter; | |
17 | ||
18 | import org.eclipse.jdt.core.IJavaElement; | |
19 | ||
20 | /** | |
21 | * Filters out all packages and folders | |
22 | */ | |
23 | class ContainerFilter extends ViewerFilter { | |
24 | ||
25 | private boolean fFilterContainers; | |
26 | ||
27 | public static boolean FILTER_CONTAINERS= true; | |
28 | public static boolean FILTER_NON_CONTAINERS= false; | |
29 | ||
30 | public ContainerFilter(boolean filterContainers) { | |
31 | fFilterContainers= filterContainers; | |
32 | } | |
33 | ||
34 | /* (non-Javadoc) | |
35 | * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) | |
36 | */ | |
37 | @Override | |
38 | public boolean select(Viewer viewer, Object parent, Object element) { | |
39 | boolean isContainer= element instanceof IContainer; | |
40 | if (!isContainer && element instanceof IJavaElement) { | |
41 | int type= ((IJavaElement)element).getElementType(); | |
42 | isContainer= type == IJavaElement.JAVA_MODEL | |
43 | || type == IJavaElement.JAVA_PROJECT | |
44 | || type == IJavaElement.PACKAGE_FRAGMENT | |
45 | || type ==IJavaElement.PACKAGE_FRAGMENT_ROOT; | |
46 | } | |
47 | return (fFilterContainers && !isContainer) || (!fFilterContainers && isContainer); | |
48 | } | |
49 | } |