KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > core > subscribers > SyncSetInput


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.internal.core.subscribers;
12
13 import org.eclipse.core.resources.IResource;
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.eclipse.team.core.TeamException;
16 import org.eclipse.team.core.synchronize.*;
17 import org.eclipse.team.internal.core.Policy;
18
19 /**
20  * This is the superclass for all SyncSet input providers
21  */

22 public abstract class SyncSetInput {
23     
24     private SubscriberSyncInfoSet syncSet;
25     private SyncInfoFilter filter = new FastSyncInfoFilter();
26     
27     public SyncSetInput(SubscriberEventHandler handler) {
28         syncSet = new SubscriberSyncInfoSet(handler);
29     }
30     
31     public SubscriberSyncInfoSet getSyncSet() {
32         return syncSet;
33     }
34     
35     /**
36      * This method is invoked from reset to get all the sync information from
37      * the input source.
38      */

39     protected abstract void fetchInput(IProgressMonitor monitor) throws TeamException;
40
41     /**
42      * The input is no longer being used. Disconnect it from its source.
43      */

44     public abstract void disconnect();
45         
46     /**
47      * Reset the input. This will clear the current contents of the sync set and
48      * obtain the contents from the input source.
49      */

50     public void reset(IProgressMonitor monitor) throws TeamException {
51         
52         try {
53             syncSet.beginInput();
54             monitor = Policy.monitorFor(monitor);
55             monitor.beginTask(null, 100);
56             syncSet.clear();
57             fetchInput(Policy.subMonitorFor(monitor, 90));
58         } finally {
59             syncSet.endInput(Policy.subMonitorFor(monitor, 10));
60             monitor.done();
61         }
62     }
63
64     /**
65      * Collect the change in the provided sync info.
66      */

67     protected void collect(SyncInfo info, IProgressMonitor monitor) {
68         boolean isOutOfSync = filter.select(info, monitor);
69         SyncInfo oldInfo = syncSet.getSyncInfo(info.getLocal());
70         boolean wasOutOfSync = oldInfo != null;
71         if (isOutOfSync) {
72             syncSet.add(info);
73         } else if (wasOutOfSync) {
74             syncSet.remove(info.getLocal());
75         }
76     }
77
78     protected void remove(IResource resource) {
79         SyncInfo oldInfo = syncSet.getSyncInfo(resource);
80         if (oldInfo != null) {
81             syncSet.remove(resource);
82         }
83     }
84     
85     public SyncInfoFilter getFilter() {
86         return filter;
87     }
88
89     public void setFilter(SyncInfoFilter filter) {
90         this.filter = filter;
91     }
92
93 }
94
Popular Tags