package com.vaadin.tests.tickets; import com.vaadin.Application; import com.vaadin.data.Validator; import com.vaadin.data.util.BeanItem; import com.vaadin.data.util.MethodProperty; import com.vaadin.data.validator.IntegerValidator; import com.vaadin.server.ThemeResource; import com.vaadin.ui.AbstractComponent; import com.vaadin.ui.Alignment; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.CheckBox; import com.vaadin.ui.Form; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Panel; import com.vaadin.ui.UI.LegacyWindow; public class Ticket736 extends Application.LegacyApplication { Address address = new Address(); @Override public void init() { final LegacyWindow mainWin = new LegacyWindow("Test app for #736"); setMainWindow(mainWin); setTheme("runo"); // Create form for editing address final Form f = new Form(); f.setItemDataSource(new BeanItem
(address, new String[] { "name", "street", "zip", "city", "state", "country" })); f.setCaption("Office address"); f.setIcon(new ThemeResource("../runo/icons/16/document.png")); f.setDescription("Jep jpe, this is form description."); mainWin.addComponent(f); // Select to use buffered mode for editing to enable commit and discard f.setBuffered(true); Button commit = new Button("Commit", new ClickListener() { @Override public void buttonClick(ClickEvent event) { f.commit(); } }); Button discard = new Button("Discard", new ClickListener() { @Override public void buttonClick(ClickEvent event) { f.discard(); } }); HorizontalLayout ol = new HorizontalLayout(); ol.setHeight("3em"); ol.addComponent(commit); ol.setComponentAlignment(commit, Alignment.TOP_RIGHT); ol.addComponent(discard); f.setFooter(ol); // Add some validators for the form f.getField("zip").addValidator( new IntegerValidator("'{0}' is not a number")); ((AbstractComponent) f.getField("zip")).setDescription("Jepjep"); ((AbstractComponent) f.getField("zip")).setIcon(new ThemeResource( "../runo/icons/16/folder.png")); f.getField("state").addValidator(new IsValidState()); f.getField("name").setRequired(true); f.getField("street").setRequired(true); f.getField("city").setRequired(true); f.getField("zip").setRequired(true); // Debug form properties final Panel formProperties = new Panel("Form properties"); formProperties.setWidth("200px"); final String[] visibleProps = { "required", "invalidAllowed", "readOnly", "readThrough", "writeThrough", "invalidCommitted", "validationVisible", "immediate" }; for (int i = 0; i < visibleProps.length; i++) { CheckBox b = new CheckBox(visibleProps[i], new MethodProperty