Add NotificationGroup with example (#257)

* Add NotificationGroup with example

Because Notifications.Bus.register() is deprecated

* Refactor code snippet after review

Move NotificationGroup instance to class constant
This commit is contained in:
Grig Alex 2020-03-03 19:47:17 +03:00 committed by GitHub
parent 1cd2fcd51f
commit 40e0954e20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -48,7 +48,36 @@ The `groupDisplayId` parameter of the
[`Notification`](upsource:///platform/platform-api/src/com/intellij/notification/Notification.java) [`Notification`](upsource:///platform/platform-api/src/com/intellij/notification/Notification.java)
constructor specifies a notification type. constructor specifies a notification type.
The user can choose the display type corresponding to each notification type under `Settings | Appearance and Behavior | Notifications`. The user can choose the display type corresponding to each notification type under `Settings | Appearance and Behavior | Notifications`.
To specify the preferred display type, you need to call To specify the preferred display type, you need to use
[`Notifications.Bus.register()`](upsource:///platform/platform-api/src/com/intellij/notification/Notifications.java) [`NotificationGroup`](upsource:///platform/platform-api/src/com/intellij/notification/NotificationGroup.java)
before displaying any notifications. to create notifications.
### Example
Simple use of notifications using
[`NotificationGroup`](upsource:///platform/platform-api/src/com/intellij/notification/NotificationGroup.java).
```java
public class MyGroovyDSLErrorsNotifier {
private final NotificationGroup NOTIFICATION_GROUP = new NotificationGroup("Groovy DSL errors", NotificationDisplayType.BALLOON, true);
public Notification notify(String content) {
return notify(null, content);
}
public Notification notify(Project project, String content) {
final Notification notification = NOTIFICATION_GROUP.createNotification(content, NotificationType.ERROR);
notification.notify(project);
return notification;
}
}
```
Usage of the class with
[`NotificationGroup`](upsource:///platform/platform-api/src/com/intellij/notification/NotificationGroup.java)
above.
```java
MyGroovyDSLErrorsNotifier myGroovyDSLErrorsNotifier = new MyGroovyDSLErrorsNotifier();
myGroovyDSLErrorsNotifier.notify("Some Groovy DSL error text");
```