1 11 package org.eclipse.team.internal.ccvs.ui.operations; 12 13 import java.util.ArrayList ; 14 import java.util.HashMap ; 15 import java.util.Iterator ; 16 import java.util.List ; 17 import java.util.Map ; 18 import java.util.Set ; 19 20 import org.eclipse.core.runtime.IProgressMonitor; 21 import org.eclipse.team.internal.ccvs.core.*; 22 import org.eclipse.team.internal.ccvs.ui.Policy; 23 import org.eclipse.ui.IWorkbenchPart; 24 25 28 public abstract class RepositoryLocationOperation extends RemoteOperation { 29 30 protected RepositoryLocationOperation(IWorkbenchPart part, ICVSRemoteResource[] remoteResources) { 31 super(part, remoteResources); 32 } 33 34 37 public void execute(IProgressMonitor monitor) throws CVSException, InterruptedException { 38 Map table = getLocationMapping(getRemoteResources()); 39 Set keySet = table.keySet(); 40 monitor.beginTask(null, keySet.size() * 100); 41 Iterator iterator = keySet.iterator(); 42 while (iterator.hasNext()) { 43 ICVSRepositoryLocation location = (ICVSRepositoryLocation)iterator.next(); 44 List list = (List )table.get(location); 45 ICVSRemoteResource[] remoteResources = (ICVSRemoteResource[])list.toArray(new ICVSRemoteResource[list.size()]); 46 execute(location, remoteResources, Policy.subMonitorFor(monitor, 100)); 47 } 48 } 49 50 57 protected abstract void execute(ICVSRepositoryLocation location, ICVSRemoteResource[] resources, IProgressMonitor monitor) throws CVSException; 58 59 63 private Map getLocationMapping(ICVSRemoteResource[] remoteResources) { 64 Map locationsMap = new HashMap (); 65 for (int i = 0; i < remoteResources.length; i++) { 66 ICVSRemoteResource resource = remoteResources[i]; 67 ICVSRepositoryLocation location = resource.getRepository(); 68 List resources = (List )locationsMap.get(location); 69 if (resources == null) { 70 resources = new ArrayList (); 71 locationsMap.put(location, resources); 72 } 73 resources.add(resource); 74 } 75 return locationsMap; 76 } 77 78 } 79 | Popular Tags |