ggeorg / gwt-mosaic

Automatically exported from code.google.com/p/gwt-mosaic
1 stars 0 forks source link

WindowPanel no control over close button #64

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I want to create a MODAL login dialog using WindowPanel.
When the user has been logged in before, he is allowed to choose 
cancel button or the close button of the window. Otherwise cancel (works)
and close button should be disabled.

According to the sources there is no way to control the state of the close
button. I am not able to enable/disable the close button, nor to remove the
close button at all.

I am using mosaic 0.3.0.rc1 for gwt 1.7.1

Original issue reported on code.google.com by stefanre...@gmail.com on 10 Nov 2009 at 8:21

GoogleCodeExporter commented 9 years ago
Hi,

You can remove it if you want:

windowPanel.getHeader().clear();

or you can can call showLoginForm() in a loop until login is successful.

A simple login showLoginForm() is below, the close button is like Cancel button.

Let me know if that helps.

Kind Regards,
George.

private void showLoginForm() {
    final TextBox username = new TextBox();
    final PasswordTextBox passwd = new PasswordTextBox();

    final MessageBox prompt = new MessageBox(MessageBoxType.PASSWORD,
        "Login Form") {
      @Override
      public void onClose(boolean result) {
        hide();
        if (result) {
          InfoPanel.show("Login Form", "Form submitted!");
        } else {
          InfoPanel.show("Login Form", "You clicked 'Cancel'.");
        }
      }
    };
    prompt.setAnimationEnabled(false);
    final int width = Math.max(Window.getClientWidth() / 3, 256);
    prompt.setWidth(width + "px");

    // Create a panel to hold all of the form widgets
    final LayoutPanel panel = new LayoutPanel(new BoxLayout(
        Orientation.VERTICAL));
    panel.setPadding(0);

    panel.add(new HTML("User name:"), new BoxLayoutData(FillStyle.HORIZONTAL));
    panel.add(username, new BoxLayoutData(FillStyle.HORIZONTAL));

    panel.add(new HTML("Password:"), new BoxLayoutData(FillStyle.HORIZONTAL));
    panel.add(passwd, new BoxLayoutData(FillStyle.HORIZONTAL));

    // Add a 'submit' button.
    Button buttonSubmit = new Button("Submit");
    buttonSubmit.addClickHandler(new ClickHandler() {
      public void onClick(ClickEvent event) {
        REMOTE_CLOUDFILES_SERVICE.login(username.getText(), passwd.getText(),
            new AsyncCallback<Boolean>() {
              public void onFailure(Throwable caught) {
                GWT.log(caught.getMessage(), caught);
                InfoPanel.show(InfoPanelType.HUMANIZED_MESSAGE, "Login",
                    "Authetication failed with message: "
                        + caught.getLocalizedMessage());
              }

              public void onSuccess(Boolean result) {
                if (result != null && result) {
                  startup();
                } else {
                  InfoPanel.show(InfoPanelType.HUMANIZED_MESSAGE, "Login",
                      "Authetication failed!");
                }
              }
            });
        prompt.onClose(true);
      }
    });
    prompt.getButtonPanel().add(buttonSubmit);

    // Add a 'cancel' button.
    Button buttonCancel = new Button("Cancel");
    buttonCancel.addClickHandler(new ClickHandler() {
      public void onClick(ClickEvent event) {
        prompt.onClose(false);
      }
    });
    prompt.getButtonPanel().add(buttonCancel);

    prompt.setWidget(panel);
    prompt.showModal();

    if (prompt.getOffsetWidth() < width) {
      prompt.setWidth(width + "px");
    }

    DeferredCommand.addCommand(new Command() {
      public void execute() {
        username.setFocus(true);
      }
    });
  }

Original comment by georgopo...@gmail.com on 10 Nov 2009 at 9:07