Ver*_*gon 13
事实证明,您必须创建一个NotificationGroup实例,然后使用它来进行通知,并将通知和Project传递给Notifications.Bus.notify().
public class VoiceApplicationComponentImpl implements ApplicationComponent, VoiceApplicationComponent {
...
public static final NotificationGroup GROUP_DISPLAY_ID_INFO =
new NotificationGroup("My notification group",
NotificationDisplayType.BALLOON, true);
...
void showMyMessage(String message) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
Notification notification = GROUP_DISPLAY_ID_INFO.createNotification(message, NotificationType.ERROR);
Project[] projects = ProjectManager.getInstance().getOpenProjects();
Notifications.Bus.notify(notification, projects[0]);
}
});
}
Run Code Online (Sandbox Code Playgroud)
注意:您可能有更好的方法来获取当前的项目,现在我只假设有一个打开的项目.这意味着我的方法在启动时不起作用(项目数组为空).
另一个注意事项:你可能不需要用invokeLater包装,但我做了,因为我在另一个线程中调用了showMyMessage.