1 11 package org.eclipse.team.internal.ccvs.ui.subscriber; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.compare.structuremergeviewer.IDiffElement; 17 import org.eclipse.core.resources.*; 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.IProgressMonitor; 20 import org.eclipse.osgi.util.NLS; 21 import org.eclipse.team.core.TeamException; 22 import org.eclipse.team.core.subscribers.Subscriber; 23 import org.eclipse.team.core.synchronize.SyncInfo; 24 import org.eclipse.team.core.synchronize.SyncInfoSet; 25 import org.eclipse.team.internal.ccvs.core.CVSException; 26 import org.eclipse.team.internal.ccvs.core.CVSMergeSubscriber; 27 import org.eclipse.team.internal.ccvs.core.CVSSyncInfo; 28 import org.eclipse.team.internal.ccvs.core.CVSTag; 29 import org.eclipse.team.internal.ccvs.core.client.Command; 30 import org.eclipse.team.internal.ccvs.core.client.Update; 31 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages; 32 import org.eclipse.team.internal.ccvs.ui.Policy; 33 import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; 34 35 39 public class MergeUpdateOperation extends SafeUpdateOperation { 40 41 Subscriber currentSubcriber = null; 42 43 protected MergeUpdateOperation(ISynchronizePageConfiguration configuration, IDiffElement[] elements, boolean promptBeforeUpdate) { 44 super(configuration, elements, promptBeforeUpdate); 45 } 46 47 50 protected String getJobName() { 51 SyncInfoSet syncSet = getSyncInfoSet(); 52 return NLS.bind(CVSUIMessages.MergeUpdateAction_jobName, new String [] { new Integer (syncSet.size()).toString() }); 53 } 54 55 58 protected boolean getOverwriteLocalChanges() { 59 return true; 60 } 61 62 65 protected void updated(IResource[] resources) throws TeamException { 66 if(resources.length > 0 && currentSubcriber != null) { 68 ((CVSMergeSubscriber)currentSubcriber).merged(resources); 69 } 70 } 71 72 75 protected void runUpdateDeletions(SyncInfo[] nodes, IProgressMonitor monitor) throws TeamException { 76 try { 80 monitor.beginTask(null, 100 * nodes.length); 81 for (int i = 0; i < nodes.length; i++) { 82 IResource resource = nodes[i].getLocal(); 83 if (resource.getType() == IResource.FILE) { 84 ((IFile)resource).delete(false , true , Policy.subMonitorFor(monitor, 100)); 85 } 86 } 87 } catch (CoreException e) { 88 throw CVSException.wrapException(e); 89 } finally { 90 monitor.done(); 91 } 92 } 93 94 97 protected void runSafeUpdate(IProject project, SyncInfo[] nodes, IProgressMonitor monitor) throws TeamException { 98 if(nodes.length > 0) { 99 setSubscriber(nodes[0]); 100 CVSTag startTag = ((CVSMergeSubscriber)currentSubcriber).getStartTag(); 101 CVSTag endTag = ((CVSMergeSubscriber)currentSubcriber).getEndTag(); 102 103 List additions = new ArrayList (); 105 List changes = new ArrayList (); 106 for (int i = 0; i < nodes.length; i++) { 107 SyncInfo resource = nodes[i]; 108 int kind = resource.getKind(); 109 if ((kind & SyncInfo.CHANGE_MASK) == SyncInfo.ADDITION) { 110 additions.add(resource); 111 } else { 112 changes.add(resource); 113 } 114 } 115 116 try { 117 monitor.beginTask(null, (additions.size() + changes.size()) * 100); 118 if (!additions.isEmpty()) { 119 safeUpdate( 120 project, 121 getIResourcesFrom((SyncInfo[]) additions.toArray(new SyncInfo[additions.size()])), 122 new Command.LocalOption[] { 123 Command.DO_NOT_RECURSE, 124 Command.makeArgumentOption(Update.JOIN, endTag.getName()) 125 }, 126 Policy.subMonitorFor(monitor, additions.size() * 100)); 127 } 128 if (!changes.isEmpty()) { 129 safeUpdate( 130 project, 131 getIResourcesFrom((SyncInfo[]) changes.toArray(new SyncInfo[changes.size()])), 132 new Command.LocalOption[] { 133 Command.DO_NOT_RECURSE, 134 Command.makeArgumentOption(Update.JOIN, startTag.getName()), 135 Command.makeArgumentOption(Update.JOIN, endTag.getName()) 136 }, 137 Policy.subMonitorFor(monitor, changes.size() * 100)); 138 } 139 } finally { 140 monitor.done(); 141 } 142 } 143 } 144 145 149 private void setSubscriber(SyncInfo node) throws CVSException { 150 currentSubcriber = ((CVSSyncInfo)node).getSubscriber(); 152 if (!(currentSubcriber instanceof CVSMergeSubscriber)) { 153 throw new CVSException(NLS.bind(CVSUIMessages.MergeUpdateAction_invalidSubscriber, new String [] { currentSubcriber.toString() })); 154 } 155 } 156 157 160 protected void overwriteUpdate(SyncInfoSet set, IProgressMonitor monitor) throws TeamException { 161 SyncInfo[] nodes = set.getSyncInfos(); 162 if (nodes.length == 0) return; 163 setSubscriber(nodes[0]); 164 monitor.beginTask(null, 1000 * nodes.length); 165 try { 166 for (int i = 0; i < nodes.length; i++) { 167 makeRemoteLocal(nodes[i], Policy.subMonitorFor(monitor, 1000)); 168 } 169 } finally { 170 monitor.done(); 171 } 172 } 173 } 174 | Popular Tags |