KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > core > mapping > provider > SynchronizationContext


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.core.mapping.provider;
12
13 import org.eclipse.core.resources.IResource;
14 import org.eclipse.core.resources.mapping.ResourceMapping;
15 import org.eclipse.core.resources.mapping.ResourceTraversal;
16 import org.eclipse.core.runtime.*;
17 import org.eclipse.team.core.ICache;
18 import org.eclipse.team.core.mapping.*;
19 import org.eclipse.team.internal.core.Cache;
20 import org.eclipse.team.internal.core.Policy;
21
22 /**
23  * Abstract implementation of the {@link ISynchronizationContext} interface.
24  * This class can be subclassed by clients.
25  *
26  * @see ISynchronizationContext
27  * @since 3.2
28  */

29 public abstract class SynchronizationContext extends PlatformObject implements ISynchronizationContext {
30
31     private final int type;
32     private final IResourceDiffTree diffTree;
33     private Cache cache;
34     private final ISynchronizationScopeManager manager;
35
36     /**
37      * Create a synchronization context.
38      * @param manager the manager that defines the scope of the synchronization
39      * @param type the type of synchronization (ONE_WAY or TWO_WAY)
40      * @param diffTree the sync info tree that contains all out-of-sync resources
41      */

42     protected SynchronizationContext(ISynchronizationScopeManager manager, int type, IResourceDiffTree diffTree) {
43         this.manager = manager;
44         this.type = type;
45         this.diffTree = diffTree;
46     }
47     
48     /**
49      * {@inheritDoc}
50      */

51     public ISynchronizationScope getScope() {
52         return getScopeManager().getScope();
53     }
54
55     /**
56      * Return the scope manager for the scope of this context.
57      * @return the scope manager for the scope of this context
58      */

59     public ISynchronizationScopeManager getScopeManager() {
60         return manager;
61     }
62     
63     /**
64      * {@inheritDoc}
65      */

66     public int getType() {
67         return type;
68     }
69
70     /**
71      * {@inheritDoc}
72      */

73     public void dispose() {
74         if (cache != null) {
75             cache.dispose();
76         }
77         manager.dispose();
78     }
79
80     /**
81      * {@inheritDoc}
82      */

83     public synchronized ICache getCache() {
84         if (cache == null) {
85             cache = new Cache();
86         }
87         return cache;
88     }
89     
90     /**
91      * {@inheritDoc}
92      */

93     public IResourceDiffTree getDiffTree() {
94         return diffTree;
95     }
96     
97     /**
98      * {@inheritDoc}
99      */

100     public void refresh(ResourceMapping[] mappings, IProgressMonitor monitor) throws CoreException {
101         monitor.beginTask(null, 100);
102         ISynchronizationScopeManager manager = getScopeManager();
103         if (manager == null) {
104             // The scope manager is missing so just refresh everything
105
refresh(getScope().getTraversals(), IResource.NONE, Policy.subMonitorFor(monitor, 50));
106         } else {
107             ResourceTraversal[] traversals = manager.refresh(mappings, Policy.subMonitorFor(monitor, 50));
108             if (traversals.length > 0)
109                 refresh(traversals, IResource.NONE, Policy.subMonitorFor(monitor, 50));
110         }
111         monitor.done();
112     }
113
114 }
115
Popular Tags