From: Artur Signell Date: Thu, 22 Dec 2011 18:54:36 +0000 (+0200) Subject: com.vaadin.tests.fieldbinder -> com.vaadin.tests.fieldgroup X-Git-Tag: 7.0.0.alpha1^2~10 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=68333b6c048c9bed3044275a694458a56294ec28;p=vaadin-framework.git com.vaadin.tests.fieldbinder -> com.vaadin.tests.fieldgroup --- diff --git a/tests/testbench/com/vaadin/tests/fieldbinder/AbstractBeanFieldBinderTest.java b/tests/testbench/com/vaadin/tests/fieldbinder/AbstractBeanFieldBinderTest.java deleted file mode 100644 index e2ed2ad696..0000000000 --- a/tests/testbench/com/vaadin/tests/fieldbinder/AbstractBeanFieldBinderTest.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.vaadin.tests.fieldbinder; - -import com.vaadin.data.fieldgroup.BeanFieldGroup; -import com.vaadin.data.fieldgroup.FieldGroup.CommitException; -import com.vaadin.tests.components.TestBase; -import com.vaadin.tests.util.Log; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Button.ClickListener; -import com.vaadin.ui.Root; - -public abstract class AbstractBeanFieldBinderTest extends TestBase { - - private Button commitButton; - protected Log log = new Log(5); - - private Button discardButton; - private Button showBeanButton; - private BeanFieldGroup fieldBinder; - - @Override - protected void setup() { - addComponent(log); - } - - protected Button getDiscardButton() { - if (discardButton == null) { - discardButton = new Button("Discard", new Button.ClickListener() { - - public void buttonClick(ClickEvent event) { - getFieldBinder().discard(); - log.log("Discarded changes"); - - } - }); - } - return discardButton; - } - - protected Button getShowBeanButton() { - if (showBeanButton == null) { - showBeanButton = new Button("Show bean values", - new Button.ClickListener() { - - public void buttonClick(ClickEvent event) { - log.log(getFieldBinder().getItemDataSource() - .getBean().toString()); - - } - }); - } - return showBeanButton; - } - - protected Button getCommitButton() { - if (commitButton == null) { - commitButton = new Button("Commit"); - commitButton.addListener(new ClickListener() { - - public void buttonClick(ClickEvent event) { - String msg = "Commit succesful"; - try { - getFieldBinder().commit(); - } catch (CommitException e) { - msg = "Commit failed: " + e.getMessage(); - } - Root.getCurrentRoot().showNotification(msg); - log.log(msg); - - } - }); - } - return commitButton; - } - - protected BeanFieldGroup getFieldBinder() { - return fieldBinder; - } - - protected void setFieldBinder(BeanFieldGroup beanFieldBinder) { - fieldBinder = beanFieldBinder; - } - - @Override - protected String getDescription() { - // TODO Auto-generated method stub - return null; - } - - @Override - protected Integer getTicketNumber() { - // TODO Auto-generated method stub - return null; - } - -} diff --git a/tests/testbench/com/vaadin/tests/fieldbinder/BasicPersonForm.java b/tests/testbench/com/vaadin/tests/fieldbinder/BasicPersonForm.java deleted file mode 100644 index 1ba9426fce..0000000000 --- a/tests/testbench/com/vaadin/tests/fieldbinder/BasicPersonForm.java +++ /dev/null @@ -1,192 +0,0 @@ -package com.vaadin.tests.fieldbinder; - -import com.vaadin.data.fieldgroup.BeanFieldGroup; -import com.vaadin.data.fieldgroup.FieldGroup; -import com.vaadin.data.fieldgroup.FieldGroup.CommitEvent; -import com.vaadin.data.fieldgroup.FieldGroup.CommitException; -import com.vaadin.data.fieldgroup.FieldGroup.CommitHandler; -import com.vaadin.data.util.BeanItem; -import com.vaadin.data.util.converter.StringToBooleanConverter; -import com.vaadin.data.validator.EmailValidator; -import com.vaadin.data.validator.IntegerRangeValidator; -import com.vaadin.data.validator.StringLengthValidator; -import com.vaadin.tests.components.TestBase; -import com.vaadin.tests.data.bean.Address; -import com.vaadin.tests.data.bean.Country; -import com.vaadin.tests.data.bean.Person; -import com.vaadin.tests.data.bean.Sex; -import com.vaadin.tests.util.Log; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Panel; -import com.vaadin.ui.Root; -import com.vaadin.ui.Table; -import com.vaadin.ui.TextArea; -import com.vaadin.ui.TextField; - -public class BasicPersonForm extends TestBase { - - private Log log = new Log(5); - private TextField firstName; - private TextArea lastName; - private TextField email; - private TextField age; - private Table sex; - private TextField deceased; - - public class Configuration { - public boolean preCommitFails = false; - public boolean postCommitFails = false; - - public boolean isPreCommitFails() { - return preCommitFails; - } - - public void setPreCommitFails(boolean preCommitFails) { - this.preCommitFails = preCommitFails; - } - - public boolean isPostCommitFails() { - return postCommitFails; - } - - public void setPostCommitFails(boolean postCommitFails) { - this.postCommitFails = postCommitFails; - } - - } - - private Configuration configuration = new Configuration(); - - private class ConfigurationPanel extends Panel { - - public ConfigurationPanel() { - super("Configuration"); - BeanItem bi = new BeanItem( - configuration); - FieldGroup confFieldGroup = new FieldGroup(bi); - confFieldGroup.setItemDataSource(bi); - confFieldGroup.setBuffered(false); - - for (Object propertyId : bi.getItemPropertyIds()) { - addComponent(confFieldGroup.buildAndBind(propertyId)); - } - - } - } - - @Override - protected void setup() { - addComponent(log); - Panel confPanel = new ConfigurationPanel(); - addComponent(confPanel); - - final FieldGroup fieldGroup = new BeanFieldGroup(Person.class); - fieldGroup.addCommitHandler(new CommitHandler() { - - public void preCommit(CommitEvent commitEvent) - throws CommitException { - if (configuration.preCommitFails) { - throw new CommitException( - "Error in preCommit because first name is " - + getPerson(commitEvent.getFieldBinder()) - .getFirstName()); - } - - } - - public void postCommit(CommitEvent commitEvent) - throws CommitException { - if (configuration.postCommitFails) { - throw new CommitException( - "Error in postCommit because first name is " - + getPerson(commitEvent.getFieldBinder()) - .getFirstName()); - } - } - }); - - fieldGroup.setBuffered(true); - - fieldGroup.buildAndBindMemberFields(this); - addComponent(firstName); - addComponent(lastName); - addComponent(email); - addComponent(age); - addComponent(sex); - addComponent(deceased); - - Button commitButton = new Button("Commit", new Button.ClickListener() { - - public void buttonClick(ClickEvent event) { - String msg = "Commit succesful"; - try { - fieldGroup.commit(); - } catch (CommitException e) { - msg = "Commit failed: " + e.getMessage(); - } - Root.getCurrentRoot().showNotification(msg); - log.log(msg); - - } - }); - Button discardButton = new Button("Discard", - new Button.ClickListener() { - - public void buttonClick(ClickEvent event) { - fieldGroup.discard(); - log.log("Discarded changes"); - - } - }); - Button showBean = new Button("Show bean values", - new Button.ClickListener() { - - public void buttonClick(ClickEvent event) { - log.log(getPerson(fieldGroup).toString()); - - } - }); - addComponent(commitButton); - addComponent(discardButton); - addComponent(showBean); - email.addValidator(new EmailValidator("Must be a valid address")); - lastName.addValidator(new StringLengthValidator("Must be min 5 chars", - 5, null, true)); - - age.addValidator(new IntegerRangeValidator( - "Must be between 0 and 150, {0} is not", 0, 150)); - sex.setPageLength(0); - deceased.setConverter(new StringToBooleanConverter() { - @Override - protected String getTrueString() { - return "YAY!"; - } - - @Override - protected String getFalseString() { - return "NAAAAAH"; - } - }); - Person p = new Person("John", "Doe", "john@doe.com", 64, Sex.MALE, - new Address("John street", 11223, "John's town", Country.USA)); - fieldGroup.setItemDataSource(new BeanItem(p)); - } - - public static Person getPerson(FieldGroup binder) { - return ((BeanItem) binder.getItemDataSource()).getBean(); - } - - @Override - protected String getDescription() { - // TODO Auto-generated method stub - return null; - } - - @Override - protected Integer getTicketNumber() { - // TODO Auto-generated method stub - return null; - } - -} diff --git a/tests/testbench/com/vaadin/tests/fieldbinder/FieldBinderWithBeanValidation.java b/tests/testbench/com/vaadin/tests/fieldbinder/FieldBinderWithBeanValidation.java deleted file mode 100644 index e7b581907e..0000000000 --- a/tests/testbench/com/vaadin/tests/fieldbinder/FieldBinderWithBeanValidation.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.vaadin.tests.fieldbinder; - -import com.vaadin.data.fieldgroup.BeanFieldGroup; -import com.vaadin.data.fieldgroup.FieldGroup; -import com.vaadin.data.fieldgroup.FieldGroup.CommitException; -import com.vaadin.data.util.BeanItem; -import com.vaadin.tests.components.TestBase; -import com.vaadin.tests.data.bean.Address; -import com.vaadin.tests.data.bean.Country; -import com.vaadin.tests.data.bean.Person; -import com.vaadin.tests.data.bean.PersonWithBeanValidationAnnotations; -import com.vaadin.tests.data.bean.Sex; -import com.vaadin.tests.util.Log; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Root; -import com.vaadin.ui.Table; -import com.vaadin.ui.TextArea; -import com.vaadin.ui.TextField; - -public class FieldBinderWithBeanValidation extends TestBase { - - private Log log = new Log(5); - private TextField firstName; - private TextArea lastName; - private TextField email; - private TextField age; - private Table sex; - private TextField deceased; - - @Override - protected void setup() { - addComponent(log); - - final BeanFieldGroup fieldGroup = new BeanFieldGroup( - PersonWithBeanValidationAnnotations.class); - - fieldGroup.buildAndBindMemberFields(this); - addComponent(firstName); - addComponent(lastName); - addComponent(email); - addComponent(age); - addComponent(sex); - addComponent(deceased); - - Button commitButton = new Button("Commit", new Button.ClickListener() { - - public void buttonClick(ClickEvent event) { - String msg = "Commit succesful"; - try { - fieldGroup.commit(); - } catch (CommitException e) { - msg = "Commit failed: " + e.getMessage(); - } - Root.getCurrentRoot().showNotification(msg); - log.log(msg); - - } - }); - Button discardButton = new Button("Discard", - new Button.ClickListener() { - - public void buttonClick(ClickEvent event) { - fieldGroup.discard(); - log.log("Discarded changes"); - - } - }); - Button showBean = new Button("Show bean values", - new Button.ClickListener() { - - public void buttonClick(ClickEvent event) { - log.log(getPerson(fieldGroup).toString()); - - } - }); - addComponent(commitButton); - addComponent(discardButton); - addComponent(showBean); - sex.setPageLength(0); - - PersonWithBeanValidationAnnotations p = new PersonWithBeanValidationAnnotations( - "John", "Doe", "john@doe.com", 64, Sex.MALE, new Address( - "John street", 11223, "John's town", Country.USA)); - fieldGroup - .setItemDataSource(new BeanItem( - p)); - } - - public static Person getPerson(FieldGroup binder) { - return ((BeanItem) binder.getItemDataSource()).getBean(); - } - - @Override - protected String getDescription() { - // TODO Auto-generated method stub - return null; - } - - @Override - protected Integer getTicketNumber() { - // TODO Auto-generated method stub - return null; - } - -} diff --git a/tests/testbench/com/vaadin/tests/fieldbinder/FormBuilderWithNestedProperties.java b/tests/testbench/com/vaadin/tests/fieldbinder/FormBuilderWithNestedProperties.java deleted file mode 100644 index e786dae279..0000000000 --- a/tests/testbench/com/vaadin/tests/fieldbinder/FormBuilderWithNestedProperties.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.vaadin.tests.fieldbinder; - -import com.vaadin.data.fieldgroup.BeanFieldGroup; -import com.vaadin.data.fieldgroup.FieldGroup; -import com.vaadin.data.fieldgroup.PropertyId; -import com.vaadin.data.util.BeanItem; -import com.vaadin.tests.components.TestBase; -import com.vaadin.tests.data.bean.Address; -import com.vaadin.tests.data.bean.Country; -import com.vaadin.tests.data.bean.Person; -import com.vaadin.tests.data.bean.Sex; -import com.vaadin.ui.TextField; - -public class FormBuilderWithNestedProperties extends TestBase { - - private TextField firstName; - private TextField lastName; - @PropertyId("address.streetAddress") - private TextField streetAddress; - - @Override - protected void setup() { - FieldGroup fieldGroup = new BeanFieldGroup(Person.class); - fieldGroup.buildAndBindMemberFields(this); - - addComponent(firstName); - addComponent(lastName); - addComponent(streetAddress); - - fieldGroup.setItemDataSource(new BeanItem(new Person("Who", - "me?", "email", 1, Sex.MALE, new Address("street name", 202020, - "City", Country.FINLAND)))); - } - - @Override - protected String getDescription() { - // TODO Auto-generated method stub - return null; - } - - @Override - protected Integer getTicketNumber() { - // TODO Auto-generated method stub - return null; - } - -} diff --git a/tests/testbench/com/vaadin/tests/fieldbinder/FormManyToMany.java b/tests/testbench/com/vaadin/tests/fieldbinder/FormManyToMany.java deleted file mode 100644 index 9b1535f688..0000000000 --- a/tests/testbench/com/vaadin/tests/fieldbinder/FormManyToMany.java +++ /dev/null @@ -1,28 +0,0 @@ -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; - } - -} diff --git a/tests/testbench/com/vaadin/tests/fieldbinder/FormOneToMany.java b/tests/testbench/com/vaadin/tests/fieldbinder/FormOneToMany.java deleted file mode 100644 index 56f66fddd0..0000000000 --- a/tests/testbench/com/vaadin/tests/fieldbinder/FormOneToMany.java +++ /dev/null @@ -1,43 +0,0 @@ -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 createMillionaireItem() { - Millionaire person = new Millionaire("First", "Last", "foo@vaadin.com", - "02-111 2222", "Ruukinkatu 2-4", 20540, "Turku"); - - BeanItem item = new BeanItem(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; - } - -} diff --git a/tests/testbench/com/vaadin/tests/fieldbinder/FormOneToOne.java b/tests/testbench/com/vaadin/tests/fieldbinder/FormOneToOne.java deleted file mode 100644 index 1616551d94..0000000000 --- a/tests/testbench/com/vaadin/tests/fieldbinder/FormOneToOne.java +++ /dev/null @@ -1,38 +0,0 @@ -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 createPersonItem() { - Person person = new Person("First", "Last", "foo@vaadin.com", - "02-111 2222", "Ruukinkatu 2-4", 20540, "Turku"); - - BeanItem item = new BeanItem(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; - } - -} diff --git a/tests/testbench/com/vaadin/tests/fieldbinder/FormWithNestedProperties.java b/tests/testbench/com/vaadin/tests/fieldbinder/FormWithNestedProperties.java deleted file mode 100644 index 7dbf1e7f13..0000000000 --- a/tests/testbench/com/vaadin/tests/fieldbinder/FormWithNestedProperties.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.vaadin.tests.fieldbinder; - -import com.vaadin.data.fieldgroup.BeanFieldGroup; -import com.vaadin.data.fieldgroup.PropertyId; -import com.vaadin.tests.data.bean.Address; -import com.vaadin.tests.data.bean.Country; -import com.vaadin.tests.data.bean.Person; -import com.vaadin.tests.data.bean.Sex; -import com.vaadin.tests.util.Log; -import com.vaadin.ui.CheckBox; -import com.vaadin.ui.NativeSelect; -import com.vaadin.ui.TextField; - -public class FormWithNestedProperties extends AbstractBeanFieldBinderTest { - - private Log log = new Log(5); - - private TextField firstName = new TextField("First name"); - private TextField lastName = new TextField("Last name"); - private TextField email = new TextField("Email"); - private TextField age = new TextField("Age"); - - @PropertyId("address.streetAddress") - private TextField streetAddress = new TextField("Street address"); - private NativeSelect country; - - private CheckBox deceased = new CheckBox("Deceased"); - - @Override - protected void setup() { - super.setup(); - - setFieldBinder(new BeanFieldGroup(Person.class)); - country = getFieldBinder().buildAndBind("country", "address.country", - NativeSelect.class); - getFieldBinder().bindMemberFields(this); - addComponent(firstName); - addComponent(lastName); - addComponent(streetAddress); - addComponent(country); - addComponent(email); - addComponent(age); - addComponent(deceased); - addComponent(getCommitButton()); - addComponent(getDiscardButton()); - addComponent(getShowBeanButton()); - - getFieldBinder().setItemDataSource( - new Person("First", "Last", "Email", 52, Sex.FEMALE, - new Address("street address", 01234, "City", - Country.FINLAND))); - - } - - @Override - protected String getDescription() { - // TODO Auto-generated method stub - return null; - } - - @Override - protected Integer getTicketNumber() { - // TODO Auto-generated method stub - return null; - } - -} diff --git a/tests/testbench/com/vaadin/tests/fieldgroup/AbstractBeanFieldBinderTest.java b/tests/testbench/com/vaadin/tests/fieldgroup/AbstractBeanFieldBinderTest.java new file mode 100644 index 0000000000..d91ebba150 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/fieldgroup/AbstractBeanFieldBinderTest.java @@ -0,0 +1,96 @@ +package com.vaadin.tests.fieldgroup; + +import com.vaadin.data.fieldgroup.BeanFieldGroup; +import com.vaadin.data.fieldgroup.FieldGroup.CommitException; +import com.vaadin.tests.components.TestBase; +import com.vaadin.tests.util.Log; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.Root; + +public abstract class AbstractBeanFieldBinderTest extends TestBase { + + private Button commitButton; + protected Log log = new Log(5); + + private Button discardButton; + private Button showBeanButton; + private BeanFieldGroup fieldBinder; + + @Override + protected void setup() { + addComponent(log); + } + + protected Button getDiscardButton() { + if (discardButton == null) { + discardButton = new Button("Discard", new Button.ClickListener() { + + public void buttonClick(ClickEvent event) { + getFieldBinder().discard(); + log.log("Discarded changes"); + + } + }); + } + return discardButton; + } + + protected Button getShowBeanButton() { + if (showBeanButton == null) { + showBeanButton = new Button("Show bean values", + new Button.ClickListener() { + + public void buttonClick(ClickEvent event) { + log.log(getFieldBinder().getItemDataSource() + .getBean().toString()); + + } + }); + } + return showBeanButton; + } + + protected Button getCommitButton() { + if (commitButton == null) { + commitButton = new Button("Commit"); + commitButton.addListener(new ClickListener() { + + public void buttonClick(ClickEvent event) { + String msg = "Commit succesful"; + try { + getFieldBinder().commit(); + } catch (CommitException e) { + msg = "Commit failed: " + e.getMessage(); + } + Root.getCurrentRoot().showNotification(msg); + log.log(msg); + + } + }); + } + return commitButton; + } + + protected BeanFieldGroup getFieldBinder() { + return fieldBinder; + } + + protected void setFieldBinder(BeanFieldGroup beanFieldBinder) { + fieldBinder = beanFieldBinder; + } + + @Override + protected String getDescription() { + // TODO Auto-generated method stub + return null; + } + + @Override + protected Integer getTicketNumber() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/tests/testbench/com/vaadin/tests/fieldgroup/BasicPersonForm.java b/tests/testbench/com/vaadin/tests/fieldgroup/BasicPersonForm.java new file mode 100644 index 0000000000..ddeb7268fb --- /dev/null +++ b/tests/testbench/com/vaadin/tests/fieldgroup/BasicPersonForm.java @@ -0,0 +1,192 @@ +package com.vaadin.tests.fieldgroup; + +import com.vaadin.data.fieldgroup.BeanFieldGroup; +import com.vaadin.data.fieldgroup.FieldGroup; +import com.vaadin.data.fieldgroup.FieldGroup.CommitEvent; +import com.vaadin.data.fieldgroup.FieldGroup.CommitException; +import com.vaadin.data.fieldgroup.FieldGroup.CommitHandler; +import com.vaadin.data.util.BeanItem; +import com.vaadin.data.util.converter.StringToBooleanConverter; +import com.vaadin.data.validator.EmailValidator; +import com.vaadin.data.validator.IntegerRangeValidator; +import com.vaadin.data.validator.StringLengthValidator; +import com.vaadin.tests.components.TestBase; +import com.vaadin.tests.data.bean.Address; +import com.vaadin.tests.data.bean.Country; +import com.vaadin.tests.data.bean.Person; +import com.vaadin.tests.data.bean.Sex; +import com.vaadin.tests.util.Log; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Panel; +import com.vaadin.ui.Root; +import com.vaadin.ui.Table; +import com.vaadin.ui.TextArea; +import com.vaadin.ui.TextField; + +public class BasicPersonForm extends TestBase { + + private Log log = new Log(5); + private TextField firstName; + private TextArea lastName; + private TextField email; + private TextField age; + private Table sex; + private TextField deceased; + + public class Configuration { + public boolean preCommitFails = false; + public boolean postCommitFails = false; + + public boolean isPreCommitFails() { + return preCommitFails; + } + + public void setPreCommitFails(boolean preCommitFails) { + this.preCommitFails = preCommitFails; + } + + public boolean isPostCommitFails() { + return postCommitFails; + } + + public void setPostCommitFails(boolean postCommitFails) { + this.postCommitFails = postCommitFails; + } + + } + + private Configuration configuration = new Configuration(); + + private class ConfigurationPanel extends Panel { + + public ConfigurationPanel() { + super("Configuration"); + BeanItem bi = new BeanItem( + configuration); + FieldGroup confFieldGroup = new FieldGroup(bi); + confFieldGroup.setItemDataSource(bi); + confFieldGroup.setBuffered(false); + + for (Object propertyId : bi.getItemPropertyIds()) { + addComponent(confFieldGroup.buildAndBind(propertyId)); + } + + } + } + + @Override + protected void setup() { + addComponent(log); + Panel confPanel = new ConfigurationPanel(); + addComponent(confPanel); + + final FieldGroup fieldGroup = new BeanFieldGroup(Person.class); + fieldGroup.addCommitHandler(new CommitHandler() { + + public void preCommit(CommitEvent commitEvent) + throws CommitException { + if (configuration.preCommitFails) { + throw new CommitException( + "Error in preCommit because first name is " + + getPerson(commitEvent.getFieldBinder()) + .getFirstName()); + } + + } + + public void postCommit(CommitEvent commitEvent) + throws CommitException { + if (configuration.postCommitFails) { + throw new CommitException( + "Error in postCommit because first name is " + + getPerson(commitEvent.getFieldBinder()) + .getFirstName()); + } + } + }); + + fieldGroup.setBuffered(true); + + fieldGroup.buildAndBindMemberFields(this); + addComponent(firstName); + addComponent(lastName); + addComponent(email); + addComponent(age); + addComponent(sex); + addComponent(deceased); + + Button commitButton = new Button("Commit", new Button.ClickListener() { + + public void buttonClick(ClickEvent event) { + String msg = "Commit succesful"; + try { + fieldGroup.commit(); + } catch (CommitException e) { + msg = "Commit failed: " + e.getMessage(); + } + Root.getCurrentRoot().showNotification(msg); + log.log(msg); + + } + }); + Button discardButton = new Button("Discard", + new Button.ClickListener() { + + public void buttonClick(ClickEvent event) { + fieldGroup.discard(); + log.log("Discarded changes"); + + } + }); + Button showBean = new Button("Show bean values", + new Button.ClickListener() { + + public void buttonClick(ClickEvent event) { + log.log(getPerson(fieldGroup).toString()); + + } + }); + addComponent(commitButton); + addComponent(discardButton); + addComponent(showBean); + email.addValidator(new EmailValidator("Must be a valid address")); + lastName.addValidator(new StringLengthValidator("Must be min 5 chars", + 5, null, true)); + + age.addValidator(new IntegerRangeValidator( + "Must be between 0 and 150, {0} is not", 0, 150)); + sex.setPageLength(0); + deceased.setConverter(new StringToBooleanConverter() { + @Override + protected String getTrueString() { + return "YAY!"; + } + + @Override + protected String getFalseString() { + return "NAAAAAH"; + } + }); + Person p = new Person("John", "Doe", "john@doe.com", 64, Sex.MALE, + new Address("John street", 11223, "John's town", Country.USA)); + fieldGroup.setItemDataSource(new BeanItem(p)); + } + + public static Person getPerson(FieldGroup binder) { + return ((BeanItem) binder.getItemDataSource()).getBean(); + } + + @Override + protected String getDescription() { + // TODO Auto-generated method stub + return null; + } + + @Override + protected Integer getTicketNumber() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/tests/testbench/com/vaadin/tests/fieldgroup/FieldBinderWithBeanValidation.java b/tests/testbench/com/vaadin/tests/fieldgroup/FieldBinderWithBeanValidation.java new file mode 100644 index 0000000000..5e5f3093ae --- /dev/null +++ b/tests/testbench/com/vaadin/tests/fieldgroup/FieldBinderWithBeanValidation.java @@ -0,0 +1,106 @@ +package com.vaadin.tests.fieldgroup; + +import com.vaadin.data.fieldgroup.BeanFieldGroup; +import com.vaadin.data.fieldgroup.FieldGroup; +import com.vaadin.data.fieldgroup.FieldGroup.CommitException; +import com.vaadin.data.util.BeanItem; +import com.vaadin.tests.components.TestBase; +import com.vaadin.tests.data.bean.Address; +import com.vaadin.tests.data.bean.Country; +import com.vaadin.tests.data.bean.Person; +import com.vaadin.tests.data.bean.PersonWithBeanValidationAnnotations; +import com.vaadin.tests.data.bean.Sex; +import com.vaadin.tests.util.Log; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Root; +import com.vaadin.ui.Table; +import com.vaadin.ui.TextArea; +import com.vaadin.ui.TextField; + +public class FieldBinderWithBeanValidation extends TestBase { + + private Log log = new Log(5); + private TextField firstName; + private TextArea lastName; + private TextField email; + private TextField age; + private Table sex; + private TextField deceased; + + @Override + protected void setup() { + addComponent(log); + + final BeanFieldGroup fieldGroup = new BeanFieldGroup( + PersonWithBeanValidationAnnotations.class); + + fieldGroup.buildAndBindMemberFields(this); + addComponent(firstName); + addComponent(lastName); + addComponent(email); + addComponent(age); + addComponent(sex); + addComponent(deceased); + + Button commitButton = new Button("Commit", new Button.ClickListener() { + + public void buttonClick(ClickEvent event) { + String msg = "Commit succesful"; + try { + fieldGroup.commit(); + } catch (CommitException e) { + msg = "Commit failed: " + e.getMessage(); + } + Root.getCurrentRoot().showNotification(msg); + log.log(msg); + + } + }); + Button discardButton = new Button("Discard", + new Button.ClickListener() { + + public void buttonClick(ClickEvent event) { + fieldGroup.discard(); + log.log("Discarded changes"); + + } + }); + Button showBean = new Button("Show bean values", + new Button.ClickListener() { + + public void buttonClick(ClickEvent event) { + log.log(getPerson(fieldGroup).toString()); + + } + }); + addComponent(commitButton); + addComponent(discardButton); + addComponent(showBean); + sex.setPageLength(0); + + PersonWithBeanValidationAnnotations p = new PersonWithBeanValidationAnnotations( + "John", "Doe", "john@doe.com", 64, Sex.MALE, new Address( + "John street", 11223, "John's town", Country.USA)); + fieldGroup + .setItemDataSource(new BeanItem( + p)); + } + + public static Person getPerson(FieldGroup binder) { + return ((BeanItem) binder.getItemDataSource()).getBean(); + } + + @Override + protected String getDescription() { + // TODO Auto-generated method stub + return null; + } + + @Override + protected Integer getTicketNumber() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/tests/testbench/com/vaadin/tests/fieldgroup/FormBuilderWithNestedProperties.java b/tests/testbench/com/vaadin/tests/fieldgroup/FormBuilderWithNestedProperties.java new file mode 100644 index 0000000000..191ccb9134 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/fieldgroup/FormBuilderWithNestedProperties.java @@ -0,0 +1,47 @@ +package com.vaadin.tests.fieldgroup; + +import com.vaadin.data.fieldgroup.BeanFieldGroup; +import com.vaadin.data.fieldgroup.FieldGroup; +import com.vaadin.data.fieldgroup.PropertyId; +import com.vaadin.data.util.BeanItem; +import com.vaadin.tests.components.TestBase; +import com.vaadin.tests.data.bean.Address; +import com.vaadin.tests.data.bean.Country; +import com.vaadin.tests.data.bean.Person; +import com.vaadin.tests.data.bean.Sex; +import com.vaadin.ui.TextField; + +public class FormBuilderWithNestedProperties extends TestBase { + + private TextField firstName; + private TextField lastName; + @PropertyId("address.streetAddress") + private TextField streetAddress; + + @Override + protected void setup() { + FieldGroup fieldGroup = new BeanFieldGroup(Person.class); + fieldGroup.buildAndBindMemberFields(this); + + addComponent(firstName); + addComponent(lastName); + addComponent(streetAddress); + + fieldGroup.setItemDataSource(new BeanItem(new Person("Who", + "me?", "email", 1, Sex.MALE, new Address("street name", 202020, + "City", Country.FINLAND)))); + } + + @Override + protected String getDescription() { + // TODO Auto-generated method stub + return null; + } + + @Override + protected Integer getTicketNumber() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/tests/testbench/com/vaadin/tests/fieldgroup/FormManyToMany.java b/tests/testbench/com/vaadin/tests/fieldgroup/FormManyToMany.java new file mode 100644 index 0000000000..f4f612503c --- /dev/null +++ b/tests/testbench/com/vaadin/tests/fieldgroup/FormManyToMany.java @@ -0,0 +1,28 @@ +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; + } + +} diff --git a/tests/testbench/com/vaadin/tests/fieldgroup/FormOneToMany.java b/tests/testbench/com/vaadin/tests/fieldgroup/FormOneToMany.java new file mode 100644 index 0000000000..e269a39441 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/fieldgroup/FormOneToMany.java @@ -0,0 +1,43 @@ +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 createMillionaireItem() { + Millionaire person = new Millionaire("First", "Last", "foo@vaadin.com", + "02-111 2222", "Ruukinkatu 2-4", 20540, "Turku"); + + BeanItem item = new BeanItem(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; + } + +} diff --git a/tests/testbench/com/vaadin/tests/fieldgroup/FormOneToOne.java b/tests/testbench/com/vaadin/tests/fieldgroup/FormOneToOne.java new file mode 100644 index 0000000000..b16cb29a8a --- /dev/null +++ b/tests/testbench/com/vaadin/tests/fieldgroup/FormOneToOne.java @@ -0,0 +1,38 @@ +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 createPersonItem() { + Person person = new Person("First", "Last", "foo@vaadin.com", + "02-111 2222", "Ruukinkatu 2-4", 20540, "Turku"); + + BeanItem item = new BeanItem(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; + } + +} diff --git a/tests/testbench/com/vaadin/tests/fieldgroup/FormWithNestedProperties.java b/tests/testbench/com/vaadin/tests/fieldgroup/FormWithNestedProperties.java new file mode 100644 index 0000000000..205d70eba3 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/fieldgroup/FormWithNestedProperties.java @@ -0,0 +1,67 @@ +package com.vaadin.tests.fieldgroup; + +import com.vaadin.data.fieldgroup.BeanFieldGroup; +import com.vaadin.data.fieldgroup.PropertyId; +import com.vaadin.tests.data.bean.Address; +import com.vaadin.tests.data.bean.Country; +import com.vaadin.tests.data.bean.Person; +import com.vaadin.tests.data.bean.Sex; +import com.vaadin.tests.util.Log; +import com.vaadin.ui.CheckBox; +import com.vaadin.ui.NativeSelect; +import com.vaadin.ui.TextField; + +public class FormWithNestedProperties extends AbstractBeanFieldBinderTest { + + private Log log = new Log(5); + + private TextField firstName = new TextField("First name"); + private TextField lastName = new TextField("Last name"); + private TextField email = new TextField("Email"); + private TextField age = new TextField("Age"); + + @PropertyId("address.streetAddress") + private TextField streetAddress = new TextField("Street address"); + private NativeSelect country; + + private CheckBox deceased = new CheckBox("Deceased"); + + @Override + protected void setup() { + super.setup(); + + setFieldBinder(new BeanFieldGroup(Person.class)); + country = getFieldBinder().buildAndBind("country", "address.country", + NativeSelect.class); + getFieldBinder().bindMemberFields(this); + addComponent(firstName); + addComponent(lastName); + addComponent(streetAddress); + addComponent(country); + addComponent(email); + addComponent(age); + addComponent(deceased); + addComponent(getCommitButton()); + addComponent(getDiscardButton()); + addComponent(getShowBeanButton()); + + getFieldBinder().setItemDataSource( + new Person("First", "Last", "Email", 52, Sex.FEMALE, + new Address("street address", 01234, "City", + Country.FINLAND))); + + } + + @Override + protected String getDescription() { + // TODO Auto-generated method stub + return null; + } + + @Override + protected Integer getTicketNumber() { + // TODO Auto-generated method stub + return null; + } + +}