From 799448d3ebd576a35174ab8ed4985b22f01e2046 Mon Sep 17 00:00:00 2001 From: Nikolay Chashnikov Date: Fri, 11 Sep 2009 14:27:26 +0400 Subject: [PATCH] hide notification about detected facet if it is removed --- .../autodetecting/DetectedFacetManager.java | 53 ++++++++++++------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/DetectedFacetManager.java b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/DetectedFacetManager.java index c8cee86cc6ae..a326fe802076 100644 --- a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/DetectedFacetManager.java +++ b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/DetectedFacetManager.java @@ -56,7 +56,7 @@ public class DetectedFacetManager implements Disposable { private final Set> myPendingNewFacets = new HashSet>(); private final Alarm myNotificationAlarm = new Alarm(); private final ProjectFacetInfoSet myDetectedFacetSet; - private final List myNotifications = new ArrayList(); + private final List myNotifications = new ArrayList(); public DetectedFacetManager(final Project project, final FacetAutodetectingManagerImpl autodetectingManager, final ProjectFacetInfoSet detectedFacetSet) { @@ -66,12 +66,12 @@ public class DetectedFacetManager implements Disposable { myAutodetectingManager = autodetectingManager; myDetectedFacetSet.addListener(new ProjectFacetInfoSet.DetectedFacetListener() { public void facetDetected(final DetectedFacetInfo info) { - onDetectedFacetChanged(Collections.singletonList(info)); + onDetectedFacetChanged(Collections.singletonList(info), Collections.>emptyList()); } public void facetRemoved(final DetectedFacetInfo info) { myAutodetectingManager.getFileIndex().removeFromIndex(info); - onDetectedFacetChanged(Collections.>emptyList()); + onDetectedFacetChanged(Collections.>emptyList(), Collections.singletonList(info)); } }); Disposer.register(myProject, this); @@ -91,19 +91,19 @@ public class DetectedFacetManager implements Disposable { return myProject; } - public void onDetectedFacetChanged(@NotNull final Collection> added) { + public void onDetectedFacetChanged(@NotNull final Collection> added, @NotNull final Collection> removed) { if (!myUIInitialized) return; if (!ApplicationManager.getApplication().isHeadlessEnvironment()) { - final boolean clearNotifications = myDetectedFacetSet.getAllDetectedFacets().isEmpty(); - Runnable runnable = new Runnable() { public void run() { if (isDisposed()) return; myPendingNewFacets.addAll(added); - if (clearNotifications) { - //getNotifications().invalidateAll(NOTIFICATION_ID); + for (FacetDetectedNotification notification : myNotifications) { + for (DetectedFacetInfo facetInfo : removed) { + notification.processFacetRemoved(facetInfo); + } } queueNotificationPopup(); } @@ -145,14 +145,14 @@ public class DetectedFacetManager implements Disposable { HashMap, List> filesMap = getFilesMap(newFacets); if (!filesMap.isEmpty() && showNotification) { final Set> detectedFacetInfos = filesMap.keySet(); - final Notification notification; + final FacetDetectedNotification notification; if (filesMap.size() == 1) { final DetectedFacetInfo facetInfo = detectedFacetInfos.iterator().next(); final List files = filesMap.get(facetInfo); notification = createSingleFacetDetectedNotification(facetInfo, files.toArray(new VirtualFile[files.size()])); } else { - notification = createSeveralFacetsDetectedNotification(filesMap.size()); + notification = createSeveralFacetsDetectedNotification(filesMap.keySet()); } myNotifications.add(notification); Notifications.Bus.notify(notification, myProject); @@ -167,7 +167,7 @@ public class DetectedFacetManager implements Disposable { public void initUI() { myUIInitialized = true; - onDetectedFacetChanged(myDetectedFacetSet.getAllDetectedFacets()); + onDetectedFacetChanged(myDetectedFacetSet.getAllDetectedFacets(), Collections.>emptyList()); } public void disposeUI() { @@ -291,7 +291,7 @@ public class DetectedFacetManager implements Disposable { return FacetManager.getInstance(module).createFacet(facetType, info.getFacetName(), (C)info.getConfiguration(), underlyingFacet); } - private Notification createSingleFacetDetectedNotification(final DetectedFacetInfo detectedFacetInfo, final VirtualFile[] files) { + private FacetDetectedNotification createSingleFacetDetectedNotification(final DetectedFacetInfo detectedFacetInfo, final VirtualFile[] files) { DetectedFacetPresentation presentation = FacetDetectorRegistryEx.getDetectedFacetPresentation(detectedFacetInfo.getFacetType()); String text = presentation.getAutodetectionPopupText(detectedFacetInfo.getModule(), detectedFacetInfo.getFacetType(), @@ -303,7 +303,7 @@ public class DetectedFacetManager implements Disposable { final String description = ProjectBundle.message("facet.autodetected.info.text", detectedFacetInfo.getFacetType().getPresentableName(), text, detectedFacetInfo.getFacetName()); final String title = ProjectBundle.message("notification.name.0.facet.detected", detectedFacetInfo.getFacetType().getPresentableName()); - return new Notification(NOTIFICATION_ID, title, description, NotificationType.INFORMATION, new NotificationListener() { + return new FacetDetectedNotification(title, description, new NotificationListener() { public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) { if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { notification.expire(); @@ -329,13 +329,13 @@ public class DetectedFacetManager implements Disposable { } } } - }); + }, Collections.singletonList(detectedFacetInfo)); } - private Notification createSeveralFacetsDetectedNotification(final int facetsNumber) { - final String title = ProjectBundle.message("notification.name.0.facets.detected", facetsNumber); - final String content = ProjectBundle.message("facet.autodetection.several.facets.detected.text", facetsNumber); - return new Notification(NOTIFICATION_ID, title, content, NotificationType.INFORMATION, new NotificationListener() { + private FacetDetectedNotification createSeveralFacetsDetectedNotification(final Set> facets) { + final String title = ProjectBundle.message("notification.name.0.facets.detected", facets.size()); + final String content = ProjectBundle.message("facet.autodetection.several.facets.detected.text", facets.size()); + return new FacetDetectedNotification(title, content, new NotificationListener() { public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) { if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { if (isDisposed()) { @@ -347,7 +347,7 @@ public class DetectedFacetManager implements Disposable { } } } - }); + }, facets); } private void removeAllNotifications() { @@ -391,6 +391,21 @@ public class DetectedFacetManager implements Disposable { } myAutodetectingManager.removeFacetFromCache(facet); } + } + private static class FacetDetectedNotification extends Notification { + private List> myFacets = new ArrayList>(); + + private FacetDetectedNotification(@NotNull String title, @NotNull String content, NotificationListener listener, Collection> facets) { + super(NOTIFICATION_ID, title, content, NotificationType.INFORMATION, listener); + myFacets.addAll(facets); + } + + public void processFacetRemoved(DetectedFacetInfo facetInfo) { + myFacets.remove(facetInfo); + if (myFacets.isEmpty() && !isExpired()) { + expire(); + } + } } }