01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.ui.jarpackager;
11:
12: import org.eclipse.core.resources.IContainer;
13:
14: import org.eclipse.jface.viewers.Viewer;
15: import org.eclipse.jface.viewers.ViewerFilter;
16:
17: import org.eclipse.jdt.core.IJavaElement;
18:
19: /**
20: * Filters out all packages and folders
21: */
22: class ContainerFilter extends ViewerFilter {
23:
24: private boolean fFilterContainers;
25:
26: public static boolean FILTER_CONTAINERS = true;
27: public static boolean FILTER_NON_CONTAINERS = false;
28:
29: public ContainerFilter(boolean filterContainers) {
30: fFilterContainers = filterContainers;
31: }
32:
33: /* (non-Javadoc)
34: * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
35: */
36: public boolean select(Viewer viewer, Object parent, Object element) {
37: boolean isContainer = element instanceof IContainer;
38: if (!isContainer && element instanceof IJavaElement) {
39: int type = ((IJavaElement) element).getElementType();
40: isContainer = type == IJavaElement.JAVA_MODEL
41: || type == IJavaElement.JAVA_PROJECT
42: || type == IJavaElement.PACKAGE_FRAGMENT
43: || type == IJavaElement.PACKAGE_FRAGMENT_ROOT;
44: }
45: return (fFilterContainers && !isContainer)
46: || (!fFilterContainers && isContainer);
47: }
48: }
|