more appropriate dispose objects for general "show popup for component" - if any found

This commit is contained in:
irengrig
2013-02-08 17:26:56 +04:00
parent 4120a63c5e
commit f65b29d22e
3 changed files with 7 additions and 46 deletions
@@ -15,6 +15,7 @@
*/
package com.intellij.openapi.ui.popup.util;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
@@ -136,15 +137,15 @@ public class PopupUtil {
final Project project = projects == null || projects.length == 0 ? ProjectManager.getInstance().getDefaultProject() : projects[0];
final JFrame jFrame = WindowManager.getInstance().getFrame(project);
if (jFrame != null) {
showBalloonForComponent(jFrame, message, type, true);
showBalloonForComponent(jFrame, message, type, true, project);
} else {
LOG.info("Can not get component to show message: " + message);
}
return;
}
showBalloonForComponent(frame.getComponent(), message, type, true);
showBalloonForComponent(frame.getComponent(), message, type, true, frame.getProject());
} else {
showBalloonForComponent(targetWindow, message, type, true);
showBalloonForComponent(targetWindow, message, type, true, null);
}
}
};
@@ -152,9 +153,9 @@ public class PopupUtil {
}
public static void showBalloonForComponent(@NotNull Component component, @NotNull final String message, final MessageType type,
final boolean atTop) {
final boolean atTop, @Nullable final Disposable disposable) {
BalloonBuilder balloonBuilder = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(message, type, null);
balloonBuilder.setDisposable(ApplicationManager.getApplication());
balloonBuilder.setDisposable(disposable == null ? ApplicationManager.getApplication() : disposable);
Balloon balloon = balloonBuilder.createBalloon();
Dimension size = component.getSize();
Balloon.Position position;
@@ -228,7 +228,7 @@ public class VcsHistoryDialog extends DialogWrapper implements DataProvider {
@Override
public void run() {
if (! VcsHistoryDialog.this.isShowing()) return;
PopupUtil.showBalloonForComponent(VcsHistoryDialog.this.getRootPane(), canNoLoadMessage(e), MessageType.ERROR, true);
PopupUtil.showBalloonForComponent(VcsHistoryDialog.this.getRootPane(), canNoLoadMessage(e), MessageType.ERROR, true, myProject);
}
});
}
@@ -22,20 +22,13 @@ 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.util.PopupUtil;
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.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import java.awt.*;
/**
* Shows a notification balloon over one of version control related tool windows: Changes View or Version Control View.
@@ -126,37 +119,4 @@ public class VcsBalloonProblemNotifier implements Runnable {
}
notification.notify(myProject.isDefault() ? null : myProject);
}
public static void showBalloonForActiveComponent(@NotNull final String message, final MessageType type) {
Runnable runnable = new Runnable() {
public void run() {
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;
}
PopupUtil.showBalloonForComponent(frame.getComponent(), message, type, true);
} else {
PopupUtil.showBalloonForComponent(targetWindow, message, type, true);
}
}
};
UIUtil.invokeLaterIfNeeded(runnable);
}
}