示例#1
0
  /**
   * Makes this window as a modal dialog. It will automatically center the window (ignoring {@link
   * #getLeft} and {@link #getTop}).
   *
   * <p>Notice: though both setMode("modal") and doModal() both causes the window to become modal,
   * they are a bit different. doModal causes the event listener to suspend immediately, while
   * setMode("modal") posts an event ({@link Events#ON_MODAL}). That is, {@link #setMode} won't
   * suspend the execution immediately, but {@link #doModal} will. {@link #doModal} can be called
   * only in an event listener, while {@link #setMode} can be called anytime.
   *
   * @exception SuspendNotAllowedException if 1) not in an event listener;<br>
   *     2) the event thread is disabled.<br>
   *     3) there are too many suspended processing thread than the deployer allows. By default,
   *     there is no limit of # of suspended threads.
   * @exception InterruptedException thrown if the desktop or the Web application is being
   *     destroyed, or {@link org.zkoss.zk.ui.sys.DesktopCtrl#ceaseSuspendedThread}. To tell the
   *     difference, check the getMessage method of InterruptedException.
   * @since 3.0.4
   */
  public void doModal() throws InterruptedException, SuspendNotAllowedException {
    if (!isEventThreadEnabled(true)) {
      checkOverlappable(_MODAL_);
      setNonModalMode(_MODAL_);
      return;
    }

    checkOverlappable(MODAL);

    if (_mode != MODAL) {
      if (!Events.inEventListener())
        throw new SuspendNotAllowedException("doModal must be called in an event listener");

      int oldmode = _mode;
      boolean oldvisi = isVisible();

      setVisible(true); // if MODAL, it must be visible; vice versa

      try {
        enterModal();
      } catch (SuspendNotAllowedException ex) {
        handleFailedModal(oldmode, oldvisi);
        throw ex;
      }
    }
  }