Java Code Examples for com.intellij.notification.Notification#notify()

The following examples show how to use com.intellij.notification.Notification#notify() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private Notification showRunNotification(@NotNull FlutterApp app, @Nullable String title, @NotNull String content, boolean isError) {
  final String toolWindowId = app.getMode() == RunMode.DEBUG ? ToolWindowId.DEBUG : ToolWindowId.RUN;
  final NotificationGroup notificationGroup = getNotificationGroup(toolWindowId);
  final Notification notification;
  if (title == null) {
    notification = notificationGroup.createNotification(content, isError ? NotificationType.ERROR : NotificationType.INFORMATION);
  }
  else {
    notification =
      notificationGroup.createNotification(title, content, isError ? NotificationType.ERROR : NotificationType.INFORMATION, null);
  }
  notification.setIcon(FlutterIcons.Flutter);
  notification.notify(myProject);

  lastNotification = notification;

  return notification;
}
 
Example 2
private Notification showRunNotification(@NotNull FlutterApp app, @Nullable String title, @NotNull String content, boolean isError) {
  final String toolWindowId = app.getMode() == RunMode.DEBUG ? ToolWindowId.DEBUG : ToolWindowId.RUN;
  final NotificationGroup notificationGroup = getNotificationGroup(toolWindowId);
  final Notification notification;
  if (title == null) {
    notification = notificationGroup.createNotification(content, isError ? NotificationType.ERROR : NotificationType.INFORMATION);
  }
  else {
    notification =
      notificationGroup.createNotification(title, content, isError ? NotificationType.ERROR : NotificationType.INFORMATION, null);
  }
  notification.setIcon(FlutterIcons.Flutter);
  notification.notify(myProject);

  lastNotification = notification;

  return notification;
}
 
Example 3
/**
 * Template came from maven plugin:
 * https://github.com/JetBrains/intellij-community/blob/b5d046018b9a82fccd86bc9c1f1da2e28068440a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenImportNotifier.java#L92-L108
 */
static void notify(Project project) {
  if(hasExistingRefreshNotification(project)){
    return;
  }

  Notification notification = new Notification(
    PantsConstants.PANTS,
    NOTIFICATION_TITLE,
    "<a href='refresh'>" + NOTIFICATION_BUTTON_TITLE + "</a> ",
    NotificationType.INFORMATION,
    new ProjectRefreshListener(project)
  );

  notification.notify(project);
}
 
Example 4
private static void showNotify(final Project project, final String pluginFileName, final File unityPluginFile, @Nonnull String title, @Nonnull List<VirtualFile> oldPluginFiles)
{
	Notification notification = new Notification(ourGroup.getDisplayId(), "Unity3D Plugin", title, !oldPluginFiles.isEmpty() ? NotificationType.ERROR : NotificationType.INFORMATION);
	notification.setListener((thisNotification, hyperlinkEvent) ->
	{
		thisNotification.hideBalloon();

		switch(hyperlinkEvent.getDescription())
		{
			case "info":
				BrowserUtil.browse("https://github.com/consulo/consulo/issues/250");
				break;
			case "update":
				updatePlugin(project, pluginFileName, unityPluginFile, oldPluginFiles);
				break;
		}
	});
	notification.notify(project);
}
 
Example 5
private static void notifyFailed(Project project, String message) {
  Notification notification =
      NOTIFICATION_GROUP.createNotification(
          "Failed to add source file to project",
          message,
          NotificationType.WARNING,
          /* listener= */ null);
  notification.notify(project);
}
 
Example 6
Source Project: intellij   File: FastBuildSuggestion.java    License: Apache License 2.0 5 votes vote down vote up
public void displayNotification(BlazeCommandRunConfiguration runProfile) {
  long msSinceLastDisplay = System.currentTimeMillis() - state.lastDisplayedTimeMs;

  if (state.triedFastBuild
      || state.timesDisplayed >= MAX_TIMES_TO_DISPLAY
      || msSinceLastDisplay < MINIMUM_TIME_BETWEEN_DISPLAY.toMillis()) {
    return;
  }

  if (!FastBuildConfigurationRunner.canRun(runProfile)
      || !isGoodCandidateForFastRun(runProfile)) {
    return;
  }

  logDisplay(msSinceLastDisplay);

  Notification notification =
      new Notification(
          NOTIFICATION_GROUP.getDisplayId(),
          NOTIFICATION_TITLE,
          "Tip: Try speeding up your Java tests by running them without Blaze using "
              + "<a href=\""
              + URL
              + "\">fast builds</a>.",
          NotificationType.INFORMATION,
          new OpenLinkAndLog());
  notification.notify(runProfile.getProject());
  state.lastDisplayedTimeMs = System.currentTimeMillis();
  state.timesDisplayed++;
}
 
Example 7
private void displayNewUserNotification(Project project, GoogleJavaFormatSettings settings) {
  Notification notification =
      new Notification(
          NOTIFICATION_GROUP.getDisplayId(),
          NOTIFICATION_TITLE,
          "The google-java-format plugin is disabled by default. "
              + "<a href=\"enable\">Enable for this project</a>.",
          NotificationType.INFORMATION,
          (n, e) -> {
            settings.setEnabled(true);
            n.expire();
          });
  notification.notify(project);
}
 
Example 8
Source Project: consulo   File: JBViewport.java    License: Apache License 2.0 5 votes vote down vote up
private static Notification notify(String message) {
  Notification notification = NOTIFICATION_GROUP.createNotification(message, NotificationType.INFORMATION);
  notification.notify(null);

  Timer timer = new Timer(NOTIFICATION_TIMEOUT, event -> notification.expire());
  timer.setRepeats(false);
  timer.start();

  return notification;
}
 
