mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-29 17:57:53 +08:00
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:
parent
1cd2fcd51f
commit
40e0954e20
@ -48,7 +48,36 @@ The `groupDisplayId` parameter of the
|
||||
[`Notification`](upsource:///platform/platform-api/src/com/intellij/notification/Notification.java)
|
||||
constructor specifies a notification type.
|
||||
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
|
||||
[`Notifications.Bus.register()`](upsource:///platform/platform-api/src/com/intellij/notification/Notifications.java)
|
||||
before displaying any notifications.
|
||||
To specify the preferred display type, you need to use
|
||||
[`NotificationGroup`](upsource:///platform/platform-api/src/com/intellij/notification/NotificationGroup.java)
|
||||
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");
|
||||
```
|
||||
|
Loading…
x
Reference in New Issue
Block a user