1 12 package org.eclipse.team.internal.ccvs.ui.operations; 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 import java.util.Set ; 17 18 import org.eclipse.core.resources.*; 19 import org.eclipse.core.resources.mapping.ResourceMapping; 20 import org.eclipse.core.runtime.*; 21 import org.eclipse.core.runtime.Status; 22 import org.eclipse.osgi.util.NLS; 23 import org.eclipse.team.internal.ccvs.core.*; 24 import org.eclipse.team.internal.ccvs.core.client.*; 25 import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption; 26 import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo; 27 import org.eclipse.team.internal.ccvs.core.util.PrepareForReplaceVisitor; 28 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages; 29 import org.eclipse.team.internal.ccvs.ui.Policy; 30 import org.eclipse.ui.IWorkbenchPart; 31 32 35 public class ReplaceOperation extends UpdateOperation { 36 37 public ReplaceOperation(IWorkbenchPart part, IResource[] resources, CVSTag tag, boolean recurse) { 38 super(part, asResourceMappers(resources, recurse ? IResource.DEPTH_INFINITE : IResource.DEPTH_ONE), new LocalOption[] { Update.IGNORE_LOCAL_CHANGES }, tag); 39 } 40 41 public ReplaceOperation(IWorkbenchPart part, ResourceMapping[] mappings, CVSTag tag) { 42 super(part, mappings, new LocalOption[] { Update.IGNORE_LOCAL_CHANGES }, tag); 43 } 44 45 48 protected String getTaskName() { 49 return CVSUIMessages.ReplaceOperation_taskName; 50 } 51 52 55 protected IStatus executeCommand( 56 final Session session, 57 final CVSTeamProvider provider, 58 final ICVSResource[] resources, 59 final boolean recurse, IProgressMonitor monitor) 60 throws CVSException, InterruptedException { 61 62 final IStatus[] status = new IStatus[] { Status.OK_STATUS }; 63 try { 64 ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { 65 public void run(IProgressMonitor monitor) throws CoreException { 66 try { 67 status[0] = internalExecuteCommand(session, provider, resources, recurse, monitor); 68 } catch (InterruptedException e) { 69 throw new OperationCanceledException(); 70 } 71 } 72 73 }, null, IWorkspace.AVOID_UPDATE, monitor); 74 } catch (CoreException e) { 75 throw CVSException.wrapException(e); 76 } 77 return status[0]; 78 } 79 80 private Set prepDeletedFiles; 82 83 private IStatus internalExecuteCommand(Session session, CVSTeamProvider provider, ICVSResource[] resources, boolean recurse, IProgressMonitor monitor) throws CVSException, InterruptedException { 84 monitor.beginTask(null, 100); 85 ICVSResource[] managedResources = getResourcesToUpdate(resources); 86 try { 87 PrepareForReplaceVisitor pfrv = new PrepareForReplaceVisitor(session, getTag()); 89 pfrv.visitResources( 90 provider.getProject(), 91 resources, 92 CVSUIMessages.ReplaceOperation_1, 93 recurse ? IResource.DEPTH_INFINITE : IResource.DEPTH_ONE, 94 Policy.subMonitorFor(monitor, 30)); 95 prepDeletedFiles = pfrv.getDeletedFiles(); 96 97 IStatus status = OK; 99 if (managedResources.length > 0) { 100 status = super.executeCommand(session, provider, managedResources, recurse, Policy.subMonitorFor(monitor, 70)); 102 } 103 104 if (status.isOK() && CVSProviderPlugin.getPlugin().getPruneEmptyDirectories()) { 107 new PruneFolderVisitor().visit(session, resources); 108 } 109 110 return status; 111 } finally { 112 monitor.done(); 113 } 114 } 115 116 123 protected ICVSResource[] getResourcesToUpdate(ICVSResource[] resources) throws CVSException { 124 List managedResources = new ArrayList (); 126 for (int i = 0; i < resources.length; i++) { 127 ICVSResource resource = resources[i]; 128 if ((resource.isFolder() && ((ICVSFolder)resource).isCVSFolder())) { 129 managedResources.add(resource); 130 } else if (!resource.isFolder()){ 131 byte[] syncBytes = ((ICVSFile)resource).getSyncBytes(); 132 if (syncBytes != null && !ResourceSyncInfo.isAddition(syncBytes)) { 133 managedResources.add(resource); 134 } 135 } 136 } 137 return (ICVSResource[]) managedResources.toArray(new ICVSResource[managedResources.size()]); 138 } 139 140 143 protected Update getUpdateCommand() { 144 return new Replace(prepDeletedFiles); 147 } 148 149 152 protected String getTaskName(CVSTeamProvider provider) { 153 return NLS.bind(CVSUIMessages.ReplaceOperation_0, new String [] { provider.getProject().getName() }); 154 } 155 } 156 | Popular Tags |