KickJava   Java API By Example, From Geeks To Geeks.

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


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.resources.IWorkspaceRunnable;
15 import org.eclipse.core.runtime.IProgressMonitor;
16 import org.eclipse.team.core.synchronize.*;
17
18 /**
19  * This collector maintains a {@link SyncInfoSet} for a particular team subscriber keeping
20  * it up-to-date with both incoming changes and outgoing changes as they occur for
21  * resources in the workspace. The collector can be configured to consider all the subscriber's
22  * roots or only a subset.
23  * <p>
24  * The advantage of this collector is that it processes both resource and team
25  * subscriber deltas in a background thread.
26  * </p>
27  * @since 3.0
28  */

29 public final class WorkingSetFilteredSyncInfoCollector {
30
31     private WorkingSetSyncSetInput workingSetInput;
32     private SyncSetInputFromSyncSet filteredInput;
33     private SubscriberEventHandler eventHandler;
34     
35     /**
36      * Create a collector that collects out-of-sync resources that are children of
37      * the given roots. If the roots are <code>null</code>, then all out-of-sync resources
38      * from the subscriber are collected. An empty array of roots will cause no resources
39      * to be collected. The <code>start()</code> method must be called after creation
40      * to rpime the collector's sync sets.
41      * @param collector the subscriber's collector
42      * @param roots the roots of the out-of-sync resources to be collected
43      */

44     public WorkingSetFilteredSyncInfoCollector(SubscriberSyncInfoCollector collector, IResource[] roots) {
45         this.eventHandler = collector.getEventHandler();
46         // TODO: optimize and don't use working set if no roots are passed in
47
workingSetInput = new WorkingSetSyncSetInput((SubscriberSyncInfoSet)collector.getSyncInfoSet(), getEventHandler());
48         filteredInput = new SyncSetInputFromSyncSet(workingSetInput.getSyncSet(), getEventHandler());
49         filteredInput.setFilter(new SyncInfoFilter() {
50             public boolean select(SyncInfo info, IProgressMonitor monitor) {
51                 return true;
52             }
53         });
54     }
55     
56     /**
57      * Return the set that provides access to the out-of-sync resources for the collector's
58      * subscriber that are descendants of the roots for the collector,
59      * are in the collector's working set and match the collectors filter.
60      * @return a SyncInfoSet containing out-of-sync resources
61      */

62     public SyncInfoTree getSyncInfoTree() {
63         return filteredInput.getSyncSet();
64     }
65
66     /**
67      * Clears this collector's sync info sets and causes them to be recreated from the
68      * associated <code>Subscriber</code>. The reset will occur in the background. If the
69      * caller wishes to wait for the reset to complete, they should call
70      * waitForCollector(IProgressMonitor).
71      */

72     public void reset() {
73         workingSetInput.reset();
74     }
75
76     /**
77      * Disposes of the background job associated with this collector and deregisters
78      * all it's listeners. This method must be called when the collector is no longer
79      * referenced and could be garbage collected.
80      */

81     public void dispose() {
82         workingSetInput.disconnect();
83         if(filteredInput != null) {
84             filteredInput.disconnect();
85         }
86     }
87     
88     /**
89      * Return the event handler that performs the background processing for this collector.
90      * The event handler also serves the purpose of serializing the modifications and adjustments
91      * to the collector's sync sets in order to ensure that the state of the sets is kept
92      * consistent.
93      * @return Returns the eventHandler.
94      */

95     protected SubscriberEventHandler getEventHandler() {
96         return eventHandler;
97     }
98     
99     /**
100      * Set the filter for this collector. Only elements that match the filter will
101      * be in the out sync info set.
102      * @param filter the sync info filter
103      */

104     public void setFilter(SyncInfoFilter filter) {
105         filteredInput.setFilter(filter);
106         filteredInput.reset();
107     }
108     
109     /**
110      * Return a <code>SyncInfoSet</code> that contains the out-of-sync elements
111      * from the subsciber sync info set filtered
112      * by the working set resources but not the collector's <code>SyncInfoFilter</code>.
113      * @return a <code>SyncInfoSet</code>
114      */

115     public SyncInfoSet getWorkingSetSyncInfoSet() {
116         return workingSetInput.getSyncSet();
117     }
118
119     /**
120      * Run the given runnable in the event handler of the collector
121      * @param runnable a runnable
122      */

123     public void run(IWorkspaceRunnable runnable) {
124         eventHandler.run(runnable, true /* front of queue */);
125     }
126 }
127
Popular Tags