1 11 package org.eclipse.team.internal.ui.synchronize; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 15 16 import org.eclipse.compare.structuremergeviewer.IDiffElement; 17 import org.eclipse.core.runtime.IPath; 18 import org.eclipse.core.runtime.IProgressMonitor; 19 import org.eclipse.jface.resource.ImageDescriptor; 20 import org.eclipse.jface.util.IPropertyChangeListener; 21 import org.eclipse.jface.util.PropertyChangeEvent; 22 import org.eclipse.jface.viewers.ViewerSorter; 23 import org.eclipse.team.core.synchronize.*; 24 import org.eclipse.team.internal.core.subscribers.*; 25 import org.eclipse.team.internal.ui.*; 26 import org.eclipse.team.internal.ui.synchronize.actions.ChangeSetActionGroup; 27 import org.eclipse.team.ui.synchronize.*; 28 29 32 public class ChangeSetModelProvider extends CompositeModelProvider { 33 34 private ViewerSorter viewerSorter; 35 36 private final String subProvierId; 38 39 private Map rootToProvider = new HashMap (); 41 private ViewerSorter embeddedSorter; 42 43 private SyncInfoSetChangeSetCollector checkedInCollector; 44 45 private IChangeSetChangeListener changeSetListener = new IChangeSetChangeListener() { 46 47 50 public void setAdded(final ChangeSet set) { 51 final SyncInfoTree syncInfoSet; 52 if (set instanceof CheckedInChangeSet) { 54 syncInfoSet = checkedInCollector.getSyncInfoSet(set); 55 } else { 56 syncInfoSet = activeCollector.getSyncInfoSet(set); 57 } 58 if (syncInfoSet != null) 59 createChangeSetModelElement(set, syncInfoSet); 60 } 61 62 65 public void defaultSetChanged(final ChangeSet previousDefault, final ChangeSet set) { 66 refreshLabel(previousDefault); 67 refreshLabel(set); 68 } 69 70 73 public void setRemoved(final ChangeSet set) { 74 removeModelElementForSet(set); 75 } 76 77 80 public void nameChanged(final ChangeSet set) { 81 refreshLabel(set); 82 } 83 84 87 public void resourcesChanged(ChangeSet set, IPath[] paths) { 88 } 91 }; 92 93 private ActiveChangeSetCollector activeCollector; 94 95 98 public static class ChangeSetModelProviderDescriptor implements ISynchronizeModelProviderDescriptor { 99 public static final String ID = TeamUIPlugin.ID + ".modelprovider_cvs_changelog"; public String getId() { 101 return ID; 102 } 103 public String getName() { 104 return TeamUIMessages.ChangeLogModelProvider_5; 105 } 106 public ImageDescriptor getImageDescriptor() { 107 return TeamUIPlugin.getImageDescriptor(ITeamUIImages.IMG_CHANGE_SET); 108 } 109 }; 110 private static final ChangeSetModelProviderDescriptor descriptor = new ChangeSetModelProviderDescriptor(); 111 112 protected ChangeSetModelProvider(ISynchronizePageConfiguration configuration, SyncInfoSet set, String subProvierId) { 113 super(configuration, set); 114 this.subProvierId = subProvierId; 115 ChangeSetCapability changeSetCapability = getChangeSetCapability(); 116 if (changeSetCapability.supportsCheckedInChangeSets()) { 117 checkedInCollector = changeSetCapability.createSyncInfoSetChangeSetCollector(configuration); 118 checkedInCollector.setProvider(this); 119 checkedInCollector.addListener(changeSetListener); 120 } 121 if (changeSetCapability.supportsActiveChangeSets()) { 122 activeCollector = new ActiveChangeSetCollector(configuration, this); 123 activeCollector.setChangeSetChangeListener(changeSetListener); 124 configuration.addMenuGroup(ISynchronizePageConfiguration.P_CONTEXT_MENU, ChangeSetActionGroup.CHANGE_SET_GROUP); 125 } 126 } 127 128 131 protected void handleChanges(ISyncInfoTreeChangeEvent event, IProgressMonitor monitor) { 132 boolean handled = false; 133 if (checkedInCollector != null && getChangeSetCapability().enableCheckedInChangeSetsFor(getConfiguration())) { 134 checkedInCollector.handleChange(event); 135 handled = true; 136 } 137 if (activeCollector != null && getChangeSetCapability().enableActiveChangeSetsFor(getConfiguration())) { 138 activeCollector.handleChange(event); 139 handled = true; 140 } 141 if (!handled) { 142 ISynchronizeModelProvider provider = getProviderRootedAt(getModelRoot()); 144 if (provider != null) { 145 SyncInfoSet set = provider.getSyncInfoSet(); 146 try { 147 set.beginInput(); 148 set.removeAll(event.getRemovedResources()); 149 SyncInfo[] added = event.getAddedResources(); 150 for (int i = 0; i < added.length; i++) { 151 SyncInfo info = added[i]; 152 set.add(info); 153 } 154 SyncInfo[] changed = event.getChangedResources(); 155 for (int i = 0; i < changed.length; i++) { 156 SyncInfo info = changed[i]; 157 set.add(info); 158 } 159 } finally { 160 set.endInput(monitor); 161 } 162 } 163 } 164 } 165 166 169 protected void handleAddition(SyncInfo info) { 170 } 172 173 176 protected IDiffElement[] buildModelObjects(ISynchronizeModelElement node) { 177 180 if (node == getModelRoot()) { 181 182 if (checkedInCollector != null) { 184 checkedInCollector.reset(null); 185 checkedInCollector.removeListener(changeSetListener); 186 } 187 if (activeCollector != null) { 188 activeCollector.setChangeSetChangeListener(null); 189 activeCollector.reset(null); 190 } 191 192 boolean handled = false; 194 if (checkedInCollector != null && getChangeSetCapability().enableCheckedInChangeSetsFor(getConfiguration())) { 195 checkedInCollector.addListener(changeSetListener); 196 checkedInCollector.reset(getSyncInfoSet()); 197 handled = true; 198 } 199 if (activeCollector != null && getChangeSetCapability().enableActiveChangeSetsFor(getConfiguration())) { 200 activeCollector.setChangeSetChangeListener(changeSetListener); 201 activeCollector.reset(getSyncInfoSet()); 202 handled = true; 203 } 204 if (!handled) { 205 ISynchronizeModelProvider provider = getProviderRootedAt(getModelRoot()); 207 if (provider != null) { 208 ((SynchronizeModelProvider)provider).getSyncInfoSet().addAll(getSyncInfoSet()); 209 } 210 } 211 } 212 return new IDiffElement[0]; 213 } 214 215 218 public ISynchronizeModelProviderDescriptor getDescriptor() { 219 return descriptor; 220 } 221 222 225 public ViewerSorter getViewerSorter() { 226 if (viewerSorter == null) { 227 viewerSorter = new ChangeSetModelSorter(this, ChangeSetActionGroup.getSortCriteria(getConfiguration())); 228 } 229 return viewerSorter; 230 } 231 232 235 public void setViewerSorter(ViewerSorter viewerSorter) { 236 this.viewerSorter = viewerSorter; 237 firePropertyChange(ISynchronizeModelProvider.P_VIEWER_SORTER, null, null); 238 } 239 240 243 protected SynchronizePageActionGroup createActionGroup() { 244 return new ChangeSetActionGroup(this); 245 } 246 247 private ISynchronizeModelProvider createProviderRootedAt(ISynchronizeModelElement parent, SyncInfoTree set) { 248 ISynchronizeModelProvider provider = createModelProvider(parent, getSubproviderId(), set); 249 addProvider(provider); 250 rootToProvider.put(parent, provider); 251 return provider; 252 } 253 254 private ISynchronizeModelProvider getProviderRootedAt(ISynchronizeModelElement parent) { 255 return (ISynchronizeModelProvider)rootToProvider.get(parent); 256 } 257 258 261 protected void removeProvider(ISynchronizeModelProvider provider) { 262 rootToProvider.remove(provider.getModelRoot()); 263 super.removeProvider(provider); 264 } 265 266 270 public String getSubproviderId() { 271 return subProvierId; 272 } 273 274 278 public ViewerSorter getEmbeddedSorter() { 279 return embeddedSorter; 280 } 281 282 285 protected void recursiveClearModelObjects(ISynchronizeModelElement node) { 286 super.recursiveClearModelObjects(node); 287 if (node == getModelRoot()) { 288 rootToProvider.clear(); 289 embeddedSorter = null; 291 createRootProvider(); 292 } 293 } 294 295 301 private void createRootProvider() { 302 SyncInfoTree tree; 304 if (activeCollector != null && getChangeSetCapability().enableActiveChangeSetsFor(getConfiguration())) { 305 tree = activeCollector.getRootSet(); 307 } else { 308 tree = new SyncInfoTree(); 309 } 310 final ISynchronizeModelProvider provider = createProviderRootedAt(getModelRoot(), tree); 311 embeddedSorter = provider.getViewerSorter(); 312 if (provider instanceof AbstractSynchronizeModelProvider) { 313 SynchronizePageActionGroup actionGroup = ((AbstractSynchronizeModelProvider)provider).getActionGroup(); 314 if (actionGroup != null) { 315 getConfiguration().addActionContribution(actionGroup); 317 provider.addPropertyChangeListener(new IPropertyChangeListener() { 318 public void propertyChange(PropertyChangeEvent event) { 319 if (event.getProperty().equals(P_VIEWER_SORTER)) { 320 embeddedSorter = provider.getViewerSorter(); 321 ChangeSetModelProvider.this.firePropertyChange(P_VIEWER_SORTER, null, null); 322 } 323 } 324 }); 325 } 326 } 327 } 328 329 333 protected ISynchronizeModelElement getModelElement(ChangeSet set) { 334 IDiffElement[] children = getModelRoot().getChildren(); 335 for (int i = 0; i < children.length; i++) { 336 IDiffElement element = children[i]; 337 if (element instanceof ChangeSetDiffNode && ((ChangeSetDiffNode)element).getSet() == set) { 338 return (ISynchronizeModelElement)element; 339 } 340 } 341 return null; 342 } 343 344 347 public ChangeSetCapability getChangeSetCapability() { 348 ISynchronizeParticipant participant = getConfiguration().getParticipant(); 349 if (participant instanceof IChangeSetProvider) { 350 IChangeSetProvider provider = (IChangeSetProvider) participant; 351 return provider.getChangeSetCapability(); 352 } 353 return null; 354 } 355 356 public void dispose() { 357 if (checkedInCollector != null) { 358 checkedInCollector.removeListener(changeSetListener); 359 checkedInCollector.dispose(); 360 } 361 if (activeCollector != null) { 362 activeCollector.setChangeSetChangeListener(null); 363 activeCollector.dispose(); 364 } 365 super.dispose(); 366 } 367 368 369 public void waitUntilDone(IProgressMonitor monitor) { 370 super.waitUntilDone(monitor); 371 if (checkedInCollector != null) { 372 checkedInCollector.waitUntilDone(monitor); 373 super.waitUntilDone(monitor); 375 } 376 } 377 378 void removeModelElementForSet(final ChangeSet set) { 379 ISynchronizeModelElement node = getModelElement(set); 380 if (node != null) { 381 ISynchronizeModelProvider provider = getProviderRootedAt(node); 382 removeFromViewer(new ISynchronizeModelElement[] { node }); 383 removeProvider(provider); 384 } 385 } 386 387 public void createChangeSetModelElement(ChangeSet set, SyncInfoTree tree) { 388 ISynchronizeModelElement node = getModelElement(set); 390 ISynchronizeModelProvider provider = null; 391 if (node != null) { 392 provider = getProviderRootedAt(node); 393 } 394 if (provider == null) { 395 provider = createProvider(set, tree); 396 provider.prepareInput(null); 397 } 398 } 399 400 private ISynchronizeModelProvider createProvider(ChangeSet set, SyncInfoTree tree) { 401 ChangeSetDiffNode node = new ChangeSetDiffNode(getModelRoot(), set); 402 addToViewer(node); 403 return createProviderRootedAt(node, tree); 404 } 405 406 public void refreshLabel(ChangeSet set) { 407 ISynchronizeModelElement node = getModelElement(set); 408 if (node != null) { 409 getViewer().refresh(node); 410 } 411 } 412 } 413 | Popular Tags |