blob: 8e68cdd484742444b8317556ec56e0db0799c5ba (
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
/*******************************************************************************
* Copyright (c) 2006 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.ui.synchronize;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.core.resources.IResource;
import org.eclipse.team.core.subscribers.ISubscriberChangeEvent;
import org.eclipse.team.ui.mapping.ITeamStateChangeEvent;
/**
* An implementation of {@link ITeamStateChangeEvent}.
* <p>
* This class is not intended to be subclassed by clients.
*
* @since 3.2
*/
public class TeamStateChangeEvent implements ITeamStateChangeEvent {
private Set changes = new HashSet();
private Set addedRoots = new HashSet();
private Set removedRoots = new HashSet();
public TeamStateChangeEvent() {
super();
}
/**
* Convenience constructor for creating an event from a subscriber change.
* @param deltas the set of subscriber changes
*/
public TeamStateChangeEvent(ISubscriberChangeEvent[] deltas) {
for (int i = 0; i < deltas.length; i++) {
ISubscriberChangeEvent event = deltas[i];
IResource resource = event.getResource();
if ((event.getFlags() & ISubscriberChangeEvent.ROOT_ADDED) != 0)
rootAdded(resource);
if ((event.getFlags() & ISubscriberChangeEvent.ROOT_REMOVED) != 0)
rootRemoved(resource);
if ((event.getFlags() & ISubscriberChangeEvent.SYNC_CHANGED) != 0)
changed(resource);
// Indicate that the ancestors may have changed as well
while (resource.getType() != IResource.PROJECT) {
resource = resource.getParent();
changed(resource);
}
}
}
/**
* The given resource has changed state.
* @param resource the resource whose state has changed
*/
public void changed(IResource resource) {
changes.add(resource);
}
/**
* The given root resource has been removed.
* @param resource the resource
*/
public void rootRemoved(IResource resource) {
removedRoots.add(resource);
}
/**
* The given root resource has been added.
* @param resource the resource
*/
public void rootAdded(IResource resource) {
addedRoots.add(resource);
}
/* (non-Javadoc)
* @see org.eclipse.team.ui.mapping.IDecoratedStateChangeEvent#getAddedRoots()
*/
public IResource[] getAddedRoots() {
return (IResource[]) addedRoots.toArray(new IResource[addedRoots.size()]);
}
/* (non-Javadoc)
* @see org.eclipse.team.ui.mapping.IDecoratedStateChangeEvent#getRemovedRoots()
*/
public IResource[] getRemovedRoots() {
return (IResource[]) removedRoots.toArray(new IResource[removedRoots.size()]);
}
/* (non-Javadoc)
* @see org.eclipse.team.ui.mapping.IDecoratedStateChangeEvent#getChangedResources()
*/
public IResource[] getChangedResources() {
return (IResource[]) changes.toArray(new IResource[changes.size()]);
}
/* (non-Javadoc)
* @see org.eclipse.team.ui.mapping.IDecoratedStateChangeEvent#hasChange(org.eclipse.core.resources.IResource)
*/
public boolean hasChange(IResource resource) {
if (changes.contains(resource))
return true;
if (isChildOfChangedRoot(resource)) {
return true;
}
return false;
}
private boolean isChildOfChangedRoot(IResource resource) {
if (resource == null || resource.getType() == IResource.ROOT)
return false;
if (addedRoots.contains(resource) || removedRoots.contains(resource))
return true;
return isChildOfChangedRoot(resource.getParent());
}
}
|