OwnerOptional (Component parentComponent) { Window owner = findOwnerByComponent(parentComponent); IdePopupManager manager = IdeEventQueue.getInstance().getPopupManager(); if (manager.isPopupWindow(owner)) { if (!owner.isFocused() || !SystemInfo.isJetBrainsJvm) { owner = owner.getOwner(); while (UIUtil.isSimpleWindow(owner)) { owner = owner.getOwner(); } } } if (owner instanceof Dialog ownerDialog) { if (!ownerDialog.isModal() && !UIUtil.isPossibleOwner(ownerDialog)) { while (owner instanceof Dialog && !((Dialog)owner).isModal()) { owner = owner.getOwner(); } } } while (owner != null && !owner.isShowing()) { owner = owner.getOwner(); } // Window cannot be parent of JDialog () if (UIUtil.isSimpleWindow(owner)) { owner = null; } return new OwnerOptional(owner); }