1 12 package org.eclipse.team.internal.ui.synchronize; 13 14 import java.util.HashMap ; 15 import java.util.Map ; 16 17 import org.eclipse.core.resources.mapping.ResourceMapping; 18 import org.eclipse.core.runtime.*; 19 import org.eclipse.team.core.diff.*; 20 import org.eclipse.team.core.mapping.IResourceDiffTree; 21 import org.eclipse.team.core.mapping.ISynchronizationContext; 22 import org.eclipse.team.internal.core.mapping.GroupProgressMonitor; 23 import org.eclipse.team.ui.synchronize.ISynchronizeParticipant; 24 import org.eclipse.team.ui.synchronize.ModelSynchronizeParticipant; 25 26 public class RefreshModelParticipantJob extends RefreshParticipantJob { 27 28 private final ResourceMapping[] mappings; 29 private IProgressMonitor group; 30 private int groupTicks; 31 32 public class ChangeDescription implements IChangeDescription, IDiffChangeListener { 33 Map changes = new HashMap (); 34 35 public int getChangeCount() { 36 return changes.size(); 37 } 38 39 public void diffsChanged(IDiffChangeEvent event, IProgressMonitor monitor) { 40 IDiff[] additions = event.getAdditions(); 41 for (int i = 0; i < additions.length; i++) { 42 IDiff node = additions[i]; 43 changes.put(node.getPath(), node); 44 } 45 IDiff[] changed = event.getChanges(); 46 for (int i = 0; i < changed.length; i++) { 47 IDiff node = changed[i]; 48 changes.put(node.getPath(), node); 49 } 50 } 51 52 public void propertyChanged(IDiffTree tree, int property, IPath[] paths) { 53 } 55 } 56 57 public RefreshModelParticipantJob(ISynchronizeParticipant participant, String jobName, String taskName, ResourceMapping[] mappings, IRefreshSubscriberListener listener) { 58 super(participant, jobName, taskName, listener); 59 this.mappings = mappings; 60 } 61 62 protected void doRefresh(IChangeDescription changeListener, 63 IProgressMonitor monitor) throws CoreException { 64 ISynchronizationContext context = ((ModelSynchronizeParticipant)getParticipant()).getContext(); 65 try { 66 context.getDiffTree().addDiffChangeListener((ChangeDescription)changeListener); 67 context.refresh(mappings, monitor); 69 try { 71 Platform.getJobManager().join(context, monitor); 72 } catch (InterruptedException e) { 73 } 75 } finally { 76 context.getDiffTree().removeDiffChangeListener((ChangeDescription)changeListener); 77 } 78 } 79 80 protected int getChangeCount() { 81 return ((ModelSynchronizeParticipant)getParticipant()).getContext().getDiffTree().size(); 82 } 83 84 protected int getIncomingChangeCount() { 85 IResourceDiffTree diffTree = ((ModelSynchronizeParticipant)getParticipant()).getContext().getDiffTree(); 86 return (int) diffTree.countFor(IThreeWayDiff.INCOMING, IThreeWayDiff.DIRECTION_MASK); 87 } 88 89 protected int getOutgoingChangeCount() { 90 IResourceDiffTree diffTree = ((ModelSynchronizeParticipant)getParticipant()).getContext().getDiffTree(); 91 return (int) diffTree.countFor(IThreeWayDiff.OUTGOING, IThreeWayDiff.DIRECTION_MASK); 92 } 93 94 protected void handleProgressGroupSet(IProgressMonitor group, int ticks) { 95 this.group = group; 96 this.groupTicks = ticks; 97 } 98 99 protected IChangeDescription createChangeDescription() { 100 return new ChangeDescription(); 101 } 102 103 public boolean belongsTo(Object family) { 104 if (family instanceof RefreshModelParticipantJob) { 105 RefreshModelParticipantJob rmpj = (RefreshModelParticipantJob) family; 106 return rmpj.getParticipant() == getParticipant(); 107 } 108 if (family == getParticipant()) 109 return true; 110 return super.belongsTo(family); 111 } 112 113 public IStatus run(IProgressMonitor monitor) { 114 if (group != null) 115 monitor = wrapMonitorWithGroup(monitor); 116 return super.run(monitor); 117 } 118 119 private IProgressMonitor wrapMonitorWithGroup(IProgressMonitor monitor) { 120 return new GroupProgressMonitor(monitor, group, groupTicks); 121 } 122 123 } 124 | Popular Tags |