KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > subscriber > CompareRevertOperation


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.subscriber;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.HashSet JavaDoc;
15 import java.util.List JavaDoc;
16 import java.util.Set JavaDoc;
17
18 import org.eclipse.compare.structuremergeviewer.IDiffElement;
19 import org.eclipse.core.resources.IProject;
20 import org.eclipse.core.resources.IResource;
21 import org.eclipse.core.runtime.IProgressMonitor;
22 import org.eclipse.osgi.util.NLS;
23 import org.eclipse.team.core.TeamException;
24 import org.eclipse.team.core.synchronize.SyncInfo;
25 import org.eclipse.team.core.synchronize.SyncInfoSet;
26 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages;
27 import org.eclipse.team.internal.ccvs.ui.Policy;
28 import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
29
30
31 public class CompareRevertOperation extends CVSSubscriberOperation {
32     protected CompareRevertOperation(ISynchronizePageConfiguration configuration, IDiffElement[] elements) {
33         super(configuration, elements);
34     }
35     
36     /* (non-Javadoc)
37      * @see org.eclipse.team.internal.ccvs.ui.subscriber.CVSSubscriberAction#getJobName()
38      */

39     protected String JavaDoc getJobName() {
40         SyncInfoSet syncSet = getSyncInfoSet();
41         return NLS.bind(CVSUIMessages.CompareRevertAction_0, new String JavaDoc[] { new Integer JavaDoc(syncSet.size()).toString() });
42
43     }
44     
45     /* (non-Javadoc)
46      * @see org.eclipse.team.internal.ccvs.ui.subscriber.CVSSubscriberAction#run(org.eclipse.team.core.subscribers.MutableSyncInfoSet, org.eclipse.core.runtime.IProgressMonitor)
47      */

48     protected void runWithProjectRule(IProject project, SyncInfoSet syncSet, IProgressMonitor monitor) throws TeamException {
49         SyncInfo[] changed = syncSet.getSyncInfos();
50         if (changed.length == 0) return;
51         
52         if(! promptForOverwrite(syncSet)) return;
53         
54         // The list of sync resources to be updated using "cvs update"
55
List JavaDoc updateShallow = new ArrayList JavaDoc();
56         // A list of sync resource folders which need to be created locally
57
// (incoming addition or previously pruned)
58
Set JavaDoc parentCreationElements = new HashSet JavaDoc();
59     
60         for (int i = 0; i < changed.length; i++) {
61             SyncInfo changedNode = changed[i];
62             
63             // Make sure that parent folders exist
64
SyncInfo parent = getParent(changedNode);
65             if (parent != null && isOutOfSync(parent)) {
66                 // We need to ensure that parents that are either incoming folder additions
67
// or previously pruned folders are recreated.
68
parentCreationElements.add(parent);
69             }
70             
71             IResource resource = changedNode.getLocal();
72             if (resource.getType() == IResource.FILE) {
73                 if (changedNode.getLocal().exists()) {
74                     updateShallow.add(changedNode);
75                 } else if (changedNode.getRemote() != null) {
76                     updateShallow.add(changedNode);
77                 }
78             } else {
79                 // Special handling for folders to support shallow operations on files
80
// (i.e. folder operations are performed using the sync info already
81
// contained in the sync info.
82
if (isOutOfSync(changedNode)) {
83                     parentCreationElements.add(changedNode);
84                 }
85             }
86
87         }
88         try {
89             monitor.beginTask(null, 100);
90
91             if (parentCreationElements.size() > 0) {
92                 makeInSync((SyncInfo[]) parentCreationElements.toArray(new SyncInfo[parentCreationElements.size()]), Policy.subMonitorFor(monitor, 25));
93             }
94             if (updateShallow.size() > 0) {
95                 runUpdate((SyncInfo[])updateShallow.toArray(new SyncInfo[updateShallow.size()]), Policy.subMonitorFor(monitor, 75));
96             }
97         } finally {
98             monitor.done();
99         }
100         return;
101     }
102     
103     private void runUpdate(SyncInfo[] infos, IProgressMonitor monitor) throws TeamException {
104         monitor.beginTask(null, 100 * infos.length);
105         for (int i = 0; i < infos.length; i++) {
106             SyncInfo info = infos[i];
107             makeRemoteLocal(info, Policy.subMonitorFor(monitor, 100));
108         }
109         monitor.done();
110     }
111 }
112
Popular Tags