1 11 package org.eclipse.team.internal.ui.mapping; 12 13 import java.util.HashSet ; 14 import java.util.Set ; 15 16 import org.eclipse.core.resources.*; 17 import org.eclipse.core.resources.mapping.RemoteResourceMappingContext; 18 import org.eclipse.core.resources.mapping.ResourceTraversal; 19 import org.eclipse.core.runtime.*; 20 import org.eclipse.team.core.diff.IDiff; 21 import org.eclipse.team.core.diff.IThreeWayDiff; 22 import org.eclipse.team.core.mapping.IResourceDiff; 23 import org.eclipse.team.core.mapping.ISynchronizationContext; 24 import org.eclipse.team.ui.mapping.SynchronizationContentProvider; 25 26 34 public final class SynchronizationResourceMappingContext extends 35 RemoteResourceMappingContext { 36 37 private final ISynchronizationContext context; 38 39 43 public SynchronizationResourceMappingContext(ISynchronizationContext context) { 44 this.context = context; 45 } 46 47 50 public boolean isThreeWay() { 51 return context.getType() == ISynchronizationContext.THREE_WAY; 52 } 53 54 57 public boolean hasRemoteChange(IResource resource, IProgressMonitor monitor) throws CoreException { 58 IDiff diff = context.getDiffTree().getDiff(resource); 59 if (diff instanceof IThreeWayDiff) { 60 IThreeWayDiff twd = (IThreeWayDiff) diff; 61 IDiff remote = twd.getRemoteChange(); 62 return remote != null && remote.getKind() != IDiff.NO_CHANGE; 63 } 64 return diff != null && diff.getKind() != IDiff.NO_CHANGE; 65 } 66 67 70 public boolean hasLocalChange(IResource resource, IProgressMonitor monitor) throws CoreException { 71 IDiff diff = context.getDiffTree().getDiff(resource); 72 if (diff instanceof IThreeWayDiff) { 73 IThreeWayDiff twd = (IThreeWayDiff) diff; 74 IDiff local = twd.getLocalChange(); 75 return local != null && local.getKind() != IDiff.NO_CHANGE; 76 } 77 return false; 78 } 79 80 83 public IStorage fetchRemoteContents(IFile file, IProgressMonitor monitor) throws CoreException { 84 IDiff diff = context.getDiffTree().getDiff(file); 85 if (diff instanceof IThreeWayDiff) { 86 IThreeWayDiff twd = (IThreeWayDiff) diff; 87 IDiff remote = twd.getRemoteChange(); 88 if (remote instanceof IResourceDiff) { 89 IResourceDiff rd = (IResourceDiff) remote; 90 return rd.getAfterState().getStorage(monitor); 91 } 92 } else if (diff instanceof IResourceDiff) { 93 IResourceDiff rd = (IResourceDiff) diff; 94 return rd.getAfterState().getStorage(monitor); 95 } 96 return file; 97 } 98 99 102 public IStorage fetchBaseContents(IFile file, IProgressMonitor monitor) throws CoreException { 103 IDiff diff = context.getDiffTree().getDiff(file); 104 if (diff instanceof IThreeWayDiff) { 105 IThreeWayDiff twd = (IThreeWayDiff) diff; 106 IDiff remote = twd.getRemoteChange(); 107 if (remote instanceof IResourceDiff) { 108 IResourceDiff rd = (IResourceDiff) remote; 109 return rd.getBeforeState().getStorage(monitor); 110 } 111 IDiff local = twd.getLocalChange(); 112 if (local instanceof IResourceDiff) { 113 IResourceDiff rd = (IResourceDiff) local; 114 return rd.getBeforeState().getStorage(monitor); 115 } 116 } 117 return null; 118 } 119 120 public IResource[] fetchMembers(IContainer container, IProgressMonitor monitor) throws CoreException { 121 Set result = new HashSet (); 122 IResource[] children = container.members(); 123 for (int i = 0; i < children.length; i++) { 124 IResource resource = children[i]; 125 result.add(resource); 126 } 127 IPath[] childPaths = context.getDiffTree().getChildren(container.getFullPath()); 128 for (int i = 0; i < childPaths.length; i++) { 129 IPath path = childPaths[i]; 130 IDiff delta = context.getDiffTree().getDiff(path); 131 IResource child; 132 if (delta == null) { 133 if (path.segmentCount() == 1) { 135 child = ((IWorkspaceRoot)container).getProject(path.lastSegment()); 136 } else { 137 child = container.getFolder(new Path(path.lastSegment())); 138 } 139 } else { 140 child = context.getDiffTree().getResource(delta); 141 } 142 result.add(child); 143 } 144 return (IResource[]) result.toArray(new IResource[result.size()]); 145 } 146 147 public void refresh(ResourceTraversal[] traversals, int flags, IProgressMonitor monitor) throws CoreException { 148 } 150 151 public ISynchronizationContext getSynchronizationContext() { 152 return context; 153 } 154 155 public IProject[] getProjects() { 156 Set projects = new HashSet (); 157 IResource[] roots = context.getScope().getRoots(); 158 for (int i = 0; i < roots.length; i++) { 159 IResource resource = roots[i]; 160 projects.add(resource.getProject()); 161 } 162 return (IProject[]) projects.toArray(new IProject[projects.size()]); 163 } 164 165 } 166 | Popular Tags |