Lines 63-68
Link Here
|
63 |
import javax.swing.event.ChangeListener; |
63 |
import javax.swing.event.ChangeListener; |
64 |
import org.netbeans.api.project.FileOwnerQuery; |
64 |
import org.netbeans.api.project.FileOwnerQuery; |
65 |
import org.netbeans.api.project.Project; |
65 |
import org.netbeans.api.project.Project; |
|
|
66 |
import org.netbeans.api.project.ProjectManager; |
66 |
import org.netbeans.api.project.ProjectUtils; |
67 |
import org.netbeans.api.project.ProjectUtils; |
67 |
import org.netbeans.api.project.SourceGroup; |
68 |
import org.netbeans.api.project.SourceGroup; |
68 |
import org.netbeans.api.project.Sources; |
69 |
import org.netbeans.api.project.Sources; |
Lines 79-84
Link Here
|
79 |
import org.openide.nodes.Children; |
80 |
import org.openide.nodes.Children; |
80 |
import org.openide.nodes.FilterNode; |
81 |
import org.openide.nodes.FilterNode; |
81 |
import org.openide.nodes.Node; |
82 |
import org.openide.nodes.Node; |
|
|
83 |
import org.openide.util.Lookup; |
82 |
import org.openide.util.NbBundle; |
84 |
import org.openide.util.NbBundle; |
83 |
import org.openide.util.RequestProcessor; |
85 |
import org.openide.util.RequestProcessor; |
84 |
import org.openide.util.WeakListeners; |
86 |
import org.openide.util.WeakListeners; |
Lines 213-219
Link Here
|
213 |
|
215 |
|
214 |
// XXX Needs to listen to project rename |
216 |
// XXX Needs to listen to project rename |
215 |
// However project rename is currently disabled so it is not a big deal |
217 |
// However project rename is currently disabled so it is not a big deal |
216 |
static class ProjectChildren extends Children.Keys<Project> implements ChangeListener, PropertyChangeListener { |
218 |
static class ProjectChildren extends Children.Keys<ProjectChildren.Pair> implements ChangeListener, PropertyChangeListener { |
217 |
|
219 |
|
218 |
private java.util.Map <Sources,Reference<Project>> sources2projects = new WeakHashMap<Sources,Reference<Project>>(); |
220 |
private java.util.Map <Sources,Reference<Project>> sources2projects = new WeakHashMap<Sources,Reference<Project>>(); |
219 |
|
221 |
|
Lines 221-292
Link Here
|
221 |
|
223 |
|
222 |
public ProjectChildren( int type ) { |
224 |
public ProjectChildren( int type ) { |
223 |
this.type = type; |
225 |
this.type = type; |
224 |
OpenProjectList.getDefault().addPropertyChangeListener( this ); |
|
|
225 |
} |
226 |
} |
226 |
|
227 |
|
227 |
// Children.Keys impl -------------------------------------------------- |
228 |
// Children.Keys impl -------------------------------------------------- |
228 |
|
229 |
|
|
|
230 |
@Override |
229 |
public void addNotify() { |
231 |
public void addNotify() { |
|
|
232 |
OpenProjectList.getDefault().addPropertyChangeListener(this); |
230 |
setKeys( getKeys() ); |
233 |
setKeys( getKeys() ); |
231 |
} |
234 |
} |
232 |
|
235 |
|
|
|
236 |
@Override |
233 |
public void removeNotify() { |
237 |
public void removeNotify() { |
|
|
238 |
OpenProjectList.getDefault().removePropertyChangeListener(this); |
234 |
for (Sources sources : sources2projects.keySet()) { |
239 |
for (Sources sources : sources2projects.keySet()) { |
235 |
sources.removeChangeListener( this ); |
240 |
sources.removeChangeListener( this ); |
236 |
} |
241 |
} |
237 |
sources2projects.clear(); |
242 |
sources2projects.clear(); |
238 |
setKeys(Collections.<Project>emptySet()); |
243 |
setKeys(Collections.<Pair>emptySet()); |
239 |
} |
244 |
} |
240 |
|
245 |
|
241 |
protected Node[] createNodes(Project project) { |
246 |
protected Node[] createNodes(Pair p) { |
242 |
LogicalViewProvider lvp = project.getLookup().lookup(LogicalViewProvider.class); |
247 |
Project project = p.project; |
243 |
|
248 |
|
244 |
Node nodes[] = null; |
249 |
Node origNodes[] = null; |
245 |
boolean projectInLookup = true; |
250 |
boolean[] projectInLookup = new boolean[1]; |
|
|
251 |
projectInLookup[0] = true; |
246 |
|
252 |
|
247 |
if ( type == PHYSICAL_VIEW ) { |
253 |
if ( type == PHYSICAL_VIEW ) { |
248 |
Sources sources = ProjectUtils.getSources( project ); |
254 |
Sources sources = ProjectUtils.getSources( project ); |
249 |
sources.removeChangeListener( this ); |
255 |
sources.removeChangeListener( this ); |
250 |
sources.addChangeListener( this ); |
256 |
sources.addChangeListener( this ); |
251 |
sources2projects.put( sources, new WeakReference<Project>( project ) ); |
257 |
sources2projects.put( sources, new WeakReference<Project>( project ) ); |
252 |
nodes = PhysicalView.createNodesForProject( project ); |
258 |
origNodes = PhysicalView.createNodesForProject( project ); |
|
|
259 |
} else { |
260 |
origNodes = new Node[] { logicalViewForProject(project, projectInLookup) }; |
253 |
} |
261 |
} |
254 |
else if ( lvp == null ) { |
262 |
|
255 |
ErrorManager.getDefault().log(ErrorManager.WARNING, "Warning - project " + ProjectUtils.getInformation(project).getName() + " failed to supply a LogicalViewProvider in its lookup"); // NOI18N |
263 |
Node[] badgedNodes = new Node[ origNodes.length ]; |
256 |
Sources sources = ProjectUtils.getSources( project ); |
264 |
for( int i = 0; i < origNodes.length; i++ ) { |
257 |
sources.removeChangeListener( this ); |
265 |
if ( type == PHYSICAL_VIEW && !PhysicalView.isProjectDirNode( origNodes[i] ) ) { |
258 |
sources.addChangeListener( this ); |
266 |
// Don't badge external sources |
259 |
nodes = PhysicalView.createNodesForProject( project ); |
267 |
badgedNodes[i] = origNodes[i]; |
260 |
if ( nodes.length > 0 ) { |
|
|
261 |
nodes = new Node[] { nodes[0] }; |
262 |
} |
268 |
} |
263 |
else { |
269 |
else { |
264 |
nodes = new Node[] { Node.EMPTY }; |
270 |
badgedNodes[i] = new BadgingNode( origNodes[i], |
|
|
271 |
type == LOGICAL_VIEW && projectInLookup[0]); |
265 |
} |
272 |
} |
266 |
} |
273 |
} |
267 |
else { |
274 |
|
268 |
nodes = new Node[] { lvp.createLogicalView() }; |
275 |
return badgedNodes; |
269 |
if (nodes[0].getLookup().lookup(Project.class) != project) { |
276 |
} |
|
|
277 |
|
278 |
private Node logicalViewForProject(Project project, boolean[] projectInLookup) { |
279 |
Node node; |
280 |
|
281 |
LogicalViewProvider lvp = project.getLookup().lookup(LogicalViewProvider.class); |
282 |
|
283 |
if ( lvp == null ) { |
284 |
ErrorManager.getDefault().log(ErrorManager.WARNING, "Warning - project " + ProjectUtils.getInformation(project).getName() + " failed to supply a LogicalViewProvider in its lookup"); // NOI18N |
285 |
Sources sources = ProjectUtils.getSources(project); |
286 |
sources.removeChangeListener(this); |
287 |
sources.addChangeListener(this); |
288 |
Node[] physical = PhysicalView.createNodesForProject(project); |
289 |
if (physical.length > 0) { |
290 |
node = physical[0]; |
291 |
} else { |
292 |
node = Node.EMPTY; |
293 |
} |
294 |
} else { |
295 |
node = lvp.createLogicalView(); |
296 |
if (node.getLookup().lookup(Project.class) != project) { |
270 |
// Various actions, badging, etc. are not going to work. |
297 |
// Various actions, badging, etc. are not going to work. |
271 |
ErrorManager.getDefault().log(ErrorManager.WARNING, "Warning - project " + ProjectUtils.getInformation(project).getName() + " failed to supply itself in the lookup of the root node of its own logical view"); // NOI18N |
298 |
ErrorManager.getDefault().log(ErrorManager.WARNING, "Warning - project " + ProjectUtils.getInformation(project).getName() + " failed to supply itself in the lookup of the root node of its own logical view"); // NOI18N |
272 |
//#114664 |
299 |
//#114664 |
273 |
projectInLookup = false; |
300 |
if (projectInLookup != null) { |
|
|
301 |
projectInLookup[0] = false; |
274 |
} |
302 |
} |
275 |
} |
303 |
} |
276 |
|
|
|
277 |
Node[] badgedNodes = new Node[ nodes.length ]; |
278 |
for( int i = 0; i < nodes.length; i++ ) { |
279 |
if ( type == PHYSICAL_VIEW && !PhysicalView.isProjectDirNode( nodes[i] ) ) { |
280 |
// Don't badge external sources |
281 |
badgedNodes[i] = nodes[i]; |
282 |
} |
304 |
} |
283 |
else { |
|
|
284 |
badgedNodes[i] = new BadgingNode( nodes[i], |
285 |
type == LOGICAL_VIEW && projectInLookup); |
286 |
} |
287 |
} |
288 |
|
305 |
|
289 |
return badgedNodes; |
306 |
return node; |
290 |
} |
307 |
} |
291 |
|
308 |
|
292 |
// PropertyChangeListener impl ----------------------------------------- |
309 |
// PropertyChangeListener impl ----------------------------------------- |
Lines 315-336
Link Here
|
315 |
// Fix for 50259, callers sometimes hold locks |
332 |
// Fix for 50259, callers sometimes hold locks |
316 |
SwingUtilities.invokeLater( new Runnable() { |
333 |
SwingUtilities.invokeLater( new Runnable() { |
317 |
public void run() { |
334 |
public void run() { |
318 |
refreshKey( project ); |
335 |
refreshKey( new Pair(project, project.getProjectDirectory()) ); |
319 |
} |
336 |
} |
320 |
} ); |
337 |
} ); |
321 |
} |
338 |
} |
322 |
|
339 |
|
323 |
// Own methods --------------------------------------------------------- |
340 |
// Own methods --------------------------------------------------------- |
324 |
|
341 |
|
325 |
public Collection<Project> getKeys() { |
342 |
public Collection<Pair> getKeys() { |
326 |
List<Project> projects = Arrays.asList( OpenProjectList.getDefault().getOpenProjects() ); |
343 |
List<Project> projects = Arrays.asList( OpenProjectList.getDefault().getOpenProjects() ); |
327 |
Collections.sort( projects, OpenProjectList.PROJECT_BY_DISPLAYNAME ); |
344 |
Collections.sort( projects, OpenProjectList.PROJECT_BY_DISPLAYNAME ); |
328 |
|
345 |
|
329 |
return projects; |
346 |
List<Pair> dirs = Arrays.asList( new Pair[projects.size()] ); |
|
|
347 |
|
348 |
for (int i = 0; i < projects.size(); i++) { |
349 |
Project project = projects.get(i); |
350 |
dirs.set(i, new Pair(project, project.getProjectDirectory())); |
330 |
} |
351 |
} |
331 |
|
352 |
|
|
|
353 |
|
354 |
return dirs; |
332 |
} |
355 |
} |
333 |
|
356 |
|
|
|
357 |
/** Object that comparers two projects just by their directory. |
358 |
* This allows to replace a LazyProject with real one without discarding |
359 |
* the nodes. |
360 |
*/ |
361 |
private static final class Pair extends Object { |
362 |
public final Project project; |
363 |
public final FileObject fo; |
364 |
|
365 |
public Pair(Project project, FileObject fo) { |
366 |
this.project = project; |
367 |
this.fo = fo; |
368 |
} |
369 |
|
370 |
@Override |
371 |
public boolean equals(Object obj) { |
372 |
if (obj == null) { |
373 |
return false; |
374 |
} |
375 |
if (getClass() != obj.getClass()) { |
376 |
return false; |
377 |
} |
378 |
final Pair other = (Pair) obj; |
379 |
if (this.fo != other.fo && (this.fo == null || !this.fo.equals(other.fo))) { |
380 |
return false; |
381 |
} |
382 |
return true; |
383 |
} |
384 |
|
385 |
@Override |
386 |
public int hashCode() { |
387 |
int hash = 7; |
388 |
hash = 53 * hash + (this.fo != null ? this.fo.hashCode() : 0); |
389 |
return hash; |
390 |
} |
391 |
} |
392 |
|
393 |
} |
394 |
|
334 |
private static final class BadgingNode extends FilterNode implements PropertyChangeListener, Runnable, FileStatusListener { |
395 |
private static final class BadgingNode extends FilterNode implements PropertyChangeListener, Runnable, FileStatusListener { |
335 |
|
396 |
|
336 |
private static String badgedNamePattern = NbBundle.getMessage(ProjectsRootNode.class, "LBL_MainProject_BadgedNamePattern"); |
397 |
private static String badgedNamePattern = NbBundle.getMessage(ProjectsRootNode.class, "LBL_MainProject_BadgedNamePattern"); |
Lines 341-347
Link Here
|
341 |
private volatile boolean nameChange; |
402 |
private volatile boolean nameChange; |
342 |
|
403 |
|
343 |
public BadgingNode(Node n, boolean addSearchInfo) { |
404 |
public BadgingNode(Node n, boolean addSearchInfo) { |
344 |
super(n, null, addSearchInfo ? new ProxyLookup(n.getLookup(), Lookups.singleton(alwaysSearchableSearchInfo(n.getLookup().lookup(Project.class)))) : n.getLookup()); |
405 |
super(n, null, addSearchInfo ? badgingLookup(n) : n.getLookup()); |
345 |
OpenProjectList.getDefault().addPropertyChangeListener(WeakListeners.propertyChange(this, OpenProjectList.getDefault())); |
406 |
OpenProjectList.getDefault().addPropertyChangeListener(WeakListeners.propertyChange(this, OpenProjectList.getDefault())); |
346 |
Project proj = getOriginal().getLookup().lookup(Project.class); |
407 |
Project proj = getOriginal().getLookup().lookup(Project.class); |
347 |
if (proj != null) { |
408 |
if (proj != null) { |
Lines 362-367
Link Here
|
362 |
} |
423 |
} |
363 |
} |
424 |
} |
364 |
|
425 |
|
|
|
426 |
private static Lookup badgingLookup(Node n) { |
427 |
return new BadgingLookup(n.getLookup(), Lookups.singleton(alwaysSearchableSearchInfo(n.getLookup().lookup(Project.class)))); |
428 |
} |
429 |
|
430 |
private void updateLookup(Node n) { |
431 |
if (getLookup() instanceof BadgingLookup) { |
432 |
BadgingLookup bl = (BadgingLookup)getLookup(); |
433 |
bl.setMyLookups(n.getLookup(), Lookups.singleton(alwaysSearchableSearchInfo(n.getLookup().lookup(Project.class)))); |
434 |
} |
435 |
} |
436 |
|
365 |
public void run() { |
437 |
public void run() { |
366 |
if (nameChange) { |
438 |
if (nameChange) { |
367 |
fireDisplayNameChange(null, null); |
439 |
fireDisplayNameChange(null, null); |
Lines 433-446
Link Here
|
433 |
if ( OpenProjectList.PROPERTY_MAIN_PROJECT.equals( e.getPropertyName() ) ) { |
505 |
if ( OpenProjectList.PROPERTY_MAIN_PROJECT.equals( e.getPropertyName() ) ) { |
434 |
fireDisplayNameChange( null, null ); |
506 |
fireDisplayNameChange( null, null ); |
435 |
} |
507 |
} |
|
|
508 |
if ( OpenProjectList.PROPERTY_REPLACE.equals(e.getPropertyName())) { |
509 |
Project p = getLookup().lookup(Project.class); |
510 |
if (p == null) { |
511 |
return; |
436 |
} |
512 |
} |
|
|
513 |
FileObject fo = p.getProjectDirectory(); |
514 |
Project newProj = (Project)e.getNewValue(); |
515 |
assert newProj != null; |
516 |
if (newProj.getProjectDirectory().equals(fo)) { |
517 |
ProjectChildren ch = (ProjectChildren)getParentNode().getChildren(); |
518 |
Node n = ch.logicalViewForProject(newProj, null); |
519 |
changeOriginal(n, true); |
520 |
updateLookup(n); |
521 |
} |
522 |
} |
523 |
} |
437 |
|
524 |
|
438 |
private boolean isMain() { |
525 |
private boolean isMain() { |
439 |
Project p = getLookup().lookup(Project.class); |
526 |
Project p = getLookup().lookup(Project.class); |
440 |
return p != null && OpenProjectList.getDefault().isMainProject( p ); |
527 |
return p != null && OpenProjectList.getDefault().isMainProject( p ); |
441 |
} |
528 |
} |
442 |
|
529 |
|
|
|
530 |
} // end of BadgingNode |
531 |
|
532 |
private static final class BadgingLookup extends ProxyLookup { |
533 |
public BadgingLookup(Lookup... lkps) { |
534 |
super(lkps); |
443 |
} |
535 |
} |
|
|
536 |
public void setMyLookups(Lookup... lkps) { |
537 |
setLookups(lkps); |
538 |
} |
539 |
} // end of BadgingLookup |
444 |
|
540 |
|
445 |
/** |
541 |
/** |
446 |
* Produce a {@link SearchInfo} variant that is always searchable, for speed. |
542 |
* Produce a {@link SearchInfo} variant that is always searchable, for speed. |