+++ /dev/null
-package com.vaadin.tests.fieldbinder;\r
-\r
-import com.vaadin.data.fieldgroup.BeanFieldGroup;\r
-import com.vaadin.data.fieldgroup.FieldGroup.CommitException;\r
-import com.vaadin.tests.components.TestBase;\r
-import com.vaadin.tests.util.Log;\r
-import com.vaadin.ui.Button;\r
-import com.vaadin.ui.Button.ClickEvent;\r
-import com.vaadin.ui.Button.ClickListener;\r
-import com.vaadin.ui.Root;\r
-\r
-public abstract class AbstractBeanFieldBinderTest extends TestBase {\r
-\r
- private Button commitButton;\r
- protected Log log = new Log(5);\r
-\r
- private Button discardButton;\r
- private Button showBeanButton;\r
- private BeanFieldGroup fieldBinder;\r
-\r
- @Override\r
- protected void setup() {\r
- addComponent(log);\r
- }\r
-\r
- protected Button getDiscardButton() {\r
- if (discardButton == null) {\r
- discardButton = new Button("Discard", new Button.ClickListener() {\r
-\r
- public void buttonClick(ClickEvent event) {\r
- getFieldBinder().discard();\r
- log.log("Discarded changes");\r
-\r
- }\r
- });\r
- }\r
- return discardButton;\r
- }\r
-\r
- protected Button getShowBeanButton() {\r
- if (showBeanButton == null) {\r
- showBeanButton = new Button("Show bean values",\r
- new Button.ClickListener() {\r
-\r
- public void buttonClick(ClickEvent event) {\r
- log.log(getFieldBinder().getItemDataSource()\r
- .getBean().toString());\r
-\r
- }\r
- });\r
- }\r
- return showBeanButton;\r
- }\r
-\r
- protected Button getCommitButton() {\r
- if (commitButton == null) {\r
- commitButton = new Button("Commit");\r
- commitButton.addListener(new ClickListener() {\r
-\r
- public void buttonClick(ClickEvent event) {\r
- String msg = "Commit succesful";\r
- try {\r
- getFieldBinder().commit();\r
- } catch (CommitException e) {\r
- msg = "Commit failed: " + e.getMessage();\r
- }\r
- Root.getCurrentRoot().showNotification(msg);\r
- log.log(msg);\r
-\r
- }\r
- });\r
- }\r
- return commitButton;\r
- }\r
-\r
- protected BeanFieldGroup getFieldBinder() {\r
- return fieldBinder;\r
- }\r
-\r
- protected void setFieldBinder(BeanFieldGroup beanFieldBinder) {\r
- fieldBinder = beanFieldBinder;\r
- }\r
-\r
- @Override\r
- protected String getDescription() {\r
- // TODO Auto-generated method stub\r
- return null;\r
- }\r
-\r
- @Override\r
- protected Integer getTicketNumber() {\r
- // TODO Auto-generated method stub\r
- return null;\r
- }\r
-\r
-}\r
+++ /dev/null
-package com.vaadin.tests.fieldbinder;\r
-\r
-import com.vaadin.data.fieldgroup.BeanFieldGroup;\r
-import com.vaadin.data.fieldgroup.FieldGroup;\r
-import com.vaadin.data.fieldgroup.FieldGroup.CommitEvent;\r
-import com.vaadin.data.fieldgroup.FieldGroup.CommitException;\r
-import com.vaadin.data.fieldgroup.FieldGroup.CommitHandler;\r
-import com.vaadin.data.util.BeanItem;\r
-import com.vaadin.data.util.converter.StringToBooleanConverter;\r
-import com.vaadin.data.validator.EmailValidator;\r
-import com.vaadin.data.validator.IntegerRangeValidator;\r
-import com.vaadin.data.validator.StringLengthValidator;\r
-import com.vaadin.tests.components.TestBase;\r
-import com.vaadin.tests.data.bean.Address;\r
-import com.vaadin.tests.data.bean.Country;\r
-import com.vaadin.tests.data.bean.Person;\r
-import com.vaadin.tests.data.bean.Sex;\r
-import com.vaadin.tests.util.Log;\r
-import com.vaadin.ui.Button;\r
-import com.vaadin.ui.Button.ClickEvent;\r
-import com.vaadin.ui.Panel;\r
-import com.vaadin.ui.Root;\r
-import com.vaadin.ui.Table;\r
-import com.vaadin.ui.TextArea;\r
-import com.vaadin.ui.TextField;\r
-\r
-public class BasicPersonForm extends TestBase {\r
-\r
- private Log log = new Log(5);\r
- private TextField firstName;\r
- private TextArea lastName;\r
- private TextField email;\r
- private TextField age;\r
- private Table sex;\r
- private TextField deceased;\r
-\r
- public class Configuration {\r
- public boolean preCommitFails = false;\r
- public boolean postCommitFails = false;\r
-\r
- public boolean isPreCommitFails() {\r
- return preCommitFails;\r
- }\r
-\r
- public void setPreCommitFails(boolean preCommitFails) {\r
- this.preCommitFails = preCommitFails;\r
- }\r
-\r
- public boolean isPostCommitFails() {\r
- return postCommitFails;\r
- }\r
-\r
- public void setPostCommitFails(boolean postCommitFails) {\r
- this.postCommitFails = postCommitFails;\r
- }\r
-\r
- }\r
-\r
- private Configuration configuration = new Configuration();\r
-\r
- private class ConfigurationPanel extends Panel {\r
-\r
- public ConfigurationPanel() {\r
- super("Configuration");\r
- BeanItem<Configuration> bi = new BeanItem<BasicPersonForm.Configuration>(\r
- configuration);\r
- FieldGroup confFieldGroup = new FieldGroup(bi);\r
- confFieldGroup.setItemDataSource(bi);\r
- confFieldGroup.setBuffered(false);\r
-\r
- for (Object propertyId : bi.getItemPropertyIds()) {\r
- addComponent(confFieldGroup.buildAndBind(propertyId));\r
- }\r
-\r
- }\r
- }\r
-\r
- @Override\r
- protected void setup() {\r
- addComponent(log);\r
- Panel confPanel = new ConfigurationPanel();\r
- addComponent(confPanel);\r
-\r
- final FieldGroup fieldGroup = new BeanFieldGroup<Person>(Person.class);\r
- fieldGroup.addCommitHandler(new CommitHandler() {\r
-\r
- public void preCommit(CommitEvent commitEvent)\r
- throws CommitException {\r
- if (configuration.preCommitFails) {\r
- throw new CommitException(\r
- "Error in preCommit because first name is "\r
- + getPerson(commitEvent.getFieldBinder())\r
- .getFirstName());\r
- }\r
-\r
- }\r
-\r
- public void postCommit(CommitEvent commitEvent)\r
- throws CommitException {\r
- if (configuration.postCommitFails) {\r
- throw new CommitException(\r
- "Error in postCommit because first name is "\r
- + getPerson(commitEvent.getFieldBinder())\r
- .getFirstName());\r
- }\r
- }\r
- });\r
-\r
- fieldGroup.setBuffered(true);\r
-\r
- fieldGroup.buildAndBindMemberFields(this);\r
- addComponent(firstName);\r
- addComponent(lastName);\r
- addComponent(email);\r
- addComponent(age);\r
- addComponent(sex);\r
- addComponent(deceased);\r
-\r
- Button commitButton = new Button("Commit", new Button.ClickListener() {\r
-\r
- public void buttonClick(ClickEvent event) {\r
- String msg = "Commit succesful";\r
- try {\r
- fieldGroup.commit();\r
- } catch (CommitException e) {\r
- msg = "Commit failed: " + e.getMessage();\r
- }\r
- Root.getCurrentRoot().showNotification(msg);\r
- log.log(msg);\r
-\r
- }\r
- });\r
- Button discardButton = new Button("Discard",\r
- new Button.ClickListener() {\r
-\r
- public void buttonClick(ClickEvent event) {\r
- fieldGroup.discard();\r
- log.log("Discarded changes");\r
-\r
- }\r
- });\r
- Button showBean = new Button("Show bean values",\r
- new Button.ClickListener() {\r
-\r
- public void buttonClick(ClickEvent event) {\r
- log.log(getPerson(fieldGroup).toString());\r
-\r
- }\r
- });\r
- addComponent(commitButton);\r
- addComponent(discardButton);\r
- addComponent(showBean);\r
- email.addValidator(new EmailValidator("Must be a valid address"));\r
- lastName.addValidator(new StringLengthValidator("Must be min 5 chars",\r
- 5, null, true));\r
-\r
- age.addValidator(new IntegerRangeValidator(\r
- "Must be between 0 and 150, {0} is not", 0, 150));\r
- sex.setPageLength(0);\r
- deceased.setConverter(new StringToBooleanConverter() {\r
- @Override\r
- protected String getTrueString() {\r
- return "YAY!";\r
- }\r
-\r
- @Override\r
- protected String getFalseString() {\r
- return "NAAAAAH";\r
- }\r
- });\r
- Person p = new Person("John", "Doe", "john@doe.com", 64, Sex.MALE,\r
- new Address("John street", 11223, "John's town", Country.USA));\r
- fieldGroup.setItemDataSource(new BeanItem<Person>(p));\r
- }\r
-\r
- public static Person getPerson(FieldGroup binder) {\r
- return ((BeanItem<Person>) binder.getItemDataSource()).getBean();\r
- }\r
-\r
- @Override\r
- protected String getDescription() {\r
- // TODO Auto-generated method stub\r
- return null;\r
- }\r
-\r
- @Override\r
- protected Integer getTicketNumber() {\r
- // TODO Auto-generated method stub\r
- return null;\r
- }\r
-\r
-}\r
+++ /dev/null
-package com.vaadin.tests.fieldbinder;\r
-\r
-import com.vaadin.data.fieldgroup.BeanFieldGroup;\r
-import com.vaadin.data.fieldgroup.FieldGroup;\r
-import com.vaadin.data.fieldgroup.FieldGroup.CommitException;\r
-import com.vaadin.data.util.BeanItem;\r
-import com.vaadin.tests.components.TestBase;\r
-import com.vaadin.tests.data.bean.Address;\r
-import com.vaadin.tests.data.bean.Country;\r
-import com.vaadin.tests.data.bean.Person;\r
-import com.vaadin.tests.data.bean.PersonWithBeanValidationAnnotations;\r
-import com.vaadin.tests.data.bean.Sex;\r
-import com.vaadin.tests.util.Log;\r
-import com.vaadin.ui.Button;\r
-import com.vaadin.ui.Button.ClickEvent;\r
-import com.vaadin.ui.Root;\r
-import com.vaadin.ui.Table;\r
-import com.vaadin.ui.TextArea;\r
-import com.vaadin.ui.TextField;\r
-\r
-public class FieldBinderWithBeanValidation extends TestBase {\r
-\r
- private Log log = new Log(5);\r
- private TextField firstName;\r
- private TextArea lastName;\r
- private TextField email;\r
- private TextField age;\r
- private Table sex;\r
- private TextField deceased;\r
-\r
- @Override\r
- protected void setup() {\r
- addComponent(log);\r
-\r
- final BeanFieldGroup<PersonWithBeanValidationAnnotations> fieldGroup = new BeanFieldGroup<PersonWithBeanValidationAnnotations>(\r
- PersonWithBeanValidationAnnotations.class);\r
-\r
- fieldGroup.buildAndBindMemberFields(this);\r
- addComponent(firstName);\r
- addComponent(lastName);\r
- addComponent(email);\r
- addComponent(age);\r
- addComponent(sex);\r
- addComponent(deceased);\r
-\r
- Button commitButton = new Button("Commit", new Button.ClickListener() {\r
-\r
- public void buttonClick(ClickEvent event) {\r
- String msg = "Commit succesful";\r
- try {\r
- fieldGroup.commit();\r
- } catch (CommitException e) {\r
- msg = "Commit failed: " + e.getMessage();\r
- }\r
- Root.getCurrentRoot().showNotification(msg);\r
- log.log(msg);\r
-\r
- }\r
- });\r
- Button discardButton = new Button("Discard",\r
- new Button.ClickListener() {\r
-\r
- public void buttonClick(ClickEvent event) {\r
- fieldGroup.discard();\r
- log.log("Discarded changes");\r
-\r
- }\r
- });\r
- Button showBean = new Button("Show bean values",\r
- new Button.ClickListener() {\r
-\r
- public void buttonClick(ClickEvent event) {\r
- log.log(getPerson(fieldGroup).toString());\r
-\r
- }\r
- });\r
- addComponent(commitButton);\r
- addComponent(discardButton);\r
- addComponent(showBean);\r
- sex.setPageLength(0);\r
-\r
- PersonWithBeanValidationAnnotations p = new PersonWithBeanValidationAnnotations(\r
- "John", "Doe", "john@doe.com", 64, Sex.MALE, new Address(\r
- "John street", 11223, "John's town", Country.USA));\r
- fieldGroup\r
- .setItemDataSource(new BeanItem<PersonWithBeanValidationAnnotations>(\r
- p));\r
- }\r
-\r
- public static Person getPerson(FieldGroup binder) {\r
- return ((BeanItem<Person>) binder.getItemDataSource()).getBean();\r
- }\r
-\r
- @Override\r
- protected String getDescription() {\r
- // TODO Auto-generated method stub\r
- return null;\r
- }\r
-\r
- @Override\r
- protected Integer getTicketNumber() {\r
- // TODO Auto-generated method stub\r
- return null;\r
- }\r
-\r
-}\r
+++ /dev/null
-package com.vaadin.tests.fieldbinder;\r
-\r
-import com.vaadin.data.fieldgroup.BeanFieldGroup;\r
-import com.vaadin.data.fieldgroup.FieldGroup;\r
-import com.vaadin.data.fieldgroup.PropertyId;\r
-import com.vaadin.data.util.BeanItem;\r
-import com.vaadin.tests.components.TestBase;\r
-import com.vaadin.tests.data.bean.Address;\r
-import com.vaadin.tests.data.bean.Country;\r
-import com.vaadin.tests.data.bean.Person;\r
-import com.vaadin.tests.data.bean.Sex;\r
-import com.vaadin.ui.TextField;\r
-\r
-public class FormBuilderWithNestedProperties extends TestBase {\r
-\r
- private TextField firstName;\r
- private TextField lastName;\r
- @PropertyId("address.streetAddress")\r
- private TextField streetAddress;\r
-\r
- @Override\r
- protected void setup() {\r
- FieldGroup fieldGroup = new BeanFieldGroup<Person>(Person.class);\r
- fieldGroup.buildAndBindMemberFields(this);\r
-\r
- addComponent(firstName);\r
- addComponent(lastName);\r
- addComponent(streetAddress);\r
-\r
- fieldGroup.setItemDataSource(new BeanItem<Person>(new Person("Who",\r
- "me?", "email", 1, Sex.MALE, new Address("street name", 202020,\r
- "City", Country.FINLAND))));\r
- }\r
-\r
- @Override\r
- protected String getDescription() {\r
- // TODO Auto-generated method stub\r
- return null;\r
- }\r
-\r
- @Override\r
- protected Integer getTicketNumber() {\r
- // TODO Auto-generated method stub\r
- return null;\r
- }\r
-\r
-}\r
+++ /dev/null
-package com.vaadin.tests.fieldbinder;
-
-import com.vaadin.tests.components.TestBase;
-
-public class FormManyToMany extends TestBase {
-
- @Override
- protected void setup() {
- // TODO implement
-
- // TODO note that in one direction, a setter is used and automatically
- // updates the other direction (setting the Roles of a User updates
- // Roles), whereas in the other direction (updating the list of Users
- // for a Role), manual updates are needed at commit time to keep the
- // Users consistent with Roles
- }
-
- @Override
- protected String getDescription() {
- return "Forms which allow editing of a many-to-many mapping between users and roles";
- }
-
- @Override
- protected Integer getTicketNumber() {
- return null;
- }
-
-}
+++ /dev/null
-package com.vaadin.tests.fieldbinder;
-
-import com.vaadin.data.util.BeanItem;
-import com.vaadin.tests.components.TestBase;
-import com.vaadin.tests.util.Millionaire;
-import com.vaadin.ui.Form;
-
-public class FormOneToMany extends TestBase {
-
- @Override
- protected void setup() {
- final Form form = new Form();
- addComponent(form);
- form.setItemDataSource(createMillionaireItem());
-
- // TODO support adding, editing and removing secondary addresses
- }
-
- protected BeanItem<Millionaire> createMillionaireItem() {
- Millionaire person = new Millionaire("First", "Last", "foo@vaadin.com",
- "02-111 2222", "Ruukinkatu 2-4", 20540, "Turku");
-
- BeanItem<Millionaire> item = new BeanItem<Millionaire>(person);
- // add nested properties from address
- item.expandProperty("address");
-
- // TODO for now, hide secondary residences
- item.removeItemProperty("secondaryResidences");
-
- return item;
- }
-
- @Override
- protected String getDescription() {
- return "Form with an editable list of sub-objects.";
- }
-
- @Override
- protected Integer getTicketNumber() {
- return null;
- }
-
-}
+++ /dev/null
-package com.vaadin.tests.fieldbinder;
-
-import com.vaadin.data.util.BeanItem;
-import com.vaadin.tests.components.TestBase;
-import com.vaadin.tests.util.Person;
-import com.vaadin.ui.Form;
-
-public class FormOneToOne extends TestBase {
-
- @Override
- protected void setup() {
- final Form form = new Form();
- addComponent(form);
- form.setItemDataSource(createPersonItem());
- }
-
- protected BeanItem<Person> createPersonItem() {
- Person person = new Person("First", "Last", "foo@vaadin.com",
- "02-111 2222", "Ruukinkatu 2-4", 20540, "Turku");
-
- BeanItem<Person> item = new BeanItem<Person>(person);
- // add nested properties from address
- item.expandProperty("address");
-
- return item;
- }
-
- @Override
- protected String getDescription() {
- return "Form where some properties come from a sub-object of the bean.";
- }
-
- @Override
- protected Integer getTicketNumber() {
- return null;
- }
-
-}
+++ /dev/null
-package com.vaadin.tests.fieldbinder;\r
-\r
-import com.vaadin.data.fieldgroup.BeanFieldGroup;\r
-import com.vaadin.data.fieldgroup.PropertyId;\r
-import com.vaadin.tests.data.bean.Address;\r
-import com.vaadin.tests.data.bean.Country;\r
-import com.vaadin.tests.data.bean.Person;\r
-import com.vaadin.tests.data.bean.Sex;\r
-import com.vaadin.tests.util.Log;\r
-import com.vaadin.ui.CheckBox;\r
-import com.vaadin.ui.NativeSelect;\r
-import com.vaadin.ui.TextField;\r
-\r
-public class FormWithNestedProperties extends AbstractBeanFieldBinderTest {\r
-\r
- private Log log = new Log(5);\r
-\r
- private TextField firstName = new TextField("First name");\r
- private TextField lastName = new TextField("Last name");\r
- private TextField email = new TextField("Email");\r
- private TextField age = new TextField("Age");\r
-\r
- @PropertyId("address.streetAddress")\r
- private TextField streetAddress = new TextField("Street address");\r
- private NativeSelect country;\r
-\r
- private CheckBox deceased = new CheckBox("Deceased");\r
-\r
- @Override\r
- protected void setup() {\r
- super.setup();\r
-\r
- setFieldBinder(new BeanFieldGroup<Person>(Person.class));\r
- country = getFieldBinder().buildAndBind("country", "address.country",\r
- NativeSelect.class);\r
- getFieldBinder().bindMemberFields(this);\r
- addComponent(firstName);\r
- addComponent(lastName);\r
- addComponent(streetAddress);\r
- addComponent(country);\r
- addComponent(email);\r
- addComponent(age);\r
- addComponent(deceased);\r
- addComponent(getCommitButton());\r
- addComponent(getDiscardButton());\r
- addComponent(getShowBeanButton());\r
-\r
- getFieldBinder().setItemDataSource(\r
- new Person("First", "Last", "Email", 52, Sex.FEMALE,\r
- new Address("street address", 01234, "City",\r
- Country.FINLAND)));\r
-\r
- }\r
-\r
- @Override\r
- protected String getDescription() {\r
- // TODO Auto-generated method stub\r
- return null;\r
- }\r
-\r
- @Override\r
- protected Integer getTicketNumber() {\r
- // TODO Auto-generated method stub\r
- return null;\r
- }\r
-\r
-}\r
--- /dev/null
+package com.vaadin.tests.fieldgroup;\r
+\r
+import com.vaadin.data.fieldgroup.BeanFieldGroup;\r
+import com.vaadin.data.fieldgroup.FieldGroup.CommitException;\r
+import com.vaadin.tests.components.TestBase;\r
+import com.vaadin.tests.util.Log;\r
+import com.vaadin.ui.Button;\r
+import com.vaadin.ui.Button.ClickEvent;\r
+import com.vaadin.ui.Button.ClickListener;\r
+import com.vaadin.ui.Root;\r
+\r
+public abstract class AbstractBeanFieldBinderTest extends TestBase {\r
+\r
+ private Button commitButton;\r
+ protected Log log = new Log(5);\r
+\r
+ private Button discardButton;\r
+ private Button showBeanButton;\r
+ private BeanFieldGroup fieldBinder;\r
+\r
+ @Override\r
+ protected void setup() {\r
+ addComponent(log);\r
+ }\r
+\r
+ protected Button getDiscardButton() {\r
+ if (discardButton == null) {\r
+ discardButton = new Button("Discard", new Button.ClickListener() {\r
+\r
+ public void buttonClick(ClickEvent event) {\r
+ getFieldBinder().discard();\r
+ log.log("Discarded changes");\r
+\r
+ }\r
+ });\r
+ }\r
+ return discardButton;\r
+ }\r
+\r
+ protected Button getShowBeanButton() {\r
+ if (showBeanButton == null) {\r
+ showBeanButton = new Button("Show bean values",\r
+ new Button.ClickListener() {\r
+\r
+ public void buttonClick(ClickEvent event) {\r
+ log.log(getFieldBinder().getItemDataSource()\r
+ .getBean().toString());\r
+\r
+ }\r
+ });\r
+ }\r
+ return showBeanButton;\r
+ }\r
+\r
+ protected Button getCommitButton() {\r
+ if (commitButton == null) {\r
+ commitButton = new Button("Commit");\r
+ commitButton.addListener(new ClickListener() {\r
+\r
+ public void buttonClick(ClickEvent event) {\r
+ String msg = "Commit succesful";\r
+ try {\r
+ getFieldBinder().commit();\r
+ } catch (CommitException e) {\r
+ msg = "Commit failed: " + e.getMessage();\r
+ }\r
+ Root.getCurrentRoot().showNotification(msg);\r
+ log.log(msg);\r
+\r
+ }\r
+ });\r
+ }\r
+ return commitButton;\r
+ }\r
+\r
+ protected BeanFieldGroup getFieldBinder() {\r
+ return fieldBinder;\r
+ }\r
+\r
+ protected void setFieldBinder(BeanFieldGroup beanFieldBinder) {\r
+ fieldBinder = beanFieldBinder;\r
+ }\r
+\r
+ @Override\r
+ protected String getDescription() {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ protected Integer getTicketNumber() {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+}\r
--- /dev/null
+package com.vaadin.tests.fieldgroup;\r
+\r
+import com.vaadin.data.fieldgroup.BeanFieldGroup;\r
+import com.vaadin.data.fieldgroup.FieldGroup;\r
+import com.vaadin.data.fieldgroup.FieldGroup.CommitEvent;\r
+import com.vaadin.data.fieldgroup.FieldGroup.CommitException;\r
+import com.vaadin.data.fieldgroup.FieldGroup.CommitHandler;\r
+import com.vaadin.data.util.BeanItem;\r
+import com.vaadin.data.util.converter.StringToBooleanConverter;\r
+import com.vaadin.data.validator.EmailValidator;\r
+import com.vaadin.data.validator.IntegerRangeValidator;\r
+import com.vaadin.data.validator.StringLengthValidator;\r
+import com.vaadin.tests.components.TestBase;\r
+import com.vaadin.tests.data.bean.Address;\r
+import com.vaadin.tests.data.bean.Country;\r
+import com.vaadin.tests.data.bean.Person;\r
+import com.vaadin.tests.data.bean.Sex;\r
+import com.vaadin.tests.util.Log;\r
+import com.vaadin.ui.Button;\r
+import com.vaadin.ui.Button.ClickEvent;\r
+import com.vaadin.ui.Panel;\r
+import com.vaadin.ui.Root;\r
+import com.vaadin.ui.Table;\r
+import com.vaadin.ui.TextArea;\r
+import com.vaadin.ui.TextField;\r
+\r
+public class BasicPersonForm extends TestBase {\r
+\r
+ private Log log = new Log(5);\r
+ private TextField firstName;\r
+ private TextArea lastName;\r
+ private TextField email;\r
+ private TextField age;\r
+ private Table sex;\r
+ private TextField deceased;\r
+\r
+ public class Configuration {\r
+ public boolean preCommitFails = false;\r
+ public boolean postCommitFails = false;\r
+\r
+ public boolean isPreCommitFails() {\r
+ return preCommitFails;\r
+ }\r
+\r
+ public void setPreCommitFails(boolean preCommitFails) {\r
+ this.preCommitFails = preCommitFails;\r
+ }\r
+\r
+ public boolean isPostCommitFails() {\r
+ return postCommitFails;\r
+ }\r
+\r
+ public void setPostCommitFails(boolean postCommitFails) {\r
+ this.postCommitFails = postCommitFails;\r
+ }\r
+\r
+ }\r
+\r
+ private Configuration configuration = new Configuration();\r
+\r
+ private class ConfigurationPanel extends Panel {\r
+\r
+ public ConfigurationPanel() {\r
+ super("Configuration");\r
+ BeanItem<Configuration> bi = new BeanItem<BasicPersonForm.Configuration>(\r
+ configuration);\r
+ FieldGroup confFieldGroup = new FieldGroup(bi);\r
+ confFieldGroup.setItemDataSource(bi);\r
+ confFieldGroup.setBuffered(false);\r
+\r
+ for (Object propertyId : bi.getItemPropertyIds()) {\r
+ addComponent(confFieldGroup.buildAndBind(propertyId));\r
+ }\r
+\r
+ }\r
+ }\r
+\r
+ @Override\r
+ protected void setup() {\r
+ addComponent(log);\r
+ Panel confPanel = new ConfigurationPanel();\r
+ addComponent(confPanel);\r
+\r
+ final FieldGroup fieldGroup = new BeanFieldGroup<Person>(Person.class);\r
+ fieldGroup.addCommitHandler(new CommitHandler() {\r
+\r
+ public void preCommit(CommitEvent commitEvent)\r
+ throws CommitException {\r
+ if (configuration.preCommitFails) {\r
+ throw new CommitException(\r
+ "Error in preCommit because first name is "\r
+ + getPerson(commitEvent.getFieldBinder())\r
+ .getFirstName());\r
+ }\r
+\r
+ }\r
+\r
+ public void postCommit(CommitEvent commitEvent)\r
+ throws CommitException {\r
+ if (configuration.postCommitFails) {\r
+ throw new CommitException(\r
+ "Error in postCommit because first name is "\r
+ + getPerson(commitEvent.getFieldBinder())\r
+ .getFirstName());\r
+ }\r
+ }\r
+ });\r
+\r
+ fieldGroup.setBuffered(true);\r
+\r
+ fieldGroup.buildAndBindMemberFields(this);\r
+ addComponent(firstName);\r
+ addComponent(lastName);\r
+ addComponent(email);\r
+ addComponent(age);\r
+ addComponent(sex);\r
+ addComponent(deceased);\r
+\r
+ Button commitButton = new Button("Commit", new Button.ClickListener() {\r
+\r
+ public void buttonClick(ClickEvent event) {\r
+ String msg = "Commit succesful";\r
+ try {\r
+ fieldGroup.commit();\r
+ } catch (CommitException e) {\r
+ msg = "Commit failed: " + e.getMessage();\r
+ }\r
+ Root.getCurrentRoot().showNotification(msg);\r
+ log.log(msg);\r
+\r
+ }\r
+ });\r
+ Button discardButton = new Button("Discard",\r
+ new Button.ClickListener() {\r
+\r
+ public void buttonClick(ClickEvent event) {\r
+ fieldGroup.discard();\r
+ log.log("Discarded changes");\r
+\r
+ }\r
+ });\r
+ Button showBean = new Button("Show bean values",\r
+ new Button.ClickListener() {\r
+\r
+ public void buttonClick(ClickEvent event) {\r
+ log.log(getPerson(fieldGroup).toString());\r
+\r
+ }\r
+ });\r
+ addComponent(commitButton);\r
+ addComponent(discardButton);\r
+ addComponent(showBean);\r
+ email.addValidator(new EmailValidator("Must be a valid address"));\r
+ lastName.addValidator(new StringLengthValidator("Must be min 5 chars",\r
+ 5, null, true));\r
+\r
+ age.addValidator(new IntegerRangeValidator(\r
+ "Must be between 0 and 150, {0} is not", 0, 150));\r
+ sex.setPageLength(0);\r
+ deceased.setConverter(new StringToBooleanConverter() {\r
+ @Override\r
+ protected String getTrueString() {\r
+ return "YAY!";\r
+ }\r
+\r
+ @Override\r
+ protected String getFalseString() {\r
+ return "NAAAAAH";\r
+ }\r
+ });\r
+ Person p = new Person("John", "Doe", "john@doe.com", 64, Sex.MALE,\r
+ new Address("John street", 11223, "John's town", Country.USA));\r
+ fieldGroup.setItemDataSource(new BeanItem<Person>(p));\r
+ }\r
+\r
+ public static Person getPerson(FieldGroup binder) {\r
+ return ((BeanItem<Person>) binder.getItemDataSource()).getBean();\r
+ }\r
+\r
+ @Override\r
+ protected String getDescription() {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ protected Integer getTicketNumber() {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+}\r
--- /dev/null
+package com.vaadin.tests.fieldgroup;\r
+\r
+import com.vaadin.data.fieldgroup.BeanFieldGroup;\r
+import com.vaadin.data.fieldgroup.FieldGroup;\r
+import com.vaadin.data.fieldgroup.FieldGroup.CommitException;\r
+import com.vaadin.data.util.BeanItem;\r
+import com.vaadin.tests.components.TestBase;\r
+import com.vaadin.tests.data.bean.Address;\r
+import com.vaadin.tests.data.bean.Country;\r
+import com.vaadin.tests.data.bean.Person;\r
+import com.vaadin.tests.data.bean.PersonWithBeanValidationAnnotations;\r
+import com.vaadin.tests.data.bean.Sex;\r
+import com.vaadin.tests.util.Log;\r
+import com.vaadin.ui.Button;\r
+import com.vaadin.ui.Button.ClickEvent;\r
+import com.vaadin.ui.Root;\r
+import com.vaadin.ui.Table;\r
+import com.vaadin.ui.TextArea;\r
+import com.vaadin.ui.TextField;\r
+\r
+public class FieldBinderWithBeanValidation extends TestBase {\r
+\r
+ private Log log = new Log(5);\r
+ private TextField firstName;\r
+ private TextArea lastName;\r
+ private TextField email;\r
+ private TextField age;\r
+ private Table sex;\r
+ private TextField deceased;\r
+\r
+ @Override\r
+ protected void setup() {\r
+ addComponent(log);\r
+\r
+ final BeanFieldGroup<PersonWithBeanValidationAnnotations> fieldGroup = new BeanFieldGroup<PersonWithBeanValidationAnnotations>(\r
+ PersonWithBeanValidationAnnotations.class);\r
+\r
+ fieldGroup.buildAndBindMemberFields(this);\r
+ addComponent(firstName);\r
+ addComponent(lastName);\r
+ addComponent(email);\r
+ addComponent(age);\r
+ addComponent(sex);\r
+ addComponent(deceased);\r
+\r
+ Button commitButton = new Button("Commit", new Button.ClickListener() {\r
+\r
+ public void buttonClick(ClickEvent event) {\r
+ String msg = "Commit succesful";\r
+ try {\r
+ fieldGroup.commit();\r
+ } catch (CommitException e) {\r
+ msg = "Commit failed: " + e.getMessage();\r
+ }\r
+ Root.getCurrentRoot().showNotification(msg);\r
+ log.log(msg);\r
+\r
+ }\r
+ });\r
+ Button discardButton = new Button("Discard",\r
+ new Button.ClickListener() {\r
+\r
+ public void buttonClick(ClickEvent event) {\r
+ fieldGroup.discard();\r
+ log.log("Discarded changes");\r
+\r
+ }\r
+ });\r
+ Button showBean = new Button("Show bean values",\r
+ new Button.ClickListener() {\r
+\r
+ public void buttonClick(ClickEvent event) {\r
+ log.log(getPerson(fieldGroup).toString());\r
+\r
+ }\r
+ });\r
+ addComponent(commitButton);\r
+ addComponent(discardButton);\r
+ addComponent(showBean);\r
+ sex.setPageLength(0);\r
+\r
+ PersonWithBeanValidationAnnotations p = new PersonWithBeanValidationAnnotations(\r
+ "John", "Doe", "john@doe.com", 64, Sex.MALE, new Address(\r
+ "John street", 11223, "John's town", Country.USA));\r
+ fieldGroup\r
+ .setItemDataSource(new BeanItem<PersonWithBeanValidationAnnotations>(\r
+ p));\r
+ }\r
+\r
+ public static Person getPerson(FieldGroup binder) {\r
+ return ((BeanItem<Person>) binder.getItemDataSource()).getBean();\r
+ }\r
+\r
+ @Override\r
+ protected String getDescription() {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ protected Integer getTicketNumber() {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+}\r
--- /dev/null
+package com.vaadin.tests.fieldgroup;\r
+\r
+import com.vaadin.data.fieldgroup.BeanFieldGroup;\r
+import com.vaadin.data.fieldgroup.FieldGroup;\r
+import com.vaadin.data.fieldgroup.PropertyId;\r
+import com.vaadin.data.util.BeanItem;\r
+import com.vaadin.tests.components.TestBase;\r
+import com.vaadin.tests.data.bean.Address;\r
+import com.vaadin.tests.data.bean.Country;\r
+import com.vaadin.tests.data.bean.Person;\r
+import com.vaadin.tests.data.bean.Sex;\r
+import com.vaadin.ui.TextField;\r
+\r
+public class FormBuilderWithNestedProperties extends TestBase {\r
+\r
+ private TextField firstName;\r
+ private TextField lastName;\r
+ @PropertyId("address.streetAddress")\r
+ private TextField streetAddress;\r
+\r
+ @Override\r
+ protected void setup() {\r
+ FieldGroup fieldGroup = new BeanFieldGroup<Person>(Person.class);\r
+ fieldGroup.buildAndBindMemberFields(this);\r
+\r
+ addComponent(firstName);\r
+ addComponent(lastName);\r
+ addComponent(streetAddress);\r
+\r
+ fieldGroup.setItemDataSource(new BeanItem<Person>(new Person("Who",\r
+ "me?", "email", 1, Sex.MALE, new Address("street name", 202020,\r
+ "City", Country.FINLAND))));\r
+ }\r
+\r
+ @Override\r
+ protected String getDescription() {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ protected Integer getTicketNumber() {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+}\r
--- /dev/null
+package com.vaadin.tests.fieldgroup;
+
+import com.vaadin.tests.components.TestBase;
+
+public class FormManyToMany extends TestBase {
+
+ @Override
+ protected void setup() {
+ // TODO implement
+
+ // TODO note that in one direction, a setter is used and automatically
+ // updates the other direction (setting the Roles of a User updates
+ // Roles), whereas in the other direction (updating the list of Users
+ // for a Role), manual updates are needed at commit time to keep the
+ // Users consistent with Roles
+ }
+
+ @Override
+ protected String getDescription() {
+ return "Forms which allow editing of a many-to-many mapping between users and roles";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return null;
+ }
+
+}
--- /dev/null
+package com.vaadin.tests.fieldgroup;
+
+import com.vaadin.data.util.BeanItem;
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.tests.util.Millionaire;
+import com.vaadin.ui.Form;
+
+public class FormOneToMany extends TestBase {
+
+ @Override
+ protected void setup() {
+ final Form form = new Form();
+ addComponent(form);
+ form.setItemDataSource(createMillionaireItem());
+
+ // TODO support adding, editing and removing secondary addresses
+ }
+
+ protected BeanItem<Millionaire> createMillionaireItem() {
+ Millionaire person = new Millionaire("First", "Last", "foo@vaadin.com",
+ "02-111 2222", "Ruukinkatu 2-4", 20540, "Turku");
+
+ BeanItem<Millionaire> item = new BeanItem<Millionaire>(person);
+ // add nested properties from address
+ item.expandProperty("address");
+
+ // TODO for now, hide secondary residences
+ item.removeItemProperty("secondaryResidences");
+
+ return item;
+ }
+
+ @Override
+ protected String getDescription() {
+ return "Form with an editable list of sub-objects.";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return null;
+ }
+
+}
--- /dev/null
+package com.vaadin.tests.fieldgroup;
+
+import com.vaadin.data.util.BeanItem;
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.tests.util.Person;
+import com.vaadin.ui.Form;
+
+public class FormOneToOne extends TestBase {
+
+ @Override
+ protected void setup() {
+ final Form form = new Form();
+ addComponent(form);
+ form.setItemDataSource(createPersonItem());
+ }
+
+ protected BeanItem<Person> createPersonItem() {
+ Person person = new Person("First", "Last", "foo@vaadin.com",
+ "02-111 2222", "Ruukinkatu 2-4", 20540, "Turku");
+
+ BeanItem<Person> item = new BeanItem<Person>(person);
+ // add nested properties from address
+ item.expandProperty("address");
+
+ return item;
+ }
+
+ @Override
+ protected String getDescription() {
+ return "Form where some properties come from a sub-object of the bean.";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return null;
+ }
+
+}
--- /dev/null
+package com.vaadin.tests.fieldgroup;\r
+\r
+import com.vaadin.data.fieldgroup.BeanFieldGroup;\r
+import com.vaadin.data.fieldgroup.PropertyId;\r
+import com.vaadin.tests.data.bean.Address;\r
+import com.vaadin.tests.data.bean.Country;\r
+import com.vaadin.tests.data.bean.Person;\r
+import com.vaadin.tests.data.bean.Sex;\r
+import com.vaadin.tests.util.Log;\r
+import com.vaadin.ui.CheckBox;\r
+import com.vaadin.ui.NativeSelect;\r
+import com.vaadin.ui.TextField;\r
+\r
+public class FormWithNestedProperties extends AbstractBeanFieldBinderTest {\r
+\r
+ private Log log = new Log(5);\r
+\r
+ private TextField firstName = new TextField("First name");\r
+ private TextField lastName = new TextField("Last name");\r
+ private TextField email = new TextField("Email");\r
+ private TextField age = new TextField("Age");\r
+\r
+ @PropertyId("address.streetAddress")\r
+ private TextField streetAddress = new TextField("Street address");\r
+ private NativeSelect country;\r
+\r
+ private CheckBox deceased = new CheckBox("Deceased");\r
+\r
+ @Override\r
+ protected void setup() {\r
+ super.setup();\r
+\r
+ setFieldBinder(new BeanFieldGroup<Person>(Person.class));\r
+ country = getFieldBinder().buildAndBind("country", "address.country",\r
+ NativeSelect.class);\r
+ getFieldBinder().bindMemberFields(this);\r
+ addComponent(firstName);\r
+ addComponent(lastName);\r
+ addComponent(streetAddress);\r
+ addComponent(country);\r
+ addComponent(email);\r
+ addComponent(age);\r
+ addComponent(deceased);\r
+ addComponent(getCommitButton());\r
+ addComponent(getDiscardButton());\r
+ addComponent(getShowBeanButton());\r
+\r
+ getFieldBinder().setItemDataSource(\r
+ new Person("First", "Last", "Email", 52, Sex.FEMALE,\r
+ new Address("street address", 01234, "City",\r
+ Country.FINLAND)));\r
+\r
+ }\r
+\r
+ @Override\r
+ protected String getDescription() {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ protected Integer getTicketNumber() {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+}\r