Skip to main content
summaryrefslogtreecommitdiffstats
blob: 6c84ef99fa9eac0681823c5a0a20adf45ebc2b92 (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
96
97
98
99
100
/*******************************************************************************
 * 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.ui.sync.views;

import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.core.subscribers.SyncInfo;

/**
 * Ths class uses the contents of one sync set as the input of another.
 */
public class SyncSetInputFromSyncSet extends SyncSetInput implements ISyncSetChangedListener {

	SyncSet inputSyncSet;
	
	/**
	 * @param syncSet
	 */
	protected SyncSetInputFromSyncSet() {
	}

	/**
	 * @return
	 */
	public SyncSet getInputSyncSet() {
		return inputSyncSet;
	}

	private void connect(SyncSet set) {
		if (this.inputSyncSet != null) return;
		this.inputSyncSet = set;
		inputSyncSet.addSyncSetChangedListener(this);
	}
	
	public void disconnect() {
		if (inputSyncSet == null) return;
		inputSyncSet.removeSyncSetChangedListener(this);
		inputSyncSet = null;
	}
	
	/**
	 * @param set
	 */
	public void setInputSyncSet(SyncSet set, IProgressMonitor monitor) throws TeamException {
		if (inputSyncSet != null) disconnect();
		connect(set);
		reset(monitor);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.team.ccvs.syncviews.views.AbstractSyncSet#initialize(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
	 */
	protected void fetchInput(IProgressMonitor monitor) throws TeamException {
		if (inputSyncSet == null) return;
		SyncInfo[] infos = inputSyncSet.allMembers();
		for (int i = 0; i < infos.length; i++) {
			collect(infos[i]);
		}
	}

	/* (non-Javadoc)
	 * @see org.eclipse.team.ccvs.syncviews.views.ISyncSetChangedListener#syncSetChanged(org.eclipse.team.ccvs.syncviews.views.SyncSetChangedEvent)
	 */
	public void syncSetChanged(SyncSetChangedEvent event) {
		SyncSet syncSet = getSyncSet();
		try {
			syncSet.beginInput();
			if (event.isReset()) {
				syncSet.reset();
			}
			syncSetChanged(event.getChangedResources());			
			syncSetChanged(event.getAddedResources());
			
			remove(event.getRemovedResources());
		} finally {
			getSyncSet().endInput();
		}
	}

	private void syncSetChanged(SyncInfo[] infos) {
		for (int i = 0; i < infos.length; i++) {
			collect(infos[i]);
		}
	}
	
	private void remove(IResource[] resources) {
		for (int i = 0; i < resources.length; i++) {
			remove(resources[i]);
		}
	}
}

Back to the top