use of com.intellij.openapi.project.ProjectManagerAdapter in project intellij by bazelbuild.
the class JUnitPluginDependencyWarning method notifyJUnitNotEnabled.
/**
* Pop up a notification asking user to enable the JUnit plugin, and also add an error item to the
* event log.
*/
private static void notifyJUnitNotEnabled() {
String buildSystem = Blaze.defaultBuildSystemName();
String message = String.format("<html>The JUnit plugin is disabled, but it's required for the %s plugin to function." + "<br>Please <a href=\"fix\">enable the JUnit plugin</a> and restart the IDE", buildSystem);
NotificationListener listener = new NotificationListener.Adapter() {
@Override
protected void hyperlinkActivated(Notification notification, HyperlinkEvent e) {
if ("fix".equals(e.getDescription())) {
PluginUtils.installOrEnablePlugin(JUNIT_PLUGIN_ID);
}
}
};
Notification notification = new Notification(buildSystem + " Plugin Error", buildSystem + " plugin dependencies are missing", message, NotificationType.ERROR, listener);
notification.setImportant(true);
Application app = ApplicationManager.getApplication();
MessageBusConnection connection = app.getMessageBus().connect(app);
connection.subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener.Adapter() {
@Override
public void appStarting(@Nullable Project projectFromCommandLine) {
// Adds an error item to the 'Event Log' tab.
// Easy to ignore, but remains in event log until manually cleared.
Transactions.submitTransactionAndWait(() -> Notifications.Bus.notify(notification));
}
@Override
public void appFrameCreated(String[] commandLineArgs, Ref<Boolean> willOpenProject) {
// Popup dialog in welcome screen.
app.invokeLater(() -> showPopupNotification(message));
}
});
if (!ApplicationManager.getApplication().isHeadlessEnvironment()) {
connection.subscribe(ProjectManager.TOPIC, new ProjectManagerAdapter() {
@Override
public void projectOpened(Project project) {
// Popup dialog on project open, for users bypassing the welcome screen.
if (Blaze.isBlazeProject(project)) {
app.invokeLater(() -> showPopupNotification(message));
}
}
});
}
}
Aggregations