1 11 package org.eclipse.team.core.subscribers; 12 13 import org.eclipse.core.resources.IResource; 14 import org.eclipse.core.resources.IWorkspaceRunnable; 15 import org.eclipse.core.resources.mapping.ResourceTraversal; 16 import org.eclipse.core.runtime.*; 17 import org.eclipse.team.core.diff.DiffFilter; 18 import org.eclipse.team.core.mapping.ISynchronizationScopeManager; 19 import org.eclipse.team.core.mapping.provider.MergeContext; 20 import org.eclipse.team.core.mapping.provider.ResourceDiffTree; 21 import org.eclipse.team.core.synchronize.SyncInfo; 22 import org.eclipse.team.internal.core.mapping.GroupProgressMonitor; 23 import org.eclipse.team.internal.core.subscribers.SubscriberDiffTreeEventHandler; 24 25 35 public abstract class SubscriberMergeContext extends MergeContext { 36 37 private Subscriber subscriber; 38 private SubscriberDiffTreeEventHandler handler; 39 private final ISynchronizationScopeManager manager; 40 41 46 protected SubscriberMergeContext(Subscriber subscriber, ISynchronizationScopeManager manager) { 47 super(manager, getType(subscriber), new ResourceDiffTree()); 48 this.subscriber = subscriber; 49 this.manager = manager; 50 } 51 52 private static int getType(Subscriber subscriber) { 53 return subscriber.getResourceComparator().isThreeWay() 54 ? THREE_WAY : TWO_WAY; 55 } 56 57 61 protected void initialize() { 62 handler = new SubscriberDiffTreeEventHandler(subscriber, manager, (ResourceDiffTree)getDiffTree(), getDiffFilter()); 63 handler.setJobFamily(this); 64 handler.start(); 65 } 66 67 72 protected DiffFilter getDiffFilter() { 73 return null; 74 } 75 76 79 public void refresh(ResourceTraversal[] traversals, int flags, 80 IProgressMonitor monitor) throws CoreException { 81 GroupProgressMonitor group = getGroup(monitor); 82 if (group != null) 83 handler.setProgressGroupHint(group.getGroup(), group.getTicks()); 84 handler.initializeIfNeeded(); 85 subscriber.refresh(traversals, monitor); 86 } 87 88 private GroupProgressMonitor getGroup(IProgressMonitor monitor) { 89 if (monitor instanceof GroupProgressMonitor) { 90 return (GroupProgressMonitor) monitor; 91 } 92 if (monitor instanceof ProgressMonitorWrapper) { 93 ProgressMonitorWrapper wrapper = (ProgressMonitorWrapper) monitor; 94 return getGroup(wrapper.getWrappedProgressMonitor()); 95 } 96 return null; 97 } 98 99 102 public void dispose() { 103 handler.shutdown(); 104 super.dispose(); 105 } 106 107 113 protected SyncInfo getSyncInfo(IResource resource) throws CoreException { 114 return handler.getSubscriber().getSyncInfo(resource); 115 } 116 117 121 public Subscriber getSubscriber() { 122 return subscriber; 123 } 124 125 131 protected void runInBackground(IWorkspaceRunnable runnable) { 132 handler.run(runnable, false); 133 } 134 135 138 public Object getAdapter(Class adapter) { 139 if (adapter == SubscriberDiffTreeEventHandler.class) 140 return handler; 141 return super.getAdapter(adapter); 142 } 143 144 } 145 | Popular Tags |