KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > workingsets > JavaWorkingSetPageContentProvider


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.workingsets;
12
13 import org.eclipse.core.resources.IProject;
14 import org.eclipse.core.runtime.CoreException;
15
16 import org.eclipse.jdt.core.IJavaModel;
17 import org.eclipse.jdt.core.IPackageFragment;
18 import org.eclipse.jdt.core.IPackageFragmentRoot;
19 import org.eclipse.jdt.core.JavaModelException;
20
21 import org.eclipse.jdt.ui.StandardJavaElementContentProvider;
22
23 class JavaWorkingSetPageContentProvider extends StandardJavaElementContentProvider {
24     
25     public boolean hasChildren(Object JavaDoc element) {
26
27         if (element instanceof IProject && !((IProject)element).isAccessible())
28             return false;
29
30         if (element instanceof IPackageFragment) {
31             IPackageFragment pkg= (IPackageFragment)element;
32             try {
33                 if (pkg.getKind() == IPackageFragmentRoot.K_BINARY)
34                     return pkg.getChildren().length > 0;
35             } catch (JavaModelException ex) {
36                 // use super behavior
37
}
38         }
39         return super.hasChildren(element);
40     }
41
42     public Object JavaDoc[] getChildren(Object JavaDoc parentElement) {
43         try {
44             if (parentElement instanceof IJavaModel)
45                 return concatenate(super.getChildren(parentElement), getNonJavaProjects((IJavaModel)parentElement));
46             
47             if (parentElement instanceof IProject)
48                 return ((IProject)parentElement).members();
49
50             return super.getChildren(parentElement);
51         } catch (CoreException e) {
52             return NO_CHILDREN;
53         }
54     }
55
56     private Object JavaDoc[] getNonJavaProjects(IJavaModel model) throws JavaModelException {
57         return model.getNonJavaResources();
58     }
59 }
60
Popular Tags