1 11 package org.eclipse.ltk.ui.refactoring.model; 12 13 import java.util.HashSet ; 14 import java.util.Iterator ; 15 import java.util.Set ; 16 17 import org.eclipse.team.core.diff.IDiff; 18 import org.eclipse.team.core.diff.IDiffVisitor; 19 import org.eclipse.team.core.diff.IThreeWayDiff; 20 import org.eclipse.team.core.diff.ITwoWayDiff; 21 import org.eclipse.team.core.history.IFileRevision; 22 import org.eclipse.team.core.mapping.IResourceDiff; 23 import org.eclipse.team.core.mapping.IResourceDiffTree; 24 import org.eclipse.team.core.mapping.ISynchronizationContext; 25 import org.eclipse.team.ui.mapping.SynchronizationContentProvider; 26 27 import org.eclipse.core.runtime.Assert; 28 import org.eclipse.core.runtime.IProgressMonitor; 29 import org.eclipse.core.runtime.NullProgressMonitor; 30 import org.eclipse.core.runtime.SubProgressMonitor; 31 32 import org.eclipse.core.resources.IProject; 33 import org.eclipse.core.resources.IResource; 34 35 import org.eclipse.ltk.core.refactoring.RefactoringDescriptor; 36 import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy; 37 import org.eclipse.ltk.core.refactoring.history.RefactoringHistory; 38 39 import org.eclipse.ltk.internal.core.refactoring.history.RefactoringDescriptorProxyAdapter; 40 import org.eclipse.ltk.internal.core.refactoring.history.RefactoringHistoryImplementation; 41 import org.eclipse.ltk.internal.core.refactoring.history.RefactoringHistoryService; 42 import org.eclipse.ltk.internal.ui.refactoring.RefactoringUIMessages; 43 import org.eclipse.ltk.internal.ui.refactoring.model.RefactoringDescriptorDiff; 44 import org.eclipse.ltk.internal.ui.refactoring.model.RefactoringDescriptorSynchronizationProxy; 45 46 66 public abstract class AbstractSynchronizationContentProvider extends SynchronizationContentProvider { 67 68 86 protected RefactoringHistory getRefactorings(final ISynchronizationContext context, final IProject project, IProgressMonitor monitor) { 87 Assert.isNotNull(context); 88 Assert.isNotNull(project); 89 if (monitor == null) 90 monitor= new NullProgressMonitor(); 91 try { 92 monitor.beginTask(RefactoringUIMessages.RefactoringModelMerger_retrieving_refactorings, IProgressMonitor.UNKNOWN); 93 final IProgressMonitor finalMonitor= monitor; 94 final Set result= new HashSet (); 95 final IResourceDiffTree tree= context.getDiffTree(); 96 tree.accept(project.getFolder(RefactoringHistoryService.NAME_HISTORY_FOLDER).getFullPath(), new IDiffVisitor() { 97 98 public final boolean visit(final IDiff diff) { 99 if (diff instanceof IThreeWayDiff) { 100 final IThreeWayDiff threeWay= (IThreeWayDiff) diff; 101 final Set localDescriptors= new HashSet (); 102 final Set remoteDescriptors= new HashSet (); 103 final ITwoWayDiff localDiff= threeWay.getLocalChange(); 104 if (localDiff instanceof IResourceDiff && localDiff.getKind() != IDiff.NO_CHANGE) { 105 final IResourceDiff resourceDiff= (IResourceDiff) localDiff; 106 final IFileRevision revision= resourceDiff.getAfterState(); 107 if (revision != null) { 108 final String name= revision.getName(); 109 if (name.equalsIgnoreCase(RefactoringHistoryService.NAME_HISTORY_FILE)) 110 AbstractResourceMappingMerger.getRefactoringDescriptors(revision, localDescriptors, new SubProgressMonitor(finalMonitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)); 111 } 112 } 113 final ITwoWayDiff remoteDiff= threeWay.getLocalChange(); 114 if (remoteDiff instanceof IResourceDiff && remoteDiff.getKind() != IDiff.NO_CHANGE) { 115 final IResourceDiff resourceDiff= (IResourceDiff) remoteDiff; 116 final IFileRevision revision= resourceDiff.getAfterState(); 117 if (revision != null) { 118 final String name= revision.getName(); 119 if (name.equalsIgnoreCase(RefactoringHistoryService.NAME_HISTORY_FILE)) 120 AbstractResourceMappingMerger.getRefactoringDescriptors(revision, remoteDescriptors, new SubProgressMonitor(finalMonitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)); 121 } 122 } 123 final Set local= new HashSet (localDescriptors); 124 local.removeAll(remoteDescriptors); 125 for (final Iterator iterator= local.iterator(); iterator.hasNext();) { 126 final RefactoringDescriptor descriptor= (RefactoringDescriptor) iterator.next(); 127 result.add(new RefactoringDescriptorSynchronizationProxy(new RefactoringDescriptorProxyAdapter(descriptor), project.getName(), IThreeWayDiff.OUTGOING)); 128 } 129 final Set remote= new HashSet (remoteDescriptors); 130 remote.removeAll(localDescriptors); 131 for (final Iterator iterator= remote.iterator(); iterator.hasNext();) { 132 final RefactoringDescriptor descriptor= (RefactoringDescriptor) iterator.next(); 133 result.add(new RefactoringDescriptorSynchronizationProxy(new RefactoringDescriptorProxyAdapter(descriptor), project.getName(), IThreeWayDiff.INCOMING)); 134 } 135 } 136 return true; 137 } 138 }, IResource.DEPTH_INFINITE); 139 140 for (final Iterator iterator= result.iterator(); iterator.hasNext();) { 141 final RefactoringDescriptorSynchronizationProxy proxy= (RefactoringDescriptorSynchronizationProxy) iterator.next(); 142 if (!isVisible(new RefactoringDescriptorDiff(proxy, IDiff.CHANGE, proxy.getDirection()))) 143 result.remove(proxy); 144 } 145 146 return new RefactoringHistoryImplementation((RefactoringDescriptorProxy[]) result.toArray(new RefactoringDescriptorProxy[result.size()])); 147 } finally { 148 monitor.done(); 149 } 150 } 151 } 152 | Popular Tags |