KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.eclipse.compare.structuremergeviewer.IDiffElement;
14 import org.eclipse.core.resources.IProject;
15 import org.eclipse.core.runtime.IProgressMonitor;
16 import org.eclipse.core.runtime.IStatus;
17 import org.eclipse.osgi.util.NLS;
18 import org.eclipse.team.core.TeamException;
19 import org.eclipse.team.core.synchronize.SyncInfo;
20 import org.eclipse.team.core.synchronize.SyncInfoSet;
21 import org.eclipse.team.internal.ccvs.core.CVSException;
22 import org.eclipse.team.internal.ccvs.core.CVSSyncInfo;
23 import org.eclipse.team.internal.ccvs.core.ICVSFolder;
24 import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
25 import org.eclipse.team.internal.ccvs.ui.*;
26 import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
27
28 /**
29  * This action marks the local resource as merged by updating the base
30  * resource revision to match the remote resource revision
31  */

32 public class ConfirmMergedOperation extends CVSSubscriberOperation {
33
34     public ConfirmMergedOperation(ISynchronizePageConfiguration configuration, IDiffElement[] elements) {
35         super(configuration, elements);
36     }
37
38     /* (non-Javadoc)
39      * @see org.eclipse.team.internal.ui.actions.TeamOperation#getJobName()
40      */

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

49     protected void runWithProjectRule(IProject project, SyncInfoSet syncSet, IProgressMonitor monitor) throws CVSException {
50         SyncInfo[] syncResources = syncSet.getSyncInfos();
51         monitor.beginTask(null, 100 * syncResources.length);
52         try {
53             for (int i = 0; i < syncResources.length; i++) {
54                 SyncInfo info = syncResources[i];
55                 if (!makeOutgoing(info, Policy.subMonitorFor(monitor, 100))) {
56                     // Failure was logged in makeOutgoing
57
}
58             }
59         } catch (TeamException e) {
60             handle(e);
61         } finally {
62             monitor.done();
63         }
64     }
65
66     private boolean makeOutgoing(SyncInfo info, IProgressMonitor monitor) throws CVSException, TeamException {
67         monitor.beginTask(null, 100);
68         try {
69             CVSSyncInfo cvsInfo = getCVSSyncInfo(info);
70             if (cvsInfo == null) {
71                 CVSUIPlugin.log(IStatus.ERROR, NLS.bind(CVSUIMessages.SubscriberConfirmMergedAction_0, new String JavaDoc[] { info.getLocal().getFullPath().toString() }), null);
72                 return false;
73             }
74             // Make sure the parent is managed
75
ICVSFolder parent = CVSWorkspaceRoot.getCVSFolderFor(cvsInfo.getLocal().getParent());
76             if (!parent.isCVSFolder()) {
77                 // the parents must be made outgoing before the child can
78
SyncInfo parentInfo = cvsInfo.getSubscriber().getSyncInfo(parent.getIResource());
79                 if (!makeOutgoing(parentInfo, Policy.subMonitorFor(monitor, 20))) {
80                     return false;
81                 }
82             }
83             IStatus status = cvsInfo.makeOutgoing(Policy.subMonitorFor(monitor, 80));
84             if (status.getSeverity() == IStatus.ERROR) {
85                 logError(status);
86                 return false;
87             }
88             return true;
89         } finally {
90             monitor.done();
91         }
92     }
93 }
94
Popular Tags