1 11 package org.eclipse.jdt.internal.ui.javadocexport; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.core.resources.IWorkspaceRoot; 16 import org.eclipse.core.resources.ResourcesPlugin; 17 18 import org.eclipse.jface.viewers.ITreeContentProvider; 19 import org.eclipse.jface.viewers.Viewer; 20 21 import org.eclipse.jdt.core.IJavaElement; 22 import org.eclipse.jdt.core.IJavaProject; 23 import org.eclipse.jdt.core.IPackageFragment; 24 import org.eclipse.jdt.core.IPackageFragmentRoot; 25 import org.eclipse.jdt.core.JavaCore; 26 import org.eclipse.jdt.core.JavaModelException; 27 28 import org.eclipse.jdt.internal.ui.JavaPlugin; 29 30 public class JavadocProjectContentProvider implements ITreeContentProvider { 31 32 35 public Object [] getChildren(Object parentElement) { 36 try { 37 if (parentElement instanceof IJavaProject) { 38 IJavaProject project= (IJavaProject) parentElement; 39 return getPackageFragmentRoots(project); 40 } else if (parentElement instanceof IPackageFragmentRoot) { 41 return getPackageFragments((IPackageFragmentRoot) parentElement); 42 } 43 } catch (JavaModelException e) { 44 JavaPlugin.log(e); 45 } 46 return new Object [0]; 47 } 48 51 public Object [] getElements(Object inputElement) { 52 IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot(); 53 try { 54 return JavaCore.create(root).getJavaProjects(); 55 } catch (JavaModelException e) { 56 JavaPlugin.log(e); 57 } 58 return new Object [0]; 59 } 60 61 64 public Object getParent(Object element) { 65 66 IJavaElement parent= ((IJavaElement)element).getParent(); 67 if (parent instanceof IPackageFragmentRoot) { 68 IPackageFragmentRoot root= (IPackageFragmentRoot) parent; 69 if (root.getPath().equals(root.getJavaProject().getProject().getFullPath())) { 70 return root.getJavaProject(); 71 } 72 } 73 return parent; 74 } 75 76 79 public boolean hasChildren(Object element) { 80 return (getChildren(element).length > 0); 81 } 82 83 86 public void dispose() { 87 } 88 89 92 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 93 } 94 95 private Object [] getPackageFragmentRoots(IJavaProject project) throws JavaModelException { 96 ArrayList result= new ArrayList (); 97 98 IPackageFragmentRoot[] roots= project.getPackageFragmentRoots(); 99 for (int i= 0; i < roots.length; i++) { 100 IPackageFragmentRoot root= roots[i]; 101 if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { 102 if (root.getPath().equals(root.getJavaProject().getPath())) { 103 Object [] packageFragments= getPackageFragments(root); 104 for (int k= 0; k < packageFragments.length; k++) { 105 result.add(packageFragments[k]); 106 } 107 } else { 108 result.add(root); 109 } 110 } 111 } 112 return result.toArray(); 113 } 114 115 private Object [] getPackageFragments(IPackageFragmentRoot root) throws JavaModelException { 116 ArrayList packageFragments= new ArrayList (); 117 118 IJavaElement[] children= root.getChildren(); 119 for (int i= 0; i < children.length; i++) { 120 if (((IPackageFragment) children[i]).containsJavaResources()) 121 packageFragments.add(children[i]); 122 } 123 return packageFragments.toArray(); 124 } 125 } 126 | Popular Tags |