1 11 package org.eclipse.team.internal.ccvs.ui.subscriber; 12 13 import java.lang.reflect.InvocationTargetException ; 14 15 import org.eclipse.compare.structuremergeviewer.IDiffElement; 16 import org.eclipse.core.resources.*; 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IProgressMonitor; 19 import org.eclipse.team.core.TeamException; 20 import org.eclipse.team.core.synchronize.SyncInfo; 21 import org.eclipse.team.core.synchronize.SyncInfoSet; 22 import org.eclipse.team.internal.ccvs.core.CVSException; 23 import org.eclipse.team.internal.ccvs.core.client.Command; 24 import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption; 25 import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot; 26 import org.eclipse.team.internal.ccvs.ui.Policy; 27 import org.eclipse.team.internal.ccvs.ui.operations.ReplaceOperation; 28 import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; 29 30 33 public class WorkspaceUpdateOperation extends SafeUpdateOperation { 34 35 protected WorkspaceUpdateOperation(ISynchronizePageConfiguration configuration, IDiffElement[] elements, boolean promptBeforeUpdate) { 36 super(configuration, elements, promptBeforeUpdate); 37 } 38 39 42 protected void runUpdateDeletions(SyncInfo[] nodes, IProgressMonitor monitor) throws TeamException { 43 monitor.beginTask(null, nodes.length * 100); 44 for (int i = 0; i < nodes.length; i++) { 45 SyncInfo node = nodes[i]; 46 unmanage(node, Policy.subMonitorFor(monitor, 50)); 47 deleteAndKeepHistory(node.getLocal(), Policy.subMonitorFor(monitor, 50)); 48 } 49 pruneEmptyParents(nodes); 50 monitor.done(); 51 } 52 53 56 protected void runSafeUpdate(IProject project, SyncInfo[] nodes, IProgressMonitor monitor) throws TeamException { 57 safeUpdate(project, getIResourcesFrom(nodes), new LocalOption[] { Command.DO_NOT_RECURSE }, monitor); 58 } 59 60 63 protected void overwriteUpdate(SyncInfoSet syncSet, IProgressMonitor monitor) throws TeamException { 64 try { 65 new ReplaceOperation(getPart(), syncSet.getResources(), null , false ) 66 .run(monitor); 67 } catch (InvocationTargetException e) { 68 throw CVSException.wrapException(e); 69 } catch (InterruptedException e) { 70 Policy.cancelOperation(); 71 } 72 73 } 74 75 76 79 protected void updated(IResource[] resources) throws TeamException { 80 } 82 83 private void unmanage(SyncInfo element, IProgressMonitor monitor) throws CVSException { 84 CVSWorkspaceRoot.getCVSResourceFor(element.getLocal()).unmanage(monitor); 85 } 86 87 private void deleteAndKeepHistory(IResource resource, IProgressMonitor monitor) throws CVSException { 88 try { 89 if (!resource.exists()) return; 90 if (resource.getType() == IResource.FILE) 91 ((IFile)resource).delete(false , true , monitor); 92 else if (resource.getType() == IResource.FOLDER) 93 ((IFolder)resource).delete(false , true , monitor); 94 } catch (CoreException e) { 95 throw CVSException.wrapException(e); 96 } 97 } 98 99 } 100 | Popular Tags |