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
|
/*******************************************************************************
* Copyright (c) 2000, 2017 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* 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.ISyncInfoSetChangeEvent;
import org.eclipse.team.core.synchronize.ISyncInfoSetChangeListener;
import org.eclipse.team.core.synchronize.SyncInfo;
import org.eclipse.team.core.synchronize.SyncInfoSet;
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);
}
@Override
public void disconnect() {
if (inputSyncSet == null) return;
inputSyncSet.removeSyncSetChangedListener(this);
inputSyncSet = null;
}
@Override
protected void fetchInput(IProgressMonitor monitor) {
if (inputSyncSet == null) return;
SyncInfo[] infos = inputSyncSet.getSyncInfos();
for (SyncInfo info : infos) {
collect(info, monitor);
}
}
@Override
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 (SyncInfo info : infos) {
collect(info, monitor);
}
}
private void remove(IResource[] resources) {
for (IResource resource : resources) {
remove(resource);
}
}
public void reset() {
inputSyncSet.connect(this);
}
@Override
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();
}
}
}
@Override
public void syncInfoSetErrors(SyncInfoSet set, ITeamStatus[] errors, IProgressMonitor monitor) {
SubscriberSyncInfoSet syncSet = getSyncSet();
try {
syncSet.beginInput();
for (ITeamStatus status : errors) {
syncSet.addError(status);
}
} finally {
syncSet.endInput(monitor);
}
}
}
|