Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 04f99b14d83e8d3511bc5c6fe0c3c75d313e12fd (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
94
95
/*******************************************************************************
 * Copyright (c) 2000, 2004 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.core.subscribers;

import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.internal.core.subscribers.SyncSetInputFromSyncSet;
import org.eclipse.team.internal.core.subscribers.WorkingSetSyncSetInput;

/**
 * Collects changes from a provided sync info set and creates another set based on 
 * the provided filters.
 * 
 * @see TeamSubscriberSyncInfoCollector
 * 
 * @since 3.0
 */
public final class FilteredSyncInfoCollector {

	private WorkingSetSyncSetInput workingSetInput;
	private SyncSetInputFromSyncSet filteredInput;
	private SyncInfoSet source;

	public FilteredSyncInfoCollector(SyncInfoSet source, IResource[] workingSet, SyncInfoFilter filter) {
		this.source = source;
		
		// TODO: optimize and don't use working set if no roots are passed in
		workingSetInput = new WorkingSetSyncSetInput(source);
		workingSetInput.setWorkingSet(workingSet);		
		filteredInput = new SyncSetInputFromSyncSet(workingSetInput.getSyncSet());
		if(filter == null) {
			setFilter(new SyncInfoFilter() {
				public boolean select(SyncInfo info, IProgressMonitor monitor) {
					return true;
				}
			}, null);
		} else {
			setFilter(filter, null);
		}
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.team.internal.ui.synchronize.sets.SyncInfoSetDelegator#getSyncInfoSet()
	 */
	public SyncInfoSet getSyncInfoSet() {
		if(filteredInput != null) {
			return filteredInput.getSyncSet();
		} else {
			return workingSetInput.getSyncSet();
		}
	}
	
	public void setWorkingSet(IResource[] resources) {
		workingSetInput.setWorkingSet(resources);
	}
	
	public IResource[] getWorkingSet() {
		return workingSetInput.getWorkingSet();
	}
	
	public void setFilter(SyncInfoFilter filter, IProgressMonitor monitor) {
		filteredInput.setFilter(filter);
		try {
			filteredInput.reset(monitor);
		} catch (TeamException e) {
		}
	}
	
	public SyncInfoFilter getFilter() {
		if(filteredInput != null) {
			return filteredInput.getFilter();
		}
		return null;
	}
	
	public SyncInfoSet getWorkingSetSyncInfoSet() {
		return workingSetInput.getSyncSet();
	}
	
	public void dispose() {
		workingSetInput.disconnect();
		if(filteredInput != null) {
			filteredInput.disconnect();
		}
	}
}

Back to the top