1 11 package org.eclipse.team.internal.ccvs.ui.operations; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.core.resources.IResource; 17 import org.eclipse.core.resources.mapping.ResourceMapping; 18 import org.eclipse.core.runtime.IProgressMonitor; 19 import org.eclipse.core.runtime.IStatus; 20 import org.eclipse.osgi.util.NLS; 21 import org.eclipse.team.core.TeamException; 22 import org.eclipse.team.core.diff.IDiff; 23 import org.eclipse.team.core.diff.IThreeWayDiff; 24 import org.eclipse.team.core.history.IFileRevision; 25 import org.eclipse.team.core.mapping.IResourceDiffTree; 26 import org.eclipse.team.core.variants.IResourceVariant; 27 import org.eclipse.team.internal.ccvs.core.*; 28 import org.eclipse.team.internal.ccvs.core.client.*; 29 import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption; 30 import org.eclipse.team.internal.ccvs.core.client.listeners.IUpdateMessageListener; 31 import org.eclipse.team.internal.ccvs.core.client.listeners.UpdateListener; 32 import org.eclipse.team.internal.ccvs.core.resources.RemoteFile; 33 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages; 34 import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin; 35 import org.eclipse.team.internal.ui.Utils; 36 import org.eclipse.ui.IWorkbenchPart; 37 38 42 public abstract class CacheTreeContentsOperation extends SingleCommandOperation { 43 44 private final IResourceDiffTree tree; 45 46 public CacheTreeContentsOperation(IWorkbenchPart part, ResourceMapping[] mappings, IResourceDiffTree tree) { 47 super(part, mappings, Command.NO_LOCAL_OPTIONS); 48 this.tree = tree; 49 } 50 51 54 protected void execute(CVSTeamProvider provider, IResource[] resources, boolean recurse, IProgressMonitor monitor) throws CVSException, InterruptedException { 55 IResource[] files = getFilesWithUncachedContents(resources, recurse); 56 if (files.length > 0) 57 super.execute(provider, files, recurse, monitor); 58 } 59 60 private IResource[] getFilesWithUncachedContents(IResource[] resources, boolean recurse) { 61 ArrayList result = new ArrayList (); 62 for (int i = 0; i < resources.length; i++) { 63 IResource resource = resources[i]; 64 IDiff[] nodes = tree.getDiffs(resource, recurse ? IResource.DEPTH_INFINITE: IResource.DEPTH_ONE); 65 for (int j = 0; j < nodes.length; j++) { 66 IDiff node = nodes[j]; 67 if (needsContents(node)) { 68 result.add(tree.getResource(node)); 69 } 70 } 71 } 72 return (IResource[]) result.toArray(new IResource[result.size()]); 73 } 74 75 protected boolean needsContents(IDiff node) { 76 if (node instanceof IThreeWayDiff) { 77 IThreeWayDiff twd = (IThreeWayDiff) node; 78 IResource local = getTree().getResource(node); 79 IFileRevision remote = getRemoteFileState(twd); 80 if (remote != null) { 81 IResourceVariant variant = (IResourceVariant)Utils.getAdapter(remote, IResourceVariant.class); 82 if (local.getType() == IResource.FILE 83 && isEnabledForDirection(twd.getDirection()) 84 && variant instanceof RemoteFile) { 85 RemoteFile rf = (RemoteFile) variant; 86 if (!rf.isContentsCached()) { 87 return true; 88 } 89 } 90 } 91 } 92 return false; 93 } 94 95 100 protected abstract IFileRevision getRemoteFileState(IThreeWayDiff twd); 101 102 107 protected abstract boolean isEnabledForDirection(int direction); 108 109 116 protected ICVSFolder getLocalRoot(CVSTeamProvider provider) 117 throws CVSException { 118 try { 119 ICVSRemoteResource tree = buildTree(provider); 120 return (ICVSFolder)tree; 121 } catch (TeamException e) { 122 throw CVSException.wrapException(e); 123 } 124 } 125 126 protected abstract ICVSRemoteResource buildTree(CVSTeamProvider provider) throws TeamException; 127 128 131 protected ICVSResource[] getCVSArguments(Session session, IResource[] resources) { 132 List result = new ArrayList (); 133 for (int i = 0; i < resources.length; i++) { 134 IResource resource = resources[i]; 135 try { 136 ICVSResource file = session.getLocalRoot().getChild(resource.getProjectRelativePath().toString()); 137 result.add(file); 138 } catch (CVSException e) { 139 CVSUIPlugin.log(e); 141 } 142 } 143 144 return (ICVSResource[]) result.toArray(new ICVSResource[result.size()]); 145 } 146 147 150 protected IStatus executeCommand(Session session, CVSTeamProvider provider, ICVSResource[] resources, boolean recurse, IProgressMonitor monitor) throws CVSException, InterruptedException { 151 return Command.UPDATE.execute( 152 session, 153 Command.NO_GLOBAL_OPTIONS, 154 getLocalOptions(true), 155 resources, 156 new UpdateListener(new IUpdateMessageListener() { 157 public void fileInformation(int type, ICVSFolder parent, String filename) { 158 } 160 public void fileDoesNotExist(ICVSFolder parent, String filename) { 161 } 163 public void directoryInformation(ICVSFolder commandRoot, String path, 164 boolean newDirectory) { 165 } 167 public void directoryDoesNotExist(ICVSFolder commandRoot, String path) { 168 } 170 }), 171 monitor); 172 } 173 174 177 protected LocalOption[] getLocalOptions(boolean recurse) { 178 return Update.IGNORE_LOCAL_CHANGES.addTo(super.getLocalOptions(recurse)); 179 } 180 181 184 protected String getTaskName(CVSTeamProvider provider) { 185 return NLS.bind(CVSUIMessages.CacheTreeContentsOperation_0, new String [] {provider.getProject().getName()}); 186 } 187 188 191 protected String getTaskName() { 192 return CVSUIMessages.CacheTreeContentsOperation_1; 193 } 194 195 199 protected IResourceDiffTree getTree() { 200 return tree; 201 } 202 203 206 public boolean consultModelsForMappings() { 207 return false; 208 } 209 210 213 protected boolean isReportableError(IStatus status) { 214 return super.isReportableError(status) && status.getSeverity() == IStatus.ERROR; 215 } 216 217 } 218 | Popular Tags |