Extract single notification manager
This commit is contained in:
+12
-7
@@ -17,23 +17,28 @@
|
||||
package org.jetbrains.jet.plugin.configuration
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.jet.plugin.configuration.ui.ConfigureKotlinNotification
|
||||
import org.jetbrains.jet.plugin.configuration.ui.notifications.ConfigureKotlinNotification
|
||||
import com.intellij.notification.NotificationsManager
|
||||
import com.intellij.notification.Notification
|
||||
|
||||
object ConfigureKotlinNotificationManager {
|
||||
object ConfigureKotlinNotificationManager: KotlinSingleNotificationManager<ConfigureKotlinNotification> {
|
||||
fun notify(project: Project) {
|
||||
notify(project, ConfigureKotlinNotification(project, ConfigureKotlinNotification.getNotificationString(project)))
|
||||
}
|
||||
}
|
||||
|
||||
trait KotlinSingleNotificationManager<T: Notification> {
|
||||
fun notify(project: Project, notification: T) {
|
||||
val notificationsManager = NotificationsManager.getNotificationsManager()
|
||||
if (notificationsManager == null) {
|
||||
return
|
||||
}
|
||||
|
||||
val notificationString = ConfigureKotlinNotification.getNotificationString(project)
|
||||
|
||||
var isNotificationExists = false
|
||||
|
||||
val notifications = notificationsManager.getNotificationsOfType(javaClass<ConfigureKotlinNotification>(), project)
|
||||
val notifications = notificationsManager.getNotificationsOfType(notification.javaClass, project) as Array<Notification>
|
||||
for (oldNotification in notifications) {
|
||||
if (oldNotification.getNotificationText() == notificationString) {
|
||||
if (oldNotification == notification) {
|
||||
isNotificationExists = true
|
||||
}
|
||||
else {
|
||||
@@ -41,7 +46,7 @@ object ConfigureKotlinNotificationManager {
|
||||
}
|
||||
}
|
||||
if (!isNotificationExists) {
|
||||
ConfigureKotlinNotification(project, notificationString).showNotification()
|
||||
notification.notify(project)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+17
-11
@@ -34,7 +34,6 @@ public class ConfigureKotlinNotification extends Notification {
|
||||
private static final String GROUP_ID = "Configure Kotlin: balloon";
|
||||
private static final String TITLE = "Configure Kotlin";
|
||||
|
||||
@NotNull private final Project project;
|
||||
@NotNull private final String notificationText;
|
||||
|
||||
public ConfigureKotlinNotification(
|
||||
@@ -55,19 +54,9 @@ public class ConfigureKotlinNotification extends Notification {
|
||||
}
|
||||
});
|
||||
|
||||
this.project = project;
|
||||
this.notificationText = notificationText;
|
||||
}
|
||||
|
||||
public void showNotification() {
|
||||
super.notify(project);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getNotificationText() {
|
||||
return notificationText;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getNotificationString(Project project) {
|
||||
StringBuilder builder = new StringBuilder("Configure ");
|
||||
@@ -102,4 +91,21 @@ public class ConfigureKotlinNotification extends Notification {
|
||||
isOnlyOneModule ? ") module" : ") modules",
|
||||
"</a>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof ConfigureKotlinNotification)) return false;
|
||||
|
||||
ConfigureKotlinNotification that = (ConfigureKotlinNotification) o;
|
||||
|
||||
if (!notificationText.equals(that.notificationText)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return notificationText.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user