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");
}
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");
}
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);
}
Aggregations