KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > operations > RepositoryLocationOperation


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ccvs.ui.operations;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.HashMap JavaDoc;
15 import java.util.Iterator JavaDoc;
16 import java.util.List JavaDoc;
17 import java.util.Map JavaDoc;
18 import java.util.Set JavaDoc;
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 /**
26  * Operation that divides the resources by location
27  */

28 public abstract class RepositoryLocationOperation extends RemoteOperation {
29     
30     protected RepositoryLocationOperation(IWorkbenchPart part, ICVSRemoteResource[] remoteResources) {
31         super(part, remoteResources);
32     }
33     
34     /* (non-Javadoc)
35      * @see org.eclipse.team.internal.ccvs.ui.operations.CVSOperation#execute(org.eclipse.core.runtime.IProgressMonitor)
36      */

37     public void execute(IProgressMonitor monitor) throws CVSException, InterruptedException JavaDoc {
38         Map JavaDoc table = getLocationMapping(getRemoteResources());
39         Set JavaDoc keySet = table.keySet();
40         monitor.beginTask(null, keySet.size() * 100);
41         Iterator JavaDoc iterator = keySet.iterator();
42         while (iterator.hasNext()) {
43             ICVSRepositoryLocation location = (ICVSRepositoryLocation)iterator.next();
44             List JavaDoc list = (List JavaDoc)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     /**
51      * Perform the operation for the given resources found on the
52      * given repository.
53      * @param location the repository location
54      * @param resources the resources of this operation found in the repository
55      * @param monitor a progres monitor
56      */

57     protected abstract void execute(ICVSRepositoryLocation location, ICVSRemoteResource[] resources, IProgressMonitor monitor) throws CVSException;
58
59     /*
60      * Return a map that maps a location to all the resources
61      * from the given list that are located in that repository.
62      */

63     private Map JavaDoc getLocationMapping(ICVSRemoteResource[] remoteResources) {
64         Map JavaDoc locationsMap = new HashMap JavaDoc();
65         for (int i = 0; i < remoteResources.length; i++) {
66             ICVSRemoteResource resource = remoteResources[i];
67             ICVSRepositoryLocation location = resource.getRepository();
68             List JavaDoc resources = (List JavaDoc)locationsMap.get(location);
69             if (resources == null) {
70                 resources = new ArrayList JavaDoc();
71                 locationsMap.put(location, resources);
72             }
73             resources.add(resource);
74         }
75         return locationsMap;
76     }
77
78 }
79
Popular Tags