1 11 package org.eclipse.team.internal.core.mapping; 12 13 import java.util.HashSet ; 14 import java.util.Set ; 15 16 import org.eclipse.core.resources.mapping.ResourceMapping; 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IProgressMonitor; 19 import org.eclipse.osgi.util.NLS; 20 import org.eclipse.team.core.TeamException; 21 import org.eclipse.team.core.mapping.ISynchronizationScopeManager; 22 import org.eclipse.team.core.mapping.provider.SynchronizationScopeManager; 23 import org.eclipse.team.internal.core.BackgroundEventHandler; 24 import org.eclipse.team.internal.core.Messages; 25 26 public class ScopeManagerEventHandler extends BackgroundEventHandler { 27 28 public static final int REFRESH = 10; 29 private Set toRefresh = new HashSet (); 30 private ISynchronizationScopeManager manager; 31 32 class ResourceMappingEvent extends Event { 33 private final ResourceMapping[] mappings; 34 public ResourceMappingEvent(ResourceMapping[] mappings) { 35 super(REFRESH); 36 this.mappings = mappings; 37 } 38 } 39 40 public ScopeManagerEventHandler(SynchronizationScopeManager manager) { 41 super(NLS.bind(Messages.ScopeManagerEventHandler_0, manager.getName()), NLS.bind(Messages.ScopeManagerEventHandler_1, manager.getName())); 42 this.manager = manager; 43 } 44 45 protected boolean doDispatchEvents(IProgressMonitor monitor) 46 throws TeamException { 47 ResourceMapping[] mappings = (ResourceMapping[]) toRefresh.toArray(new ResourceMapping[toRefresh.size()]); 48 toRefresh.clear(); 49 if (mappings.length > 0) { 50 try { 51 manager.refresh(mappings, monitor); 52 } catch (CoreException e) { 53 throw TeamException.asTeamException(e); 54 } 55 } 56 return mappings.length > 0; 57 } 58 59 protected void processEvent(Event event, IProgressMonitor monitor) 60 throws CoreException { 61 if (event instanceof ResourceMappingEvent) { 62 ResourceMappingEvent rme = (ResourceMappingEvent) event; 63 for (int i = 0; i < rme.mappings.length; i++) { 64 ResourceMapping mapping = rme.mappings[i]; 65 toRefresh.add(mapping); 66 } 67 } 68 69 } 70 71 public void refresh(ResourceMapping[] mappings) { 72 queueEvent(new ResourceMappingEvent(mappings), false); 73 } 74 75 protected Object getJobFamiliy() { 76 return manager; 77 } 78 } 79 | Popular Tags |