1 11 package org.eclipse.ui.internal.ide.misc; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.core.resources.IContainer; 17 import org.eclipse.core.resources.IProject; 18 import org.eclipse.core.resources.IResource; 19 import org.eclipse.core.resources.IWorkspace; 20 import org.eclipse.core.runtime.CoreException; 21 import org.eclipse.jface.viewers.ITreeContentProvider; 22 import org.eclipse.jface.viewers.Viewer; 23 24 27 public class ContainerContentProvider implements ITreeContentProvider { 28 private boolean showClosedProjects = true; 29 30 33 public ContainerContentProvider() { 34 } 35 36 40 public void dispose() { 41 } 42 43 46 public Object [] getChildren(Object element) { 47 if (element instanceof IWorkspace) { 48 IProject[] allProjects = ((IWorkspace) element).getRoot() 50 .getProjects(); 51 if (showClosedProjects) { 52 return allProjects; 53 } 54 55 ArrayList accessibleProjects = new ArrayList (); 56 for (int i = 0; i < allProjects.length; i++) { 57 if (allProjects[i].isOpen()) { 58 accessibleProjects.add(allProjects[i]); 59 } 60 } 61 return accessibleProjects.toArray(); 62 } else if (element instanceof IContainer) { 63 IContainer container = (IContainer) element; 64 if (container.isAccessible()) { 65 try { 66 List children = new ArrayList (); 67 IResource[] members = container.members(); 68 for (int i = 0; i < members.length; i++) { 69 if (members[i].getType() != IResource.FILE) { 70 children.add(members[i]); 71 } 72 } 73 return children.toArray(); 74 } catch (CoreException e) { 75 } 77 } 78 } 79 return new Object [0]; 80 } 81 82 85 public Object [] getElements(Object element) { 86 return getChildren(element); 87 } 88 89 92 public Object getParent(Object element) { 93 if (element instanceof IResource) { 94 return ((IResource) element).getParent(); 95 } 96 return null; 97 } 98 99 102 public boolean hasChildren(Object element) { 103 return getChildren(element).length > 0; 104 } 105 106 109 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 110 } 111 112 118 public void showClosedProjects(boolean show) { 119 showClosedProjects = show; 120 } 121 122 } 123 | Popular Tags |