Lines 54-63
Link Here
|
54 |
import java.util.logging.Level; |
54 |
import java.util.logging.Level; |
55 |
import java.util.logging.LogRecord; |
55 |
import java.util.logging.LogRecord; |
56 |
import java.util.logging.Logger; |
56 |
import java.util.logging.Logger; |
|
|
57 |
import javax.swing.Icon; |
57 |
import org.netbeans.modules.projectapi.SimpleFileOwnerQueryImplementation; |
58 |
import org.netbeans.modules.projectapi.SimpleFileOwnerQueryImplementation; |
58 |
import org.netbeans.modules.projectapi.TimedWeakReference; |
59 |
import org.netbeans.modules.projectapi.TimedWeakReference; |
59 |
import org.netbeans.spi.project.FileOwnerQueryImplementation; |
60 |
import org.netbeans.spi.project.FileOwnerQueryImplementation; |
60 |
import org.netbeans.spi.project.ProjectFactory; |
61 |
import org.netbeans.spi.project.ProjectFactory; |
|
|
62 |
import org.netbeans.spi.project.ProjectFactory2; |
61 |
import org.netbeans.spi.project.ProjectState; |
63 |
import org.netbeans.spi.project.ProjectState; |
62 |
import org.openide.filesystems.FileChangeAdapter; |
64 |
import org.openide.filesystems.FileChangeAdapter; |
63 |
import org.openide.filesystems.FileChangeListener; |
65 |
import org.openide.filesystems.FileChangeListener; |
Lines 65-70
Link Here
|
65 |
import org.openide.filesystems.FileObject; |
67 |
import org.openide.filesystems.FileObject; |
66 |
import org.openide.filesystems.FileSystem; |
68 |
import org.openide.filesystems.FileSystem; |
67 |
import org.openide.filesystems.FileUtil; |
69 |
import org.openide.filesystems.FileUtil; |
|
|
70 |
import org.openide.util.ImageUtilities; |
68 |
import org.openide.util.Lookup; |
71 |
import org.openide.util.Lookup; |
69 |
import org.openide.util.LookupEvent; |
72 |
import org.openide.util.LookupEvent; |
70 |
import org.openide.util.LookupListener; |
73 |
import org.openide.util.LookupListener; |
Lines 388-393
Link Here
|
388 |
* @throws IllegalArgumentException if the supplied file object is null or not a folder |
391 |
* @throws IllegalArgumentException if the supplied file object is null or not a folder |
389 |
*/ |
392 |
*/ |
390 |
public boolean isProject(final FileObject projectDirectory) throws IllegalArgumentException { |
393 |
public boolean isProject(final FileObject projectDirectory) throws IllegalArgumentException { |
|
|
394 |
return isProject2(projectDirectory) != null; |
395 |
} |
396 |
|
397 |
public Result isProject2(final FileObject projectDirectory) throws IllegalArgumentException { |
391 |
if (projectDirectory == null) { |
398 |
if (projectDirectory == null) { |
392 |
throw new IllegalArgumentException("Attempted to pass a null directory to isProject"); // NOI18N |
399 |
throw new IllegalArgumentException("Attempted to pass a null directory to isProject"); // NOI18N |
393 |
} |
400 |
} |
Lines 397-407
Link Here
|
397 |
if (projectDirectory.isValid()) { |
404 |
if (projectDirectory.isValid()) { |
398 |
throw new IllegalArgumentException("Attempted to pass a non-directory to isProject: " + projectDirectory); // NOI18N |
405 |
throw new IllegalArgumentException("Attempted to pass a non-directory to isProject: " + projectDirectory); // NOI18N |
399 |
} else { |
406 |
} else { |
400 |
return false; |
407 |
return null; |
401 |
} |
408 |
} |
402 |
} |
409 |
} |
403 |
return mutex().readAccess(new Mutex.Action<Boolean>() { |
410 |
return mutex().readAccess(new Mutex.Action<Result>() { |
404 |
public Boolean run() { |
411 |
public Result run() { |
405 |
synchronized (dir2Proj) { |
412 |
synchronized (dir2Proj) { |
406 |
Union2<Reference<Project>,LoadStatus> o; |
413 |
Union2<Reference<Project>,LoadStatus> o; |
407 |
do { |
414 |
do { |
Lines 416-441
Link Here
|
416 |
} while (LoadStatus.LOADING_PROJECT.is(o)); |
423 |
} while (LoadStatus.LOADING_PROJECT.is(o)); |
417 |
assert !LoadStatus.LOADING_PROJECT.is(o); |
424 |
assert !LoadStatus.LOADING_PROJECT.is(o); |
418 |
if (LoadStatus.NO_SUCH_PROJECT.is(o)) { |
425 |
if (LoadStatus.NO_SUCH_PROJECT.is(o)) { |
419 |
return false; |
426 |
return null; |
420 |
} else if (o != null) { |
427 |
} else if (o != null) { |
421 |
// Reference<Project> or SOME_SUCH_PROJECT |
428 |
// Reference<Project> or SOME_SUCH_PROJECT |
422 |
return true; |
429 |
// rather check for result than load project and lookup projectInformation for icon. |
|
|
430 |
return checkForProject(projectDirectory); |
423 |
} |
431 |
} |
424 |
// Not in cache. |
432 |
// Not in cache. |
425 |
dir2Proj.put(projectDirectory, LoadStatus.LOADING_PROJECT.wrap()); |
433 |
dir2Proj.put(projectDirectory, LoadStatus.LOADING_PROJECT.wrap()); |
426 |
} |
434 |
} |
427 |
boolean resetLP = false; |
435 |
boolean resetLP = false; |
428 |
try { |
436 |
try { |
429 |
boolean p = checkForProject(projectDirectory); |
437 |
Result p = checkForProject(projectDirectory); |
430 |
synchronized (dir2Proj) { |
438 |
synchronized (dir2Proj) { |
431 |
resetLP = true; |
439 |
resetLP = true; |
432 |
dir2Proj.notifyAll(); |
440 |
dir2Proj.notifyAll(); |
433 |
if (p) { |
441 |
if (p != null) { |
434 |
dir2Proj.put(projectDirectory, LoadStatus.SOME_SUCH_PROJECT.wrap()); |
442 |
dir2Proj.put(projectDirectory, LoadStatus.SOME_SUCH_PROJECT.wrap()); |
435 |
return true; |
443 |
return p; |
436 |
} else { |
444 |
} else { |
437 |
dir2Proj.put(projectDirectory, LoadStatus.NO_SUCH_PROJECT.wrap()); |
445 |
dir2Proj.put(projectDirectory, LoadStatus.NO_SUCH_PROJECT.wrap()); |
438 |
return false; |
446 |
return null; |
439 |
} |
447 |
} |
440 |
} |
448 |
} |
441 |
} finally { |
449 |
} finally { |
Lines 449-466
Link Here
|
449 |
}); |
457 |
}); |
450 |
} |
458 |
} |
451 |
|
459 |
|
452 |
private boolean checkForProject(FileObject dir) { |
460 |
private Result checkForProject(FileObject dir) { |
453 |
assert dir != null; |
461 |
assert dir != null; |
454 |
assert dir.isFolder() : dir; |
462 |
assert dir.isFolder() : dir; |
455 |
assert mutex().isReadAccess(); |
463 |
assert mutex().isReadAccess(); |
456 |
Iterator it = factories.allInstances().iterator(); |
464 |
Iterator<? extends ProjectFactory> it = factories.allInstances().iterator(); |
457 |
while (it.hasNext()) { |
465 |
while (it.hasNext()) { |
458 |
ProjectFactory factory = (ProjectFactory)it.next(); |
466 |
ProjectFactory factory = it.next(); |
459 |
if (factory.isProject(dir)) { |
467 |
if (factory instanceof ProjectFactory2) { |
460 |
return true; |
468 |
Result res = ((ProjectFactory2)factory).isProject2(dir); |
|
|
469 |
if (res != null) { |
470 |
return res; |
471 |
} |
472 |
} else { |
473 |
if (factory.isProject(dir)) { |
474 |
return new Result((String)null); |
475 |
} |
461 |
} |
476 |
} |
462 |
} |
477 |
} |
463 |
return false; |
478 |
return null; |
464 |
} |
479 |
} |
465 |
|
480 |
|
466 |
/** |
481 |
/** |
Lines 671-675
Link Here
|
671 |
} |
686 |
} |
672 |
|
687 |
|
673 |
} |
688 |
} |
|
|
689 |
|
690 |
public static final class Result { |
691 |
private Icon icon; |
692 |
private String path; |
693 |
|
694 |
public Result(String iconpath) { |
695 |
path = iconpath; |
696 |
} |
697 |
|
698 |
public Result(Icon icon) { |
699 |
this.icon = icon; |
700 |
} |
701 |
|
702 |
public Icon getIcon() { |
703 |
if (icon == null) { |
704 |
if (path != null) { |
705 |
icon = ImageUtilities.image2Icon(ImageUtilities.loadImage(path)); |
706 |
} |
707 |
} |
708 |
return icon; |
709 |
} |
710 |
} |
711 |
|
674 |
|
712 |
|
675 |
} |
713 |
} |