Example 9
private static void showNotification(@Nonnull DiffViewerBase viewer, @Nonnull Notification notification) {
  JComponent component = viewer.getComponent();

  Window awtWindow = UIUtil.getWindow(component);

  if (awtWindow != null) {
    consulo.ui.Window uiWindow = TargetAWT.from(awtWindow);

    IdeFrame ideFrame = uiWindow.getUserData(IdeFrame.KEY);

    if (ideFrame != null && NotificationsManagerImpl.findWindowForBalloon(viewer.getProject()) == awtWindow) {
      notification.notify(viewer.getProject());
      return;
    }
  }

  Balloon balloon = NotificationsManagerImpl.createBalloon(component, notification, false, true, null, viewer);

  Dimension componentSize = component.getSize();
  Dimension balloonSize = balloon.getPreferredSize();

  int width = Math.min(balloonSize.width, componentSize.width);
  int height = Math.min(balloonSize.height, componentSize.height);

  // top-right corner, 20px to the edges
  RelativePoint point = new RelativePoint(component, new Point(componentSize.width - 20 - width / 2, 20 + height / 2));
  balloon.show(point, Balloon.Position.above);
}
 
Example 10
void handleFileTooBigException(Logger logger, FilesTooBigForDiffException e, @Nonnull PsiFile file) {
  logger.info("Error while calculating changed ranges for: " + file.getVirtualFile(), e);
  if (!ApplicationManager.getApplication().isUnitTestMode()) {
    Notification notification =
            new Notification(ApplicationBundle.message("reformat.changed.text.file.too.big.notification.groupId"), ApplicationBundle.message("reformat.changed.text.file.too.big.notification.title"),
                             ApplicationBundle.message("reformat.changed.text.file.too.big.notification.text", file.getName()), NotificationType.INFORMATION);
    notification.notify(file.getProject());
  }
}
 
Example 11
Source Project: GitToolBox   File: GtNotifierImpl.java    License: Apache License 2.0 4 votes vote down vote up
@NotNull
private Notification notify(@NotNull Notification notification) {
  notification.notify(project);
  return notification;
}
 
Example 12
Source Project: SVNToolBox   File: ShowLockInfoTask.java    License: Apache License 2.0 4 votes vote down vote up
private void showNoLockNotification(Project project) {
    final Notification notification = createNoLockNotification();
  SvnToolBoxApp.getInstance().schedule(() -> UIUtil.invokeAndWaitIfNeeded((Runnable) notification::expire),
      5, TimeUnit.SECONDS);
    notification.notify(project);
}
 
Example 13
private void applyNotification(@Nonnull final Notification notification) {
  if (!myProject.isDisposed() && myProject.isOpen()) {
    notification.notify(myProject);
  }
}
 
Example 14
Source Project: consulo   File: SystemShortcuts.java    License: Apache License 2.0 4 votes vote down vote up
private void doNotify(@Nonnull Keymap keymap, @Nonnull String actionId, @Nonnull KeyStroke sysKS, @Nullable String macOsShortcutAction, @Nonnull KeyboardShortcut conflicted) {
  if (!ourIsNotificationRegistered) {
    ourIsNotificationRegistered = true;
    NotificationsConfiguration.getNotificationsConfiguration().register(ourNotificationGroupId, NotificationDisplayType.STICKY_BALLOON, true);
  }

  final AnAction act = ActionManager.getInstance().getAction(actionId);
  final String actText = act == null ? actionId : act.getTemplateText();
  final String message = "The " +
                         actText +
                         " shortcut conflicts with macOS shortcut" +
                         (macOsShortcutAction == null ? "" : " '" + macOsShortcutAction + "'") +
                         ". Modify this shortcut or change macOS system settings.";
  final Notification notification = new Notification(ourNotificationGroupId, "Shortcuts conflicts", message, NotificationType.WARNING, null);

  final AnAction configureShortcut = DumbAwareAction.create("Modify shortcut", e -> {
    Component component = e.getDataContext().getData(PlatformDataKeys.CONTEXT_COMPONENT);
    if (component == null) {
      Window[] frames = Window.getWindows();
      component = frames == null || frames.length == 0 ? null : frames[0];
      if (component == null) {
        LOG.error("can't show KeyboardShortcutDialog (parent component wasn't found)");
        return;
      }
    }

    KeymapPanel.addKeyboardShortcut(actionId, ActionShortcutRestrictions.getInstance().getForActionId(actionId), keymap, component, conflicted, SystemShortcuts.this);
    notification.expire();
  });
  notification.addAction(configureShortcut);

  final AnAction muteAction = DumbAwareAction.create("Don't show again", e -> {
    myMutedConflicts.addMutedAction(actionId);
    notification.expire();
  });
  notification.addAction(muteAction);

  if (SystemInfo.isMac) {
    final AnAction changeSystemSettings = DumbAwareAction.create("Change system settings", e -> {
      ApplicationManager.getApplication().executeOnPooledThread(() -> {
        final GeneralCommandLine cmdLine =
                new GeneralCommandLine("osascript", "-e", "tell application \"System Preferences\"", "-e", "set the current pane to pane id \"com.apple.preference.keyboard\"", "-e",
                                       "reveal anchor \"shortcutsTab\" of pane id \"com.apple.preference.keyboard\"", "-e", "activate", "-e", "end tell");
        try {
          ExecUtil.execAndGetOutput(cmdLine);
          // NOTE: we can't detect OS-settings changes
          // but we can try to schedule check conflicts (and expire notification if necessary)
        }
        catch (ExecutionException ex) {
          LOG.error(ex);
        }
      });
    });
    notification.addAction(changeSystemSettings);
  }

  myNotifiedActions.add(actionId);
  notification.notify(null);
}