Search in sources :

Example 1 with SubmitEvent

use of com.google.gwt.user.client.ui.FormPanel.SubmitEvent in project gwt-test-utils by gwt-test-utils.

the class BrowserTest method submit.

@Test()
public void submit() {
    // Given
    final StringBuilder sb = new StringBuilder();
    FormPanel form = new FormPanel();
    form.addSubmitHandler(new SubmitHandler() {

        public void onSubmit(SubmitEvent event) {
            sb.append("onSubmit");
        }
    });
    form.addSubmitCompleteHandler(new SubmitCompleteHandler() {

        public void onSubmitComplete(SubmitCompleteEvent event) {
            sb.append(" complete : ").append(event.getResults());
        }
    });
    // Attach to the DOM
    RootPanel.get().add(form);
    // Given
    Browser.submit(form, "mock result");
    // Then
    assertThat(sb.toString()).isEqualTo("onSubmit complete : mock result");
}
Also used : SubmitHandler(com.google.gwt.user.client.ui.FormPanel.SubmitHandler) SubmitCompleteEvent(com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent) SubmitCompleteHandler(com.google.gwt.user.client.ui.FormPanel.SubmitCompleteHandler) SubmitEvent(com.google.gwt.user.client.ui.FormPanel.SubmitEvent) Test(org.junit.Test)

Example 2 with SubmitEvent

use of com.google.gwt.user.client.ui.FormPanel.SubmitEvent in project gwt-test-utils by gwt-test-utils.

the class BrowserTest method submitThrowsErrorIfNotAttached.

@Test(expected = AssertionError.class)
public void submitThrowsErrorIfNotAttached() {
    // Given
    final StringBuilder sb = new StringBuilder();
    FormPanel form = new FormPanel();
    form.addSubmitHandler(new SubmitHandler() {

        public void onSubmit(SubmitEvent event) {
            sb.append("onSubmit");
        }
    });
    form.addSubmitCompleteHandler(new SubmitCompleteHandler() {

        public void onSubmitComplete(SubmitCompleteEvent event) {
            sb.append(" complete : ").append(event.getResults());
        }
    });
    // When
    Browser.submit(form, "mock result");
}
Also used : SubmitHandler(com.google.gwt.user.client.ui.FormPanel.SubmitHandler) SubmitCompleteEvent(com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent) SubmitCompleteHandler(com.google.gwt.user.client.ui.FormPanel.SubmitCompleteHandler) SubmitEvent(com.google.gwt.user.client.ui.FormPanel.SubmitEvent) Test(org.junit.Test)

Example 3 with SubmitEvent

use of com.google.gwt.user.client.ui.FormPanel.SubmitEvent in project gerrit by GerritCodeReview.

the class ContactPanelShort method doRegisterNewEmail.

private void doRegisterNewEmail() {
    if (!canRegisterNewEmail()) {
        return;
    }
    final AutoCenterDialogBox box = new AutoCenterDialogBox(true, true);
    final VerticalPanel body = new VerticalPanel();
    final NpTextBox inEmail = new NpTextBox();
    inEmail.setVisibleLength(60);
    final Button register = new Button(Util.C.buttonSendRegisterNewEmail());
    final Button cancel = new Button(Util.C.buttonCancel());
    final FormPanel form = new FormPanel();
    form.addSubmitHandler(new FormPanel.SubmitHandler() {

        @Override
        public void onSubmit(final SubmitEvent event) {
            event.cancel();
            final String addr = inEmail.getText().trim();
            if (!addr.contains("@")) {
                new ErrorDialog(Util.C.invalidUserEmail()).center();
                return;
            }
            inEmail.setEnabled(false);
            register.setEnabled(false);
            AccountApi.registerEmail("self", addr, new GerritCallback<EmailInfo>() {

                @Override
                public void onSuccess(EmailInfo result) {
                    box.hide();
                    if (Gerrit.info().auth().isDev()) {
                        currentEmail = addr;
                        if (emailPick.getItemCount() == 0) {
                            AccountInfo me = Gerrit.getUserAccount();
                            me.email(addr);
                            onSaveSuccess(me);
                        } else {
                            save.setEnabled(true);
                        }
                        updateEmailList();
                    }
                }

                @Override
                public void onFailure(final Throwable caught) {
                    inEmail.setEnabled(true);
                    register.setEnabled(true);
                    if (caught.getMessage().startsWith(EmailException.MESSAGE)) {
                        final ErrorDialog d = new ErrorDialog(caught.getMessage().substring(EmailException.MESSAGE.length()));
                        d.setText(Util.C.errorDialogTitleRegisterNewEmail());
                        d.center();
                    } else {
                        super.onFailure(caught);
                    }
                }
            });
        }
    });
    form.setWidget(body);
    register.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(final ClickEvent event) {
            form.submit();
        }
    });
    cancel.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            box.hide();
        }
    });
    final FlowPanel buttons = new FlowPanel();
    buttons.setStyleName(Gerrit.RESOURCES.css().patchSetActions());
    buttons.add(register);
    buttons.add(cancel);
    if (!Gerrit.info().auth().isDev()) {
        body.add(new HTML(Util.C.descRegisterNewEmail()));
    }
    body.add(inEmail);
    body.add(buttons);
    box.setText(Util.C.titleRegisterNewEmail());
    box.setWidget(form);
    box.center();
    inEmail.setFocus(true);
}
Also used : ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ErrorDialog(com.google.gerrit.client.ErrorDialog) HTML(com.google.gwt.user.client.ui.HTML) NativeString(com.google.gerrit.client.rpc.NativeString) NpTextBox(com.google.gwtexpui.globalkey.client.NpTextBox) SubmitEvent(com.google.gwt.user.client.ui.FormPanel.SubmitEvent) GerritCallback(com.google.gerrit.client.rpc.GerritCallback) VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) AutoCenterDialogBox(com.google.gwtexpui.user.client.AutoCenterDialogBox) FormPanel(com.google.gwt.user.client.ui.FormPanel) Button(com.google.gwt.user.client.ui.Button) FlowPanel(com.google.gwt.user.client.ui.FlowPanel) AccountInfo(com.google.gerrit.client.info.AccountInfo)

Aggregations

SubmitEvent (com.google.gwt.user.client.ui.FormPanel.SubmitEvent)3 SubmitCompleteEvent (com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent)2 SubmitCompleteHandler (com.google.gwt.user.client.ui.FormPanel.SubmitCompleteHandler)2 SubmitHandler (com.google.gwt.user.client.ui.FormPanel.SubmitHandler)2 Test (org.junit.Test)2 ErrorDialog (com.google.gerrit.client.ErrorDialog)1 AccountInfo (com.google.gerrit.client.info.AccountInfo)1 GerritCallback (com.google.gerrit.client.rpc.GerritCallback)1 NativeString (com.google.gerrit.client.rpc.NativeString)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 Button (com.google.gwt.user.client.ui.Button)1 FlowPanel (com.google.gwt.user.client.ui.FlowPanel)1 FormPanel (com.google.gwt.user.client.ui.FormPanel)1 HTML (com.google.gwt.user.client.ui.HTML)1 VerticalPanel (com.google.gwt.user.client.ui.VerticalPanel)1 NpTextBox (com.google.gwtexpui.globalkey.client.NpTextBox)1 AutoCenterDialogBox (com.google.gwtexpui.user.client.AutoCenterDialogBox)1