1 11 package org.eclipse.team.internal.ccvs.ui.model; 12 13 import java.util.HashMap ; 14 15 import org.eclipse.jface.viewers.AbstractTreeViewer; 16 import org.eclipse.jface.viewers.Viewer; 17 import org.eclipse.team.internal.ccvs.core.*; 18 import org.eclipse.team.internal.ccvs.core.resources.RemoteFolderTree; 19 import org.eclipse.team.internal.ccvs.core.resources.RemoteResource; 20 import org.eclipse.team.internal.ccvs.ui.repo.RepositoryRoot; 21 import org.eclipse.ui.IWorkingSet; 22 import org.eclipse.ui.model.WorkbenchContentProvider; 23 import org.eclipse.ui.progress.DeferredTreeContentManager; 24 25 31 public class RemoteContentProvider extends WorkbenchContentProvider { 32 33 IWorkingSet workingSet; 34 DeferredTreeContentManager manager; 35 36 HashMap cachedTrees; 37 38 public RemoteContentProvider(){ 39 cachedTrees = new HashMap (); 40 } 41 42 45 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 46 if (viewer instanceof AbstractTreeViewer) { 47 manager = new DeferredTreeContentManager(this, (AbstractTreeViewer) viewer); 48 } 49 super.inputChanged(viewer, oldInput, newInput); 50 } 51 52 public boolean hasChildren(Object element) { 53 if (element instanceof ICVSRemoteResource) { 56 if (element instanceof ICVSRemoteFolder) { 57 return ((ICVSRemoteFolder) element).isExpandable(); 58 } 59 return ((ICVSRemoteResource) element).isContainer(); 60 } else if (element instanceof CVSResourceElement) { 61 ICVSResource r = ((CVSResourceElement) element).getCVSResource(); 62 if (r instanceof RemoteResource) { 63 return r.isFolder(); 64 } 65 } else if (element instanceof VersionCategory) { 66 return true; 67 } else if (element instanceof BranchCategory) { 68 return true; 69 } else if (element instanceof CVSTagElement) { 70 return true; 71 } else if (element instanceof RemoteModule) { 72 return true; 73 } 74 if (manager != null) { 75 if (manager.isDeferredAdapter(element)) 76 return manager.mayHaveChildren(element); 77 } 78 79 return super.hasChildren(element); 80 } 81 82 86 public void setWorkingSet(IWorkingSet workingSet) { 87 this.workingSet = workingSet; 88 } 89 90 94 public IWorkingSet getWorkingSet() { 95 return workingSet; 96 } 97 98 101 public Object [] getChildren(Object element) { 102 Object tree = cachedTrees.get(element); 104 if (tree != null) { 105 return ((RemoteFolderTree) tree).getChildren(); 106 } 107 108 if (manager != null) { 109 Object [] children = manager.getChildren(element); 110 if (children != null) { 111 return children; 114 } 115 } 116 Object [] children = super.getChildren(element); 117 for (int i = 0; i < children.length; i++) { 118 Object object = children[i]; 119 if (object instanceof CVSModelElement) 120 ((CVSModelElement)object).setWorkingSet(getWorkingSet()); 121 } 122 return children; 123 } 124 125 public void cancelJobs(RepositoryRoot[] roots) { 126 if (manager != null) { 127 for (int i = 0; i < roots.length; i++) { 128 RepositoryRoot root = roots[i]; 129 cancelJobs(root.getRoot()); 130 } 131 } 132 } 133 134 138 public void cancelJobs(ICVSRepositoryLocation location) { 139 if (manager != null) { 140 manager.cancel(location); 141 } 142 } 143 144 149 public void addCachedTree(ICVSRemoteFolder project, RemoteFolderTree tree){ 150 cachedTrees.put(project, tree); 151 } 152 153 public void purgeCache(){ 154 cachedTrees.clear(); 155 } 156 157 158 } 159 | Popular Tags |