1 11 package org.eclipse.team.internal.core.subscribers; 12 13 import org.eclipse.core.resources.IResource; 14 import org.eclipse.core.runtime.IProgressMonitor; 15 import org.eclipse.team.core.ITeamStatus; 16 import org.eclipse.team.core.synchronize.*; 17 import org.eclipse.team.internal.core.Policy; 18 19 22 public class SyncSetInputFromSyncSet extends SyncSetInput implements ISyncInfoSetChangeListener { 23 24 SubscriberSyncInfoSet inputSyncSet; 25 26 public SyncSetInputFromSyncSet(SubscriberSyncInfoSet set, SubscriberEventHandler handler) { 27 super(handler); 28 this.inputSyncSet = set; 29 inputSyncSet.addSyncSetChangedListener(this); 30 } 31 32 public void disconnect() { 33 if (inputSyncSet == null) return; 34 inputSyncSet.removeSyncSetChangedListener(this); 35 inputSyncSet = null; 36 } 37 38 41 protected void fetchInput(IProgressMonitor monitor) { 42 if (inputSyncSet == null) return; 43 SyncInfo[] infos = inputSyncSet.getSyncInfos(); 44 for (int i = 0; i < infos.length; i++) { 45 collect(infos[i], monitor); 46 } 47 } 48 49 52 public void syncInfoChanged(ISyncInfoSetChangeEvent event, IProgressMonitor monitor) { 53 SyncInfoSet syncSet = getSyncSet(); 54 try { 55 syncSet.beginInput(); 56 monitor.beginTask(null, 105); 57 syncSetChanged(event.getChangedResources(), Policy.subMonitorFor(monitor, 50)); 58 syncSetChanged(event.getAddedResources(), Policy.subMonitorFor(monitor, 50)); 59 remove(event.getRemovedResources()); 60 } finally { 61 syncSet.endInput(Policy.subMonitorFor(monitor, 5)); 62 } 63 } 64 65 private void syncSetChanged(SyncInfo[] infos, IProgressMonitor monitor) { 66 for (int i = 0; i < infos.length; i++) { 67 collect(infos[i], monitor); 68 } 69 } 70 71 private void remove(IResource[] resources) { 72 for (int i = 0; i < resources.length; i++) { 73 remove(resources[i]); 74 } 75 } 76 77 public void reset() { 78 inputSyncSet.connect(this); 79 } 80 81 84 public void syncInfoSetReset(SyncInfoSet set, IProgressMonitor monitor) { 85 if(inputSyncSet == null) { 86 set.removeSyncSetChangedListener(this); 87 } else { 88 SyncInfoSet syncSet = getSyncSet(); 89 try { 90 syncSet.beginInput(); 91 monitor.beginTask(null, 100); 92 syncSet.clear(); 93 fetchInput(Policy.subMonitorFor(monitor, 95)); 94 } finally { 95 syncSet.endInput(Policy.subMonitorFor(monitor, 5)); 96 monitor.done(); 97 } 98 } 99 } 100 101 104 public void syncInfoSetErrors(SyncInfoSet set, ITeamStatus[] errors, IProgressMonitor monitor) { 105 SubscriberSyncInfoSet syncSet = getSyncSet(); 106 try { 107 syncSet.beginInput(); 108 for (int i = 0; i < errors.length; i++) { 109 ITeamStatus status = errors[i]; 110 syncSet.addError(status); 111 } 112 } finally { 113 syncSet.endInput(monitor); 114 } 115 } 116 } 117 | Popular Tags |