1 11 package org.eclipse.jdt.internal.ui.browsing; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 17 import org.eclipse.core.runtime.Assert; 18 19 import org.eclipse.jface.viewers.IStructuredSelection; 20 21 import org.eclipse.jdt.core.IJavaProject; 22 import org.eclipse.jdt.core.IPackageFragmentRoot; 23 import org.eclipse.jdt.core.JavaModelException; 24 25 class ProjectAndSourceFolderContentProvider extends JavaBrowsingContentProvider { 26 27 ProjectAndSourceFolderContentProvider(JavaBrowsingPart browsingPart) { 28 super(false, browsingPart); 29 } 30 31 34 public Object [] getChildren(Object element) { 35 if (!exists(element)) 36 return NO_CHILDREN; 37 38 try { 39 startReadInDisplayThread(); 40 if (element instanceof IStructuredSelection) { 41 Assert.isLegal(false); 42 Object [] result= new Object [0]; 43 Class clazz= null; 44 Iterator iter= ((IStructuredSelection)element).iterator(); 45 while (iter.hasNext()) { 46 Object item= iter.next(); 47 if (clazz == null) 48 clazz= item.getClass(); 49 if (clazz == item.getClass()) 50 result= concatenate(result, getChildren(item)); 51 else 52 return NO_CHILDREN; 53 } 54 return result; 55 } 56 if (element instanceof IStructuredSelection) { 57 Assert.isLegal(false); 58 Object [] result= new Object [0]; 59 Iterator iter= ((IStructuredSelection)element).iterator(); 60 while (iter.hasNext()) 61 result= concatenate(result, getChildren(iter.next())); 62 return result; 63 } 64 if (element instanceof IJavaProject) 65 return getPackageFragmentRoots((IJavaProject)element); 66 if (element instanceof IPackageFragmentRoot) 67 return NO_CHILDREN; 68 69 return super.getChildren(element); 70 71 } catch (JavaModelException e) { 72 return NO_CHILDREN; 73 } finally { 74 finishedReadInDisplayThread(); 75 } 76 } 77 78 protected Object [] getPackageFragmentRoots(IJavaProject project) throws JavaModelException { 79 if (!project.getProject().isOpen()) 80 return NO_CHILDREN; 81 82 IPackageFragmentRoot[] roots= project.getPackageFragmentRoots(); 83 List list= new ArrayList (roots.length); 84 for (int i= 0; i < roots.length; i++) { 87 IPackageFragmentRoot root= roots[i]; 88 if (!isProjectPackageFragmentRoot(root)) 89 list.add(root); 90 } 91 return list.toArray(); 92 } 93 94 98 public boolean hasChildren(Object element) { 99 return element instanceof IJavaProject && super.hasChildren(element); 100 } 101 } 102 | Popular Tags |