1 11 package org.eclipse.jdt.internal.ui.model; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.core.runtime.CoreException; 17 18 import org.eclipse.core.resources.IFolder; 19 20 import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy; 21 import org.eclipse.ltk.core.refactoring.history.RefactoringHistory; 22 23 import org.eclipse.jdt.core.ICompilationUnit; 24 import org.eclipse.jdt.core.IJavaProject; 25 26 import org.eclipse.jdt.ui.StandardJavaElementContentProvider; 27 28 33 public final class JavaModelContentProvider extends StandardJavaElementContentProvider { 34 35 36 private static final String NAME_SETTINGS_FOLDER= ".settings"; 38 41 public JavaModelContentProvider() { 42 super(true); 43 } 44 45 48 public Object [] getChildren(final Object element) { 49 if (element instanceof ICompilationUnit) 50 return NO_CHILDREN; 51 else if (element instanceof RefactoringHistory) 52 return ((RefactoringHistory) element).getDescriptors(); 53 else if (element instanceof IJavaProject) { 54 final List elements= new ArrayList (); 55 elements.add(((IJavaProject) element).getProject().getFolder(NAME_SETTINGS_FOLDER)); 56 final Object [] children= super.getChildren(element); 57 for (int index= 0; index < children.length; index++) { 58 if (!elements.contains(children[index])) 59 elements.add(children[index]); 60 } 61 return elements.toArray(); 62 } else if (element instanceof IFolder) { 63 final IFolder folder= (IFolder) element; 64 try { 65 return folder.members(); 66 } catch (CoreException exception) { 67 } 69 } 70 return super.getChildren(element); 71 } 72 73 76 public boolean hasChildren(final Object element) { 77 if (element instanceof ICompilationUnit) 78 return false; 79 else if (element instanceof RefactoringHistory) 80 return true; 81 else if (element instanceof RefactoringDescriptorProxy) 82 return false; 83 else if (element instanceof IFolder) 84 return true; 85 return super.hasChildren(element); 86 } 87 } 88 | Popular Tags |