1 11 package org.eclipse.team.internal.ccvs.ui.model; 12 13 import org.eclipse.core.runtime.IAdaptable; 14 import org.eclipse.core.runtime.IProgressMonitor; 15 import org.eclipse.core.runtime.jobs.ISchedulingRule; 16 import org.eclipse.jface.resource.ImageDescriptor; 17 import org.eclipse.team.core.TeamException; 18 import org.eclipse.team.internal.ccvs.core.*; 19 import org.eclipse.team.internal.ccvs.ui.*; 20 import org.eclipse.ui.model.IWorkbenchAdapter; 21 import org.eclipse.ui.progress.IDeferredWorkbenchAdapter; 22 import org.eclipse.ui.progress.IElementCollector; 23 24 public class VersionCategory extends CVSModelElement implements IAdaptable, 25 IDeferredWorkbenchAdapter { 26 private ICVSRepositoryLocation repository; 27 28 31 public VersionCategory(ICVSRepositoryLocation repo) { 32 super(); 33 this.repository = repo; 34 } 35 36 40 public Object getAdapter(Class adapter) { 41 if (adapter == IWorkbenchAdapter.class) 42 return this; 43 if (adapter == IDeferredWorkbenchAdapter.class) 44 return this; 45 return null; 46 } 47 48 53 public Object [] fetchChildren(Object o, IProgressMonitor monitor) 54 throws TeamException { 55 if (CVSUIPlugin.getPlugin().getRepositoryManager() 56 .isDisplayingProjectVersions(repository)) { 57 return getProjectVersionChildren(o, monitor); 58 } else { 59 return getVersionTagChildren(o, monitor); 60 } 61 } 62 63 66 private Object [] getVersionTagChildren(Object o, IProgressMonitor monitor) 67 throws CVSException { 68 CVSTag[] tags = CVSUIPlugin.getPlugin().getRepositoryManager() 69 .getKnownTags(repository, getWorkingSet(), CVSTag.VERSION, monitor); 70 CVSTagElement[] versionElements = new CVSTagElement[tags.length]; 71 for (int i = 0; i < tags.length; i++) { 72 versionElements[i] = new CVSTagElement(tags[i], repository); 73 } 74 return versionElements; 75 } 76 77 81 private Object [] getProjectVersionChildren(Object o, 82 IProgressMonitor monitor) throws TeamException { 83 84 ICVSRemoteResource[] resources = CVSUIPlugin.getPlugin() 85 .getRepositoryManager().getFoldersForTag(repository, 86 CVSTag.DEFAULT, monitor); 87 if (getWorkingSet() != null) 88 resources = CVSUIPlugin.getPlugin().getRepositoryManager() 89 .filterResources(getWorkingSet(), resources); 90 Object [] modules = new Object [resources.length]; 91 for (int i = 0; i < resources.length; i++) { 92 modules[i] = new RemoteModule((ICVSRemoteFolder) resources[i], 93 VersionCategory.this); 94 } 95 return modules; 96 } 97 98 104 public ImageDescriptor getImageDescriptor(Object object) { 105 return CVSUIPlugin.getPlugin().getImageDescriptor( 106 ICVSUIConstants.IMG_VERSIONS_CATEGORY); 107 } 108 109 116 public String getLabel(Object o) { 117 return CVSUIMessages.VersionCategory_Versions_1; 118 } 119 120 126 public Object getParent(Object o) { 127 return repository; 128 } 129 130 133 public ICVSRepositoryLocation getRepository(Object o) { 134 return repository; 135 } 136 137 public void fetchDeferredChildren(Object o, IElementCollector collector, 138 IProgressMonitor monitor) { 139 try { 140 collector.add(fetchChildren(o, monitor), monitor); 141 } catch (TeamException e) { 142 handle(collector, e); 143 } 144 } 145 146 public boolean isContainer() { 147 return true; 148 } 149 150 public ISchedulingRule getRule(Object element) { 151 return new RepositoryLocationSchedulingRule(repository); 152 } 153 } 154 | Popular Tags |