final FormField<String> field4 = new StringTextBoxFormField();
field4.setValidator(new CompositeFieldValidator(new NotEmptyFieldValidator(), new EmailFieldValidator()));
final FormField<Boolean> field5 = new CheckBoxFormField();
field5.setValidator(new UncheckedFieldValidator());
final PListBox listBox = new PListBox(true);
listBox.addItem("Item 1");
listBox.addItem("Item 2");
listBox.addItem("Item 3");
listBox.addItem("Item 4");
listBox.addItem("Item 5");
listBox.addItem("Item 6");
final FormField<String> field6 = new StringListBoxFormField(listBox);
field6.setValidator(new NotEmptyFieldValidator());
final FormField<Date> field7 = new DateBoxFormField();
field7.setValidator(new NotEmptyFieldValidator());
final FormField<Date> field8 = new DateBoxFormField();
field7.setValidator(new NotEmptyFieldValidator());
final FormField<String> field9 = new StringTextBoxFormField();
field9.setValidator(new NotEmptyFieldValidator());
final FormField<String> field10 = new StringTextBoxFormField();
field10.setValidator(new TwinFieldValidator("Field doesn't match", field9));
form.addFormField(field1);
form.addFormField(field2);
form.addFormField(field3);
form.addFormField(field4);
form.addFormField(field5);
form.addFormField(field6);
form.addFormField(field7);
form.addFormField(field8);
form.addFormField(field9);
form.addFormField(field10);
final FormFieldComponent formFieldComponent1 = new FormFieldComponent("field1", field1);
final FormFieldComponent formFieldComponent2 = new FormFieldComponent("field2", field2);
final FormFieldComponent formFieldComponent3 = new FormFieldComponent("field3", field3);
final FormFieldComponent formFieldComponent4 = new FormFieldComponent("field4", field4);
final FormFieldComponent formFieldComponent5 = new FormFieldComponent("field5", field5);
final FormFieldComponent formFieldComponent6 = new FormFieldComponent("field6", field6);
final FormFieldComponent formFieldComponent7 = new FormFieldComponent("field7", field7);
final FormFieldComponent formFieldComponent8 = new FormFieldComponent("field8", field8);
final FormFieldComponent formFieldComponent9 = new FormFieldComponent("field9", field9);
final FormFieldComponent formFieldComponent10 = new FormFieldComponent("field10", field10);
final PFlexTable formLayout = new PFlexTable();
formLayout.addStyleName("cell-top");
formLayout.setWidget(0, 0, formFieldComponent1);
formLayout.setWidget(0, 1, formFieldComponent2);
formLayout.setWidget(1, 0, formFieldComponent3);
formLayout.setWidget(1, 1, formFieldComponent4);
formLayout.setWidget(2, 0, formFieldComponent5);
formLayout.setWidget(2, 1, formFieldComponent6);
formLayout.setWidget(3, 0, formFieldComponent7);
formLayout.setWidget(3, 1, formFieldComponent8);
formLayout.setWidget(4, 0, formFieldComponent9);
formLayout.setWidget(4, 1, formFieldComponent10);
final PButton validateButton = new PButton("Validate");
validateButton.addClickHandler(new PClickHandler() {
@Override
public void onClick(final PClickEvent clickEvent) {
final boolean isValid = form.isValid();
PNotificationManager.showTrayNotification("The form is valid? " + (isValid ? "YES" : "NO"));
}
});
final PButton resetButton = new PButton("Reset");
resetButton.addClickHandler(new PClickHandler() {
@Override
public void onClick(final PClickEvent clickEvent) {
form.reset();
PNotificationManager.showHumanizedNotification("The form has been reseted");
}
});
final PListBox captionOriantationList = new PListBox(true);
for (final CaptionOrientation captionOriantation : CaptionOrientation.values()) {
captionOriantationList.addItem(captionOriantation.name(), captionOriantation);
}
captionOriantationList.addChangeHandler(new PChangeHandler() {
@Override
public void onChange(final PChangeEvent event) {
final CaptionOrientation captionOriantation = (CaptionOrientation) captionOriantationList.getSelectedValue();
formFieldComponent1.setCaptionOrientation(captionOriantation);
formFieldComponent2.setCaptionOrientation(captionOriantation);
formFieldComponent3.setCaptionOrientation(captionOriantation);
formFieldComponent4.setCaptionOrientation(captionOriantation);