vcs balloon: show balloon for any modal component

This commit is contained in:
irengrig
2012-10-25 16:49:53 +04:00
parent c443380b88
commit 076dc9b29d
@@ -22,12 +22,15 @@ import com.intellij.notification.NotificationType;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.ui.MessageType;
import com.intellij.openapi.ui.popup.Balloon;
import com.intellij.openapi.ui.popup.BalloonBuilder;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.util.NamedRunnable;
import com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager;
import com.intellij.openapi.wm.IdeFocusManager;
import com.intellij.openapi.wm.IdeFrame;
import com.intellij.ui.awt.RelativePoint;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -35,7 +38,6 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import java.awt.*;
import java.util.concurrent.TimeUnit;
/**
* Shows a notification balloon over one of version control related tool windows: Changes View or Version Control View.
@@ -127,7 +129,35 @@ public class VcsBalloonProblemNotifier implements Runnable {
notification.notify(myProject.isDefault() ? null : myProject);
}
public static void showBalloonForComponent(@NotNull JComponent component, @NotNull final String message, final MessageType type,
public static void showBalloonForActiveComponent(@NotNull final String message, final MessageType type) {
Window[] windows = Window.getWindows();
Window targetWindow = null;
for (Window each : windows) {
if (each.isActive()) {
targetWindow = each;
break;
}
}
if (targetWindow == null) {
targetWindow = JOptionPane.getRootFrame();
}
if (targetWindow == null) {
final IdeFrame frame = IdeFocusManager.findInstance().getLastFocusedFrame();
if (frame == null) {
final Project[] projects = ProjectManager.getInstance().getOpenProjects();
showOverChangesView(projects == null || projects.length == 0 ? ProjectManager.getInstance().getDefaultProject() : projects[0],
message, type);
return;
}
showBalloonForComponent(frame.getComponent(), message, type, true);
} else {
showBalloonForComponent(targetWindow, message, type, true);
}
}
public static void showBalloonForComponent(@NotNull Component component, @NotNull final String message, final MessageType type,
final boolean atTop) {
BalloonBuilder balloonBuilder = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(message, type, null);
Balloon balloon = balloonBuilder.createBalloon();