|
Lines 11-22
Link Here
|
| 11 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
| 12 |
package org.eclipse.hyades.test.ui.internal.navigator.proxy; |
12 |
package org.eclipse.hyades.test.ui.internal.navigator.proxy; |
| 13 |
|
13 |
|
|
|
14 |
import java.util.Collection; |
| 14 |
import java.util.HashMap; |
15 |
import java.util.HashMap; |
| 15 |
import java.util.Iterator; |
16 |
import java.util.Iterator; |
| 16 |
import java.util.LinkedList; |
|
|
| 17 |
import java.util.List; |
| 18 |
import java.util.Map; |
17 |
import java.util.Map; |
| 19 |
import java.util.Set; |
|
|
| 20 |
|
18 |
|
| 21 |
import org.eclipse.core.resources.IProject; |
19 |
import org.eclipse.core.resources.IProject; |
| 22 |
import org.eclipse.core.resources.IResourceChangeEvent; |
20 |
import org.eclipse.core.resources.IResourceChangeEvent; |
|
Lines 26-33
Link Here
|
| 26 |
import org.eclipse.core.runtime.IExtensionPoint; |
24 |
import org.eclipse.core.runtime.IExtensionPoint; |
| 27 |
import org.eclipse.core.runtime.Platform; |
25 |
import org.eclipse.core.runtime.Platform; |
| 28 |
import org.eclipse.hyades.test.ui.UiPlugin; |
26 |
import org.eclipse.hyades.test.ui.UiPlugin; |
|
|
27 |
import org.eclipse.hyades.test.ui.internal.navigator.proxy.async.SynchronizedAccess; |
| 29 |
import org.eclipse.hyades.test.ui.navigator.IProxyNode; |
28 |
import org.eclipse.hyades.test.ui.navigator.IProxyNode; |
| 30 |
import org.eclipse.hyades.test.ui.navigator.IProxyNodeListener; |
29 |
import org.eclipse.hyades.test.ui.navigator.IProxyNodeListener; |
|
|
30 |
import org.eclipse.hyades.test.ui.navigator.ITypeProviderContext; |
| 31 |
|
31 |
|
| 32 |
/** This class manage the extensions of org.eclipse.hyades.test.ui.testNavigatorTestAssetGroupProxy |
32 |
/** This class manage the extensions of org.eclipse.hyades.test.ui.testNavigatorTestAssetGroupProxy |
| 33 |
* This class manage all test asset groups created using a cache. |
33 |
* This class manage all test asset groups created using a cache. |
|
Lines 36-42
Link Here
|
| 36 |
*/ |
36 |
*/ |
| 37 |
public class TestAssetGroupProxyManager implements IResourceChangeListener { |
37 |
public class TestAssetGroupProxyManager implements IResourceChangeListener { |
| 38 |
|
38 |
|
| 39 |
static class TestAssetInfo { |
39 |
static class TestAssetInfo extends SynchronizedAccess { |
| 40 |
private String name; |
40 |
private String name; |
| 41 |
private boolean isFlat; |
41 |
private boolean isFlat; |
| 42 |
private String imageKey; |
42 |
private String imageKey; |
|
Lines 67-88
Link Here
|
| 67 |
} |
67 |
} |
| 68 |
} |
68 |
} |
| 69 |
|
69 |
|
| 70 |
private Map extensions; |
|
|
| 71 |
/** |
70 |
/** |
| 72 |
* project -> List(ITestAssetGroupProxyNode) |
71 |
* string -> TestAssetInfo |
| 73 |
*/ |
72 |
*/ |
| 74 |
private Map cache; |
73 |
private Map extensions; |
| 75 |
/** |
74 |
/** |
| 76 |
* project -> List(ITestAssetGroupProxyNode) |
75 |
* project -> List(ITestAssetGroupProxyNode) |
| 77 |
*/ |
76 |
*/ |
| 78 |
private Map removedElements; |
77 |
private Map cache; |
| 79 |
private IProxyNodeListener refresher; |
78 |
private IProxyNodeListener refresher; |
| 80 |
|
79 |
|
| 81 |
public TestAssetGroupProxyManager() { |
80 |
public TestAssetGroupProxyManager(ITypeProviderContext context) { |
| 82 |
extensions = new HashMap(); |
81 |
extensions = new HashMap(); |
| 83 |
cache = new HashMap(); |
82 |
cache = new HashMap(); |
| 84 |
removedElements = new HashMap(); |
83 |
refresher = context.getProxyNodeListener(); |
| 85 |
refresher = new TestNavigatorRefresher(); |
|
|
| 86 |
IExtensionPoint extPoint = Platform.getExtensionRegistry().getExtensionPoint(UiPlugin.getID() + ".testNavigatorTestAssetGroupProxy"); //$NON-NLS-1$ |
84 |
IExtensionPoint extPoint = Platform.getExtensionRegistry().getExtensionPoint(UiPlugin.getID() + ".testNavigatorTestAssetGroupProxy"); //$NON-NLS-1$ |
| 87 |
if (extPoint != null) { |
85 |
if (extPoint != null) { |
| 88 |
IConfigurationElement[] members = extPoint.getConfigurationElements(); |
86 |
IConfigurationElement[] members = extPoint.getConfigurationElements(); |
|
Lines 113-169
Link Here
|
| 113 |
UiPlugin.logInfo("extension: "+extension+" already registered"); //$NON-NLS-1$ //$NON-NLS-2$ |
111 |
UiPlugin.logInfo("extension: "+extension+" already registered"); //$NON-NLS-1$ //$NON-NLS-2$ |
| 114 |
} |
112 |
} |
| 115 |
} |
113 |
} |
| 116 |
|
114 |
|
| 117 |
/** Returns all test asset groups for a given project |
115 |
public Collection getExtensions() { |
| 118 |
* |
116 |
return extensions.keySet(); |
| 119 |
* @param project the project in which the test asset groups are required |
117 |
} |
| 120 |
* @return a list of ITestAssetGroupProxyNode. |
|
|
| 121 |
*/ |
| 122 |
public List getTestAssetGroups(IProject project) { |
| 123 |
if(project != null) { |
| 124 |
List groups = new LinkedList(); |
| 125 |
if(cache.containsKey(project)) { |
| 126 |
return (List)cache.get(project); |
| 127 |
} else { |
| 128 |
//- not yet built |
| 129 |
Set keys = extensions.keySet(); |
| 130 |
for (Iterator it = keys.iterator(); it.hasNext();) { |
| 131 |
ITestAssetGroupProxyNode proxy = getTestAssetGroup(project,(String) it.next()); |
| 132 |
if(proxy != null) { |
| 133 |
groups.add(proxy); |
| 134 |
} |
| 135 |
} |
| 136 |
} |
| 137 |
return groups; |
| 138 |
} else { |
| 139 |
//- return empty list |
| 140 |
return new LinkedList(); |
| 141 |
} |
| 142 |
} |
| 143 |
|
118 |
|
| 144 |
private ITestAssetGroupProxyNode getTestAssetGroup(IProject project, String extension) { |
119 |
public ITestAssetGroupProxyNode getTestAssetGroup(IProject project, String extension) { |
| 145 |
if(extensions.containsKey(extension)) { |
120 |
ITestAssetGroupProxyNode group = cacheGet(project, extension); |
| 146 |
//- this extension has a test asset group registered to display those files |
121 |
if (group == null) { |
| 147 |
TestAssetInfo info = (TestAssetInfo)extensions.get(extension); |
122 |
if(extensions.containsKey(extension)) { |
| 148 |
//- build the proxy node with the right parameters |
123 |
//- this extension has a test asset group registered to display those files |
| 149 |
ITestAssetGroupProxyNode proxy = new TestAssetGroupProxyNode(project, extension, info.getName(), info.getImageKey(), info.isFlat, project); |
124 |
TestAssetInfo info = (TestAssetInfo)extensions.get(extension); |
| 150 |
if(proxy.getChildren().length > 0) { |
125 |
//- build the proxy node with the right parameters |
| 151 |
cachePut(project, proxy); |
126 |
try { |
| 152 |
return proxy; |
127 |
if (info.acquireLock(project)) { |
| 153 |
} |
128 |
// the group may be have been computed in another thread while we |
| 154 |
} |
129 |
// were acquiring the lock. |
|
|
130 |
group = cacheGet(project, extension); |
| 131 |
if (group == null) { |
| 132 |
group = new TestAssetGroupProxyNode(project, extension, info.getName(), info.getImageKey(), info.isFlat, project); |
| 133 |
cachePut(project, extension, group); |
| 134 |
} |
| 135 |
} |
| 136 |
} finally { |
| 137 |
info.releaseLock(project); |
| 138 |
} |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
if(group != null && group.getChildren().length > 0) { |
| 143 |
return group; |
| 144 |
} |
| 155 |
return null; |
145 |
return null; |
| 156 |
} |
146 |
} |
| 157 |
|
147 |
|
| 158 |
private void cachePut(IProject project, ITestAssetGroupProxyNode testAsset) { |
148 |
private void cachePut(IProject project, String extension, ITestAssetGroupProxyNode testAsset) { |
| 159 |
List list; |
149 |
Map map = (Map) cache.get(project); |
| 160 |
if (cache.containsKey(project)) { |
150 |
if (map == null) { |
| 161 |
list = (List) cache.get(project); |
151 |
map = new HashMap(); |
| 162 |
} else { |
152 |
cache.put(project, map); |
| 163 |
list = new LinkedList(); |
153 |
} |
| 164 |
cache.put(project, list); |
154 |
map.put(extension, testAsset); |
| 165 |
} |
155 |
} |
| 166 |
list.add(testAsset); |
156 |
|
|
|
157 |
private ITestAssetGroupProxyNode cacheGet(IProject project, String extension) { |
| 158 |
Map map = (Map) cache.get(project); |
| 159 |
if (map != null) { |
| 160 |
ITestAssetGroupProxyNode group = (ITestAssetGroupProxyNode) map.get(extension); |
| 161 |
if (group != null) return group; |
| 162 |
} |
| 163 |
return null; |
| 167 |
} |
164 |
} |
| 168 |
|
165 |
|
| 169 |
/* (non-Javadoc) |
166 |
/* (non-Javadoc) |
|
Lines 178-288
Link Here
|
| 178 |
IResourceDelta delta = affectedProjects[i]; |
175 |
IResourceDelta delta = affectedProjects[i]; |
| 179 |
IProject project = (IProject)delta.getResource(); |
176 |
IProject project = (IProject)delta.getResource(); |
| 180 |
//- given a project we need to update all test asset group proxy nodes created in this project |
177 |
//- given a project we need to update all test asset group proxy nodes created in this project |
| 181 |
List groups = (List)cache.get(project); |
178 |
Map groups = (Map)cache.get(project); |
| 182 |
if(groups != null) { |
179 |
if(groups != null) { |
| 183 |
for (Iterator it = groups.iterator(); it.hasNext();) { |
180 |
for (Iterator it = extensions.keySet().iterator(); it.hasNext();) { |
| 184 |
TestAssetGroupProxyNode proxy = (TestAssetGroupProxyNode) it.next(); |
181 |
String ext = (String)it.next(); |
| 185 |
IProxyNode lowestProxy = proxy.resourceChanged(delta); |
182 |
TestAssetGroupProxyNode proxy = (TestAssetGroupProxyNode) groups.get(ext); |
| 186 |
if(proxy.getChildren().length == 0) { |
183 |
if (proxy != null) { |
| 187 |
//- this means that the group no longer contains children |
184 |
IProxyNode lowestProxy = proxy.resourceChanged(delta); |
| 188 |
prepareCacheRemove(project, proxy); |
185 |
if(proxy.getChildren().length == 0) { |
| 189 |
lowestChanged = project; |
186 |
//- this means that the group no longer contains children |
| 190 |
lowestProxy = null; |
187 |
lowestChanged = project; |
| 191 |
} |
188 |
lowestProxy = null; |
| 192 |
if(lowestProxy != null) { |
189 |
} |
| 193 |
//- there was a change in this test asset group proxy node tree |
190 |
if(lowestProxy != null) { |
| 194 |
if(lowestChanged == null) { |
191 |
//- there was a change in this test asset group proxy node tree |
| 195 |
//- this was the first change |
192 |
if(lowestChanged == null) { |
| 196 |
lowestChanged = lowestProxy; |
193 |
//- this was the first change |
| 197 |
} else { |
194 |
lowestChanged = lowestProxy; |
| 198 |
//- the second one ... we need to refresh the owner of those nodes (the project) |
195 |
} else { |
| 199 |
lowestChanged = project; |
196 |
//- the second one ... we need to refresh the owner of those nodes (the project) |
| 200 |
} |
197 |
lowestChanged = project; |
|
|
198 |
} |
| 199 |
} |
| 201 |
} |
200 |
} |
| 202 |
} |
201 |
} |
| 203 |
} |
202 |
} |
| 204 |
//- we need to handle test asset creation in empty group |
|
|
| 205 |
boolean newTAG = getAddedTestAssetGroups(project, delta); |
| 206 |
if(!(lowestChanged instanceof IProject) && newTAG) { |
| 207 |
lowestChanged = project; |
| 208 |
} |
| 209 |
} |
203 |
} |
| 210 |
//- after the for loop, we can update the cache for removes |
|
|
| 211 |
completeCacheRemoves(); |
| 212 |
//- refresh only the lowest node |
204 |
//- refresh only the lowest node |
| 213 |
if(lowestChanged != null) { |
205 |
if(lowestChanged != null) { |
| 214 |
refresher.nodeChanged(lowestChanged); |
206 |
refresher.nodeChanged(lowestChanged); |
| 215 |
} |
207 |
} |
| 216 |
} |
208 |
} |
| 217 |
|
209 |
|
| 218 |
/** Return whether the given project has changed by addition of new test asset group found in the resource delta. |
|
|
| 219 |
* @param project the project affected by the resource change |
| 220 |
* @param delta the resource change delta used to know what the change is. |
| 221 |
* @return <code>true</code> if the project has at least one new test asset group proxy node and <code>false</code> otherwise. |
| 222 |
*/ |
| 223 |
private boolean getAddedTestAssetGroups(IProject project, IResourceDelta delta) { |
| 224 |
List groups = (List)cache.get(project); |
| 225 |
List notExistingExt = new LinkedList(); |
| 226 |
//- initializing with all extensions |
| 227 |
for (Iterator it = extensions.keySet().iterator(); it.hasNext();) { |
| 228 |
notExistingExt.add(it.next()); |
| 229 |
} |
| 230 |
//- remove from all those that already been handled by a test asset group proxy node |
| 231 |
if(groups != null) { |
| 232 |
for (Iterator it = groups.iterator(); it.hasNext();) { |
| 233 |
TestAssetGroupProxyNode tagpn = (TestAssetGroupProxyNode) it.next(); |
| 234 |
notExistingExt.remove(tagpn.getExtension()); |
| 235 |
} |
| 236 |
} |
| 237 |
boolean projectChanged = false; |
| 238 |
//- then try to create a test asset group from this list of not yet handled extension |
| 239 |
for (Iterator it = notExistingExt.iterator(); it.hasNext();) { |
| 240 |
String ext = (String) it.next(); |
| 241 |
ITestAssetGroupProxyNode proxy = getTestAssetGroup(project, ext); |
| 242 |
//- if the proxy has been created, that means that the project need to be refreshed |
| 243 |
if(proxy != null) { |
| 244 |
projectChanged = true; |
| 245 |
} |
| 246 |
} |
| 247 |
return projectChanged; |
| 248 |
} |
| 249 |
|
| 250 |
private void prepareCacheRemove(IProject project, TestAssetGroupProxyNode proxy) { |
| 251 |
List proxies; |
| 252 |
if(removedElements.containsKey(project)) { |
| 253 |
//- a test asset group of this project has already been added to removals |
| 254 |
proxies = (List)removedElements.get(project); |
| 255 |
} else { |
| 256 |
proxies = new LinkedList(); |
| 257 |
removedElements.put(project, proxies); |
| 258 |
} |
| 259 |
proxies.add(proxy); |
| 260 |
} |
| 261 |
|
| 262 |
private void completeCacheRemoves() { |
| 263 |
Set removed = removedElements.entrySet(); |
| 264 |
for (Iterator it = removed.iterator(); it.hasNext();) { |
| 265 |
Map.Entry element = (Map.Entry) it.next(); |
| 266 |
IProject project = (IProject)element.getKey(); |
| 267 |
//- remove saved test asset groups of this project |
| 268 |
removeCacheElements(project, (List)element.getValue()); |
| 269 |
} |
| 270 |
//- clear removal cache. |
| 271 |
removedElements.clear(); |
| 272 |
} |
| 273 |
|
| 274 |
/** |
| 275 |
* Removes all element given by the list argument from the project cached elements |
| 276 |
* @param project the project from which the elements are removed |
| 277 |
* @param list elments to remove. (those elements should be ITestAssetGroupProxyNode) |
| 278 |
*/ |
| 279 |
private void removeCacheElements(IProject project, List list) { |
| 280 |
List groups = (List)cache.get(project); |
| 281 |
for(Iterator it = list.iterator(); it.hasNext(); ) { |
| 282 |
groups.remove(it.next()); |
| 283 |
} |
| 284 |
} |
| 285 |
|
| 286 |
public void dispose() { |
210 |
public void dispose() { |
| 287 |
FileProxyNodeCache.getInstance().removeResourceListener(this); |
211 |
FileProxyNodeCache.getInstance().removeResourceListener(this); |
| 288 |
} |
212 |
} |