fix popups: heavy/medium: restore state of factory after popup creation + delegate...
[idea/community.git] / platform / platform-impl / src / com / intellij / ui / popup / PopupComponent.java
index c62669b4b13bc89614f3eca457241763ec0b6401..445c642a0e0a644ebd5a960256725c3f530f2974 100644 (file)
 package com.intellij.ui.popup;
 
 import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.ui.popup.util.PopupUtil;
 import com.intellij.util.ReflectionUtil;
 
 import javax.swing.*;
 import java.awt.*;
-import java.lang.reflect.Method;
 
 public interface PopupComponent {
 
@@ -53,17 +53,12 @@ public interface PopupComponent {
       public PopupComponent getPopup(Component owner, Component content, int x, int y) {
         final PopupFactory factory = PopupFactory.getSharedInstance();
 
-        try {
-          final Method method = PopupFactory.class.getDeclaredMethod("setPopupType", int.class);
-          method.setAccessible(true);
-          method.invoke(factory, 2);
+        final int oldType = PopupUtil.getPopupType(factory);
+        PopupUtil.setPopupType(factory, 2);
+        final Popup popup = factory.getPopup(owner, content, x, y);
+        if (oldType >= 0) PopupUtil.setPopupType(factory, oldType);
 
-        }
-        catch (Throwable e) {
-          LOG.error(e);
-        }
-
-        return new AwtPopupWrapper(factory.getPopup(owner, content, x, y));
+        return new AwtPopupWrapper(popup);
       }
 
       public boolean isNativePopup() {