mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-30 02:07:50 +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)
|
[`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");
|
||||||
|
```
|
||||||
|
Loading…
x
Reference in New Issue
Block a user