]> source.dussan.org Git - vaadin-framework.git/commitdiff
com.vaadin.tests.fieldbinder -> com.vaadin.tests.fieldgroup
authorArtur Signell <artur@vaadin.com>
Thu, 22 Dec 2011 18:54:36 +0000 (20:54 +0200)
committerArtur Signell <artur@vaadin.com>
Thu, 22 Dec 2011 21:17:12 +0000 (23:17 +0200)
16 files changed:
tests/testbench/com/vaadin/tests/fieldbinder/AbstractBeanFieldBinderTest.java [deleted file]
tests/testbench/com/vaadin/tests/fieldbinder/BasicPersonForm.java [deleted file]
tests/testbench/com/vaadin/tests/fieldbinder/FieldBinderWithBeanValidation.java [deleted file]
tests/testbench/com/vaadin/tests/fieldbinder/FormBuilderWithNestedProperties.java [deleted file]
tests/testbench/com/vaadin/tests/fieldbinder/FormManyToMany.java [deleted file]
tests/testbench/com/vaadin/tests/fieldbinder/FormOneToMany.java [deleted file]
tests/testbench/com/vaadin/tests/fieldbinder/FormOneToOne.java [deleted file]
tests/testbench/com/vaadin/tests/fieldbinder/FormWithNestedProperties.java [deleted file]
tests/testbench/com/vaadin/tests/fieldgroup/AbstractBeanFieldBinderTest.java [new file with mode: 0644]
tests/testbench/com/vaadin/tests/fieldgroup/BasicPersonForm.java [new file with mode: 0644]
tests/testbench/com/vaadin/tests/fieldgroup/FieldBinderWithBeanValidation.java [new file with mode: 0644]
tests/testbench/com/vaadin/tests/fieldgroup/FormBuilderWithNestedProperties.java [new file with mode: 0644]
tests/testbench/com/vaadin/tests/fieldgroup/FormManyToMany.java [new file with mode: 0644]
tests/testbench/com/vaadin/tests/fieldgroup/FormOneToMany.java [new file with mode: 0644]
tests/testbench/com/vaadin/tests/fieldgroup/FormOneToOne.java [new file with mode: 0644]
tests/testbench/com/vaadin/tests/fieldgroup/FormWithNestedProperties.java [new file with mode: 0644]

diff --git a/tests/testbench/com/vaadin/tests/fieldbinder/AbstractBeanFieldBinderTest.java b/tests/testbench/com/vaadin/tests/fieldbinder/AbstractBeanFieldBinderTest.java
deleted file mode 100644 (file)
index e2ed2ad..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-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
diff --git a/tests/testbench/com/vaadin/tests/fieldbinder/BasicPersonForm.java b/tests/testbench/com/vaadin/tests/fieldbinder/BasicPersonForm.java
deleted file mode 100644 (file)
index 1ba9426..0000000
+++ /dev/null
@@ -1,192 +0,0 @@
-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
diff --git a/tests/testbench/com/vaadin/tests/fieldbinder/FieldBinderWithBeanValidation.java b/tests/testbench/com/vaadin/tests/fieldbinder/FieldBinderWithBeanValidation.java
deleted file mode 100644 (file)
index e7b5819..0000000
+++ /dev/null
@@ -1,106 +0,0 @@
-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
diff --git a/tests/testbench/com/vaadin/tests/fieldbinder/FormBuilderWithNestedProperties.java b/tests/testbench/com/vaadin/tests/fieldbinder/FormBuilderWithNestedProperties.java
deleted file mode 100644 (file)
index e786dae..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-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
diff --git a/tests/testbench/com/vaadin/tests/fieldbinder/FormManyToMany.java b/tests/testbench/com/vaadin/tests/fieldbinder/FormManyToMany.java
deleted file mode 100644 (file)
index 9b1535f..0000000
+++ /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 (file)
index 56f66fd..0000000
+++ /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<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;
-    }
-
-}
diff --git a/tests/testbench/com/vaadin/tests/fieldbinder/FormOneToOne.java b/tests/testbench/com/vaadin/tests/fieldbinder/FormOneToOne.java
deleted file mode 100644 (file)
index 1616551..0000000
+++ /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<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;
-    }
-
-}
diff --git a/tests/testbench/com/vaadin/tests/fieldbinder/FormWithNestedProperties.java b/tests/testbench/com/vaadin/tests/fieldbinder/FormWithNestedProperties.java
deleted file mode 100644 (file)
index 7dbf1e7..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-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
diff --git a/tests/testbench/com/vaadin/tests/fieldgroup/AbstractBeanFieldBinderTest.java b/tests/testbench/com/vaadin/tests/fieldgroup/AbstractBeanFieldBinderTest.java
new file mode 100644 (file)
index 0000000..d91ebba
--- /dev/null
@@ -0,0 +1,96 @@
+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
diff --git a/tests/testbench/com/vaadin/tests/fieldgroup/BasicPersonForm.java b/tests/testbench/com/vaadin/tests/fieldgroup/BasicPersonForm.java
new file mode 100644 (file)
index 0000000..ddeb726
--- /dev/null
@@ -0,0 +1,192 @@
+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
diff --git a/tests/testbench/com/vaadin/tests/fieldgroup/FieldBinderWithBeanValidation.java b/tests/testbench/com/vaadin/tests/fieldgroup/FieldBinderWithBeanValidation.java
new file mode 100644 (file)
index 0000000..5e5f309
--- /dev/null
@@ -0,0 +1,106 @@
+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
diff --git a/tests/testbench/com/vaadin/tests/fieldgroup/FormBuilderWithNestedProperties.java b/tests/testbench/com/vaadin/tests/fieldgroup/FormBuilderWithNestedProperties.java
new file mode 100644 (file)
index 0000000..191ccb9
--- /dev/null
@@ -0,0 +1,47 @@
+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
diff --git a/tests/testbench/com/vaadin/tests/fieldgroup/FormManyToMany.java b/tests/testbench/com/vaadin/tests/fieldgroup/FormManyToMany.java
new file mode 100644 (file)
index 0000000..f4f6125
--- /dev/null
@@ -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 (file)
index 0000000..e269a39
--- /dev/null
@@ -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<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;
+    }
+
+}
diff --git a/tests/testbench/com/vaadin/tests/fieldgroup/FormOneToOne.java b/tests/testbench/com/vaadin/tests/fieldgroup/FormOneToOne.java
new file mode 100644 (file)
index 0000000..b16cb29
--- /dev/null
@@ -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<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;
+    }
+
+}
diff --git a/tests/testbench/com/vaadin/tests/fieldgroup/FormWithNestedProperties.java b/tests/testbench/com/vaadin/tests/fieldgroup/FormWithNestedProperties.java
new file mode 100644 (file)
index 0000000..205d70e
--- /dev/null
@@ -0,0 +1,67 @@
+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