1 11 package org.eclipse.team.internal.ui.synchronize; 12 13 import java.util.ArrayList ; 14 import java.util.Arrays ; 15 import java.util.List ; 16 17 import org.eclipse.core.resources.IResource; 18 import org.eclipse.core.resources.IWorkspaceRunnable; 19 import org.eclipse.core.runtime.IProgressMonitor; 20 import org.eclipse.team.core.ITeamStatus; 21 import org.eclipse.team.core.synchronize.*; 22 import org.eclipse.team.internal.core.subscribers.*; 23 import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; 24 25 36 public abstract class SyncInfoSetChangeSetCollector extends ChangeSetManager { 37 38 private final ISynchronizePageConfiguration configuration; 39 private ChangeSetModelProvider provider; 40 41 47 ISyncInfoSetChangeListener changeSetListener = new ISyncInfoSetChangeListener() { 48 49 52 public void syncInfoSetReset(SyncInfoSet set, IProgressMonitor monitor) { 53 handleChangeEvent(set); 54 } 55 56 59 public void syncInfoChanged(ISyncInfoSetChangeEvent event, IProgressMonitor monitor) { 60 handleChangeEvent(event.getSet()); 61 } 62 63 66 public void syncInfoSetErrors(SyncInfoSet set, ITeamStatus[] errors, IProgressMonitor monitor) { 67 } 69 70 73 private void handleChangeEvent(SyncInfoSet set) { 74 if (set.isEmpty()) { 75 ChangeSet changeSet = getChangeSet(set); 76 if (changeSet != null) { 77 remove(changeSet); 78 } 79 } 80 } 81 }; 82 83 88 public SyncInfoSetChangeSetCollector(ISynchronizePageConfiguration configuration) { 89 this.configuration = configuration; 90 } 91 92 107 protected abstract void add(SyncInfo[] infos); 108 109 124 protected void remove(IResource[] resources) { 125 ChangeSet[] sets = getSets(); 126 for (int i = 0; i < sets.length; i++) { 127 ChangeSet set = sets[i]; 128 set.remove(resources); 129 } 130 } 131 132 135 protected ISyncInfoSetChangeListener getChangeSetChangeListener() { 136 return changeSetListener; 137 } 138 139 157 public void reset(SyncInfoSet seedSet) { 158 ChangeSet[] sets = getSets(); 160 for (int i = 0; i < sets.length; i++) { 161 ChangeSet set2 = sets[i]; 162 remove(set2); 163 } 164 if (seedSet != null) { 165 add(seedSet.getSyncInfos()); 166 } 167 } 168 169 183 public void handleChange(ISyncInfoSetChangeEvent event) { 184 List removals = new ArrayList (); 185 List additions = new ArrayList (); 186 removals.addAll(Arrays.asList(event.getRemovedResources())); 187 additions.addAll(Arrays.asList(event.getAddedResources())); 188 SyncInfo[] changed = event.getChangedResources(); 189 for (int i = 0; i < changed.length; i++) { 190 SyncInfo info = changed[i]; 191 additions.add(info); 192 removals.add(info.getLocal()); 193 } 194 if (!removals.isEmpty()) { 195 remove((IResource[]) removals.toArray(new IResource[removals.size()])); 196 } 197 if (!additions.isEmpty()) { 198 add((SyncInfo[]) additions.toArray(new SyncInfo[additions.size()])); 199 } 200 } 201 202 208 public final ISynchronizePageConfiguration getConfiguration() { 209 return configuration; 210 } 211 212 229 protected final void performUpdate(IWorkspaceRunnable runnable, boolean preserveExpansion, IProgressMonitor monitor) { 230 provider.performUpdate(runnable, preserveExpansion, false ); 231 } 232 233 236 public final void setProvider(ChangeSetModelProvider provider) { 237 this.provider = provider; 238 } 239 240 246 public void waitUntilDone(IProgressMonitor monitor) { 247 } 249 250 protected void handleSetAdded(ChangeSet set) { 251 ((CheckedInChangeSet)set).getSyncInfoSet().addSyncSetChangedListener(getChangeSetChangeListener()); 252 super.handleSetAdded(set); 253 } 254 255 protected void handleSetRemoved(ChangeSet set) { 256 ((CheckedInChangeSet)set).getSyncInfoSet().removeSyncSetChangedListener(getChangeSetChangeListener()); 257 super.handleSetRemoved(set); 258 } 259 260 266 protected ChangeSet getChangeSet(SyncInfoSet set) { 267 ChangeSet[] sets = getSets(); 268 for (int i = 0; i < sets.length; i++) { 269 ChangeSet changeSet = sets[i]; 270 if (((CheckedInChangeSet)changeSet).getSyncInfoSet() == set) { 271 return changeSet; 272 } 273 } 274 return null; 275 } 276 277 public SyncInfoTree getSyncInfoSet(ChangeSet set) { 278 return ((CheckedInChangeSet)set).getSyncInfoSet(); 279 } 280 } 281 | Popular Tags |