Skip to main content
summaryrefslogtreecommitdiffstats
blob: 3935cffe8ad6788b5fe624f7c8eea595c7e57fef (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*******************************************************************************
 * Copyright (c) 2000, 2003 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.internal.core.subscribers;

import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.core.synchronize.*;
import org.eclipse.team.internal.core.Policy;

/**
 * This is the superclass for all SyncSet input providers
 */
public abstract class SyncSetInput {
	
	private SubscriberSyncInfoSet syncSet;
	private SyncInfoFilter filter = new FastSyncInfoFilter();
	
	public SyncSetInput(SubscriberEventHandler handler) {
		syncSet = new SubscriberSyncInfoSet(handler);
	}
	
	public SubscriberSyncInfoSet getSyncSet() {
		return syncSet;
	}
	
	/**
	 * This method is invoked from reset to get all the sync information from
	 * the input source.
	 */
	protected abstract void fetchInput(IProgressMonitor monitor) throws TeamException;

	/**
	 * The input is no longer being used. Disconnect it from its source.
	 */
	public abstract void disconnect();
		
	/**
	 * Reset the input. This will clear the current contents of the sync set and
	 * obtain the contents from the input source.
	 */
	public void reset(IProgressMonitor monitor) throws TeamException {
		syncSet.beginInput();
		try {
			monitor = Policy.monitorFor(monitor);
			monitor.beginTask(null, 100);
			syncSet.clear();
			fetchInput(Policy.subMonitorFor(monitor, 90));
		} finally {
			syncSet.endInput(Policy.subMonitorFor(monitor, 10));
			monitor.done();
		}
	}

	/**
	 * Collect the change in the provided sync info.
	 */
	protected void collect(SyncInfo info, IProgressMonitor monitor) {
		boolean isOutOfSync = filter.select(info, monitor);
		SyncInfo oldInfo = syncSet.getSyncInfo(info.getLocal());
		boolean wasOutOfSync = oldInfo != null;
		if (isOutOfSync) {
			syncSet.add(info);
		} else if (wasOutOfSync) {
			syncSet.remove(info.getLocal());
		}
	}

	protected void remove(IResource resource)  {
		SyncInfo oldInfo = syncSet.getSyncInfo(resource);
		boolean wasOutOfSync = oldInfo != null;
		if (oldInfo != null) {
			syncSet.remove(resource);
		}
	}
	
	public SyncInfoFilter getFilter() {
		return filter;
	}

	public void setFilter(SyncInfoFilter filter) {
		this.filter = filter;
	}

}

Back to the top