Prevent NPE in AbstractPopup and add corresponding logging

This commit is contained in:
Sergey Malenkov
2014-07-22 17:21:50 +04:00
parent 5a49a15781
commit 4c997e0874
@@ -337,7 +337,7 @@ public class AbstractPopup implements JBPopup {
}
public void setShowHints(boolean show) {
final Window ancestor = SwingUtilities.getWindowAncestor(myComponent);
final Window ancestor = getContentWindow(myComponent);
if (ancestor instanceof RootPaneContainer) {
final JRootPane rootPane = ((RootPaneContainer)ancestor).getRootPane();
if (rootPane != null) {
@@ -828,7 +828,7 @@ public class AbstractPopup implements JBPopup {
myPopup.setRequestFocus(myRequestFocus);
myPopup.show();
final Window window = SwingUtilities.getWindowAncestor(myContent);
final Window window = getContentWindow(myContent);
myWindow = window;
@@ -1208,14 +1208,17 @@ public class AbstractPopup implements JBPopup {
size = computeWindowSize(size);
final Window window = SwingUtilities.getWindowAncestor(myContent);
window.setSize(size);
final Window window = getContentWindow(myContent);
if (window != null) {
window.setSize(size);
}
}
public void pack() {
final Window window = SwingUtilities.getWindowAncestor(myContent);
window.pack();
final Window window = getContentWindow(myContent);
if (window != null) {
window.pack();
}
}
public JComponent getComponent() {
@@ -1234,6 +1237,10 @@ public class AbstractPopup implements JBPopup {
}
myDisposed = true;
if (LOG.isDebugEnabled()) {
LOG.debug("start disposing " + myContent);
}
Disposer.dispose(this, false);
ApplicationManager.getApplication().assertIsDispatchThread();
@@ -1280,6 +1287,10 @@ public class AbstractPopup implements JBPopup {
IdeFocusManager.getInstance(myProject).typeAheadUntil(typeAheadDone);
getFocusManager().doWhenFocusSettlesDown(runFinal);
}
if (LOG.isDebugEnabled()) {
LOG.debug("stop disposing content");
}
}
private void resetWindow() {
@@ -1408,15 +1419,27 @@ public class AbstractPopup implements JBPopup {
}
public static Window moveTo(JComponent content, Point screenPoint, final Dimension headerCorrectionSize) {
setDefaultCursor(content);
final Window wnd = SwingUtilities.getWindowAncestor(content);
if (headerCorrectionSize != null) {
screenPoint.y -= headerCorrectionSize.height;
final Window wnd = getContentWindow(content);
if (wnd != null) {
wnd.setCursor(Cursor.getDefaultCursor());
if (headerCorrectionSize != null) {
screenPoint.y -= headerCorrectionSize.height;
}
wnd.setLocation(screenPoint);
}
wnd.setLocation(screenPoint);
return wnd;
}
private static Window getContentWindow(Component content) {
Window window = SwingUtilities.getWindowAncestor(content);
if (window == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("no window ancestor for " + content);
}
}
return window;
}
@Override
public Point getLocationOnScreen() {
Dimension headerCorrectionSize = myLocateByContent ? myHeaderPanel.getPreferredSize() : null;
@@ -1490,7 +1513,7 @@ public class AbstractPopup implements JBPopup {
}
public static void setDefaultCursor(JComponent content) {
final Window wnd = SwingUtilities.getWindowAncestor(content);
final Window wnd = getContentWindow(content);
if (wnd != null) {
wnd.setCursor(Cursor.getDefaultCursor());
}