KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > core > mapping > ScopeManagerEventHandler


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.core.mapping;
12
13 import java.util.HashSet JavaDoc;
14 import java.util.Set JavaDoc;
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 JavaDoc toRefresh = new HashSet JavaDoc();
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 JavaDoc getJobFamiliy() {
76         return manager;
77     }
78 }
79
Popular Tags