private boolean dispatchMouseEvent(AWTEvent event) {
    if (event.getID() != MouseEvent.MOUSE_PRESSED) {
      return false;
    }

    if (myStack.isEmpty()) {
      return false;
    }

    AbstractPopup popup = (AbstractPopup)findPopup();

    final MouseEvent mouseEvent = (MouseEvent) event;

    Point point = (Point) mouseEvent.getPoint().clone();
    SwingUtilities.convertPointToScreen(point, mouseEvent.getComponent());

    boolean needStopFurtherEventProcessing = false;
    while (true) {
      if (popup != null && !popup.isDisposed()) {
        Window window = ComponentUtil.getWindow(mouseEvent.getComponent());
        if (window != null && window != popup.getPopupWindow() && SwingUtilities.isDescendingFrom(window, popup.getPopupWindow())) {
          return false;
        }
        final Component content = popup.getContent();
        if (!UIUtil.isShowing(content)) {
          popup.cancel();
          return false;
        }

        if (!StartupUiUtil.isWaylandToolkit()) {
          final Rectangle bounds = new Rectangle(content.getLocationOnScreen(), content.getSize());
          if (bounds.contains(point) || !popup.isCancelOnClickOutside()) {
            return false;
          }
        } else {
          // In Wayland "location on screen" is not available, so do close unless the event came
          // directly from the popup itself.
          if (window == popup.getPopupWindow() || !popup.isCancelOnClickOutside()) {
            return false;
          }
        }

        if (!popup.canClose()){
          return false;
        }

        //click on context menu item
        if (MenuSelectionManager.defaultManager().getSelectedPath().length > 0) {
          return false;
        }

        if (needStopFurtherEventProcessing(popup, mouseEvent)) {
          needStopFurtherEventProcessing = true;
        }
        popup.cancel(mouseEvent);
      }

      if (myStack.isEmpty() || needStopFurtherEventProcessing) {
        return needStopFurtherEventProcessing;
      }

      popup = (AbstractPopup)myStack.peek();
      if (popup == null || popup.isDisposed()) {
        myStack.pop();
      }
    }
  }
private boolean dispatchMouseEvent(AWTEvent event)