1 11 package org.eclipse.team.internal.ccvs.ui; 12 13 import java.util.HashSet ; 14 import java.util.Set ; 15 16 import org.eclipse.core.resources.IContainer; 17 import org.eclipse.core.resources.IResource; 18 import org.eclipse.core.resources.IWorkspaceRoot; 19 import org.eclipse.core.runtime.IPath; 20 import org.eclipse.core.runtime.Path; 21 import org.eclipse.jface.viewers.ITreeContentProvider; 22 import org.eclipse.ui.model.WorkbenchContentProvider; 23 24 28 public class AdaptableHierarchicalResourceList extends AdaptableResourceList { 29 private IContainer root; 30 31 35 public AdaptableHierarchicalResourceList(IContainer root, IResource[] resources) { 36 super(resources); 37 this.root = root; 38 } 39 40 43 public Object [] getChildren(Object o) { 44 return getChildenFor(root); 45 } 46 47 private IResource[] getChildenFor(IContainer parent) { 48 Set children = new HashSet (); 49 IPath parentPath = parent.getFullPath(); 50 for (int i = 0; i < resources.length; i++) { 51 IResource resource = resources[i]; 52 IPath resourcePath = resource.getFullPath(); 53 if (parent instanceof IWorkspaceRoot) { 54 children.add(((IWorkspaceRoot)parent).getProject(resourcePath.segment(0))); 55 } else if (parentPath.isPrefixOf(resourcePath)) { 56 IPath parentRelativePath = resourcePath.removeFirstSegments(parentPath.segmentCount()); 57 if (parentRelativePath.segmentCount() == 1) { 58 children.add(resource); 59 } else if (parentRelativePath.segmentCount() > 1) { 60 children.add(parent.getFolder(new Path(null, parentRelativePath.segment(0)))); 61 } 62 } 63 } 64 return (IResource[]) children.toArray(new IResource[children.size()]); 65 } 66 67 71 public ITreeContentProvider getTreeContentProvider() { 72 return new WorkbenchContentProvider() { 73 public Object [] getChildren(Object o) { 74 if (o instanceof IContainer) { 75 return getChildenFor((IContainer) o); 76 } else { 77 return super.getChildren(o); 78 } 79 } 80 }; 81 } 82 83 public void setResources(IResource[] resources) { 84 this.resources = resources; 85 } 86 87 91 public void setRoot(IContainer root) { 92 this.root = root; 93 } 94 95 } 96 | Popular Tags |