1 12 package org.eclipse.team.core; 13 14 import java.io.File ; 15 import java.net.URI ; 16 import java.util.*; 17 18 import org.eclipse.core.resources.IProject; 19 import org.eclipse.core.runtime.IProgressMonitor; 20 import org.eclipse.team.internal.core.Messages; 21 22 34 public abstract class ProjectSetCapability { 35 36 51 public static void ensureBackwardsCompatible(RepositoryProviderType type, ProjectSetCapability capability) { 52 if (capability != null) { 53 IProjectSetSerializer oldSerializer = Team.getProjectSetSerializer(type.getID()); 54 if (oldSerializer != null) { 55 capability.setSerializer(oldSerializer); 56 } 57 } 58 } 59 60 63 private IProjectSetSerializer serializer; 64 65 80 public void projectSetCreated(File file, Object context, IProgressMonitor monitor) { 81 } 83 84 98 public void projectSetCreated(File file, ProjectSetSerializationContext context, IProgressMonitor monitor) { 99 projectSetCreated(file, context.getShell(), monitor); 101 } 102 103 137 public String [] asReference( 138 IProject[] providerProjects, 139 ProjectSetSerializationContext context, 140 IProgressMonitor monitor) 141 throws TeamException { 142 143 if (serializer != null) { 144 return serializer.asReference(providerProjects, context.getShell(), monitor); 145 } 146 throw new TeamException(Messages.ProjectSetCapability_0); 147 } 148 149 187 public IProject[] addToWorkspace( 188 String [] referenceStrings, 189 ProjectSetSerializationContext context, 190 IProgressMonitor monitor) 191 throws TeamException { 192 193 if (serializer != null) { 194 return serializer.addToWorkspace(referenceStrings, context.getFilename(), context.getShell(), monitor); 195 } 196 throw new TeamException(Messages.ProjectSetCapability_1); 197 } 198 199 205 222 protected IProject[] confirmOverwrite( 223 ProjectSetSerializationContext context, 224 IProject[] projects) 225 throws TeamException { 226 227 229 final Collection existingProjects = new ArrayList(); 230 for (int i = 0; i < projects.length; i++) { 231 IProject eachProj = projects[i]; 232 if (eachProj.exists()) { 233 existingProjects.add(eachProj); 234 } else if (new File (eachProj.getParent().getLocation().toFile(), eachProj.getName()).exists()) { 235 existingProjects.add(eachProj); 236 } 237 } 238 if (existingProjects.size() == 0) 239 return projects; 240 241 243 IProject[] confirmed = 244 context.confirmOverwrite( 245 (IProject[]) existingProjects.toArray( 246 new IProject[existingProjects.size()])); 247 if (confirmed == null) 248 return null; 249 if (existingProjects.size() == confirmed.length) 250 return projects; 251 252 254 Collection result = new ArrayList(projects.length); 255 result.addAll(Arrays.asList(projects)); 256 result.removeAll(existingProjects); 257 for (int i = 0; i < confirmed.length; i++) { 258 IProject eachProj = confirmed[i]; 259 if (existingProjects.contains(eachProj)) 260 result.add(eachProj); 261 } 262 return (IProject[]) result.toArray(new IProject[result.size()]); 263 } 264 265 270 void setSerializer(IProjectSetSerializer serializer) { 271 this.serializer = serializer; 272 } 273 274 285 public URI getURI(String referenceString) { 286 return null; 287 } 288 289 300 public String getProject(String referenceString) { 301 return null; 302 } 303 304 315 public String asReference(URI uri, String projectName) { 316 return null; 317 } 318 } 319 | Popular Tags |