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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
/*******************************************************************************
* Copyright (c) 2000, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-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.ITeamStatus;
import org.eclipse.team.core.synchronize.*;
import org.eclipse.team.internal.core.Policy;
/**
* This class uses the contents of one sync set as the input of another.
*/
public class SyncSetInputFromSyncSet extends SyncSetInput implements ISyncInfoSetChangeListener {
SubscriberSyncInfoSet inputSyncSet;
public SyncSetInputFromSyncSet(SubscriberSyncInfoSet set, SubscriberEventHandler handler) {
super(handler);
this.inputSyncSet = set;
inputSyncSet.addSyncSetChangedListener(this);
}
public void disconnect() {
if (inputSyncSet == null) return;
inputSyncSet.removeSyncSetChangedListener(this);
inputSyncSet = null;
}
/* (non-Javadoc)
* @see org.eclipse.team.ccvs.syncviews.views.AbstractSyncSet#initialize(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
*/
protected void fetchInput(IProgressMonitor monitor) {
if (inputSyncSet == null) return;
SyncInfo[] infos = inputSyncSet.getSyncInfos();
for (int i = 0; i < infos.length; i++) {
collect(infos[i], monitor);
}
}
/* (non-Javadoc)
* @see org.eclipse.team.ccvs.syncviews.views.ISyncSetChangedListener#syncSetChanged(org.eclipse.team.ccvs.syncviews.views.SyncSetChangedEvent)
*/
public void syncInfoChanged(ISyncInfoSetChangeEvent event, IProgressMonitor monitor) {
SyncInfoSet syncSet = getSyncSet();
try {
syncSet.beginInput();
monitor.beginTask(null, 105);
syncSetChanged(event.getChangedResources(), Policy.subMonitorFor(monitor, 50));
syncSetChanged(event.getAddedResources(), Policy.subMonitorFor(monitor, 50));
remove(event.getRemovedResources());
} finally {
syncSet.endInput(Policy.subMonitorFor(monitor, 5));
}
}
private void syncSetChanged(SyncInfo[] infos, IProgressMonitor monitor) {
for (int i = 0; i < infos.length; i++) {
collect(infos[i], monitor);
}
}
private void remove(IResource[] resources) {
for (int i = 0; i < resources.length; i++) {
remove(resources[i]);
}
}
public void reset() {
inputSyncSet.connect(this);
}
/* (non-Javadoc)
* @see org.eclipse.team.core.subscribers.ISyncInfoSetChangeListener#syncInfoSetReset(org.eclipse.team.core.subscribers.SyncInfoSet, org.eclipse.core.runtime.IProgressMonitor)
*/
public void syncInfoSetReset(SyncInfoSet set, IProgressMonitor monitor) {
if(inputSyncSet == null) {
set.removeSyncSetChangedListener(this);
} else {
SyncInfoSet syncSet = getSyncSet();
try {
syncSet.beginInput();
monitor.beginTask(null, 100);
syncSet.clear();
fetchInput(Policy.subMonitorFor(monitor, 95));
} finally {
syncSet.endInput(Policy.subMonitorFor(monitor, 5));
monitor.done();
}
}
}
/* (non-Javadoc)
* @see org.eclipse.team.core.subscribers.ISyncInfoSetChangeListener#syncInfoSetError(org.eclipse.team.core.subscribers.SyncInfoSet, org.eclipse.team.core.ITeamStatus[], org.eclipse.core.runtime.IProgressMonitor)
*/
public void syncInfoSetErrors(SyncInfoSet set, ITeamStatus[] errors, IProgressMonitor monitor) {
SubscriberSyncInfoSet syncSet = getSyncSet();
try {
syncSet.beginInput();
for (int i = 0; i < errors.length; i++) {
ITeamStatus status = errors[i];
syncSet.addError(status);
}
} finally {
syncSet.endInput(monitor);
}
}
}
|