]> source.dussan.org Git - vaadin-framework.git/commitdiff
#2812 copied AddressBook tutorial changes from the incubator project to Vaadin
authorHenri Sara <henri.sara@itmill.com>
Tue, 19 May 2009 13:36:19 +0000 (13:36 +0000)
committerHenri Sara <henri.sara@itmill.com>
Tue, 19 May 2009 13:36:19 +0000 (13:36 +0000)
svn changeset:7892/svn branch:6.0

WebContent/VAADIN/themes/contacts/styles.css
src/com/vaadin/demo/tutorial/addressbook/AddressBookApplication.java
src/com/vaadin/demo/tutorial/addressbook/data/Person.java
src/com/vaadin/demo/tutorial/addressbook/data/PersonContainer.java
src/com/vaadin/demo/tutorial/addressbook/data/SearchFilter.java
src/com/vaadin/demo/tutorial/addressbook/ui/PersonForm.java
src/com/vaadin/demo/tutorial/addressbook/validators/EmailValidator.java [deleted file]
src/com/vaadin/demo/tutorial/addressbook/validators/PostalCodeValidator.java [deleted file]

index c79dcb497e9b67af6c7f3f9b1dbb5b1ddcc4bb59..5a93f8604c3e7c36bf3576118ea468c61e9d3587 100644 (file)
@@ -1,4 +1,5 @@
  @import url(../runo/styles.css);
+/* Using the old default theme (runo) as the basis for now */
 
 /* Add some padding to the tree */
 .v-tree {
index ad61246c22fab267147500368e9f884e65f60f1f..2412f31916c5a6ee61ec5751f0a7a989a14e3037 100644 (file)
@@ -1,7 +1,3 @@
-/* 
-@ITMillApache2LicenseForJavaFiles@
- */
-
 package com.vaadin.demo.tutorial.addressbook;
 
 import com.vaadin.Application;
index 772f3e143ab9fa6bb37579cffb4fbc3b109aa67c..07395042107f4da4158bb056d524a59924da16dd 100644 (file)
@@ -3,117 +3,117 @@ package com.vaadin.demo.tutorial.addressbook.data;
 import java.io.Serializable;
 
 public class Person implements Serializable {
-    private String firstName = "";
-    private String lastName = "";
-    private String email = "";
-    private String phoneNumber = "";
-    private String streetAddress = "";
-    private Integer postalCode = null;
-    private String city = "";
-
-    /**
-     * @return the firstName
-     */
-    public String getFirstName() {
-        return firstName;
-    }
-
-    /**
-     * @param firstName
-     *            the firstName to set
-     */
-    public void setFirstName(String firstName) {
-        this.firstName = firstName;
-    }
-
-    /**
-     * @return the lastName
-     */
-    public String getLastName() {
-        return lastName;
-    }
-
-    /**
-     * @param lastName
-     *            the lastName to set
-     */
-    public void setLastName(String lastName) {
-        this.lastName = lastName;
-    }
-
-    /**
-     * @return the email
-     */
-    public String getEmail() {
-        return email;
-    }
-
-    /**
-     * @param email
-     *            the email to set
-     */
-    public void setEmail(String email) {
-        this.email = email;
-    }
-
-    /**
-     * @return the phoneNumber
-     */
-    public String getPhoneNumber() {
-        return phoneNumber;
-    }
-
-    /**
-     * @param phoneNumber
-     *            the phoneNumber to set
-     */
-    public void setPhoneNumber(String phoneNumber) {
-        this.phoneNumber = phoneNumber;
-    }
-
-    /**
-     * @return the streetAddress
-     */
-    public String getStreetAddress() {
-        return streetAddress;
-    }
-
-    /**
-     * @param streetAddress
-     *            the streetAddress to set
-     */
-    public void setStreetAddress(String streetAddress) {
-        this.streetAddress = streetAddress;
-    }
-
-    /**
-     * @return the postalCode
-     */
-    public Integer getPostalCode() {
-        return postalCode;
-    }
-
-    /**
-     * @param postalCode
-     *            the postalCode to set
-     */
-    public void setPostalCode(Integer postalCode) {
-        this.postalCode = postalCode;
-    }
-
-    /**
-     * @return the city
-     */
-    public String getCity() {
-        return city;
-    }
-
-    /**
-     * @param city
-     *            the city to set
-     */
-    public void setCity(String city) {
-        this.city = city;
-    }
+       private String firstName = "";
+       private String lastName = "";
+       private String email = "";
+       private String phoneNumber = "";
+       private String streetAddress = "";
+       private Integer postalCode = null;
+       private String city = "";
+
+       /**
+        * @return the firstName
+        */
+       public String getFirstName() {
+               return firstName;
+       }
+
+       /**
+        * @param firstName
+        *            the firstName to set
+        */
+       public void setFirstName(String firstName) {
+               this.firstName = firstName;
+       }
+
+       /**
+        * @return the lastName
+        */
+       public String getLastName() {
+               return lastName;
+       }
+
+       /**
+        * @param lastName
+        *            the lastName to set
+        */
+       public void setLastName(String lastName) {
+               this.lastName = lastName;
+       }
+
+       /**
+        * @return the email
+        */
+       public String getEmail() {
+               return email;
+       }
+
+       /**
+        * @param email
+        *            the email to set
+        */
+       public void setEmail(String email) {
+               this.email = email;
+       }
+
+       /**
+        * @return the phoneNumber
+        */
+       public String getPhoneNumber() {
+               return phoneNumber;
+       }
+
+       /**
+        * @param phoneNumber
+        *            the phoneNumber to set
+        */
+       public void setPhoneNumber(String phoneNumber) {
+               this.phoneNumber = phoneNumber;
+       }
+
+       /**
+        * @return the streetAddress
+        */
+       public String getStreetAddress() {
+               return streetAddress;
+       }
+
+       /**
+        * @param streetAddress
+        *            the streetAddress to set
+        */
+       public void setStreetAddress(String streetAddress) {
+               this.streetAddress = streetAddress;
+       }
+
+       /**
+        * @return the postalCode
+        */
+       public Integer getPostalCode() {
+               return postalCode;
+       }
+
+       /**
+        * @param postalCode
+        *            the postalCode to set
+        */
+       public void setPostalCode(Integer postalCode) {
+               this.postalCode = postalCode;
+       }
+
+       /**
+        * @return the city
+        */
+       public String getCity() {
+               return city;
+       }
+
+       /**
+        * @param city
+        *            the city to set
+        */
+       public void setCity(String city) {
+               this.city = city;
+       }
 
 }
\ No newline at end of file
index 5be844cc7f8b07868026c327c082d8a0a08c068d..b753125505916424be68ff0d770b9e0489c7ee07 100644 (file)
@@ -6,88 +6,88 @@ import java.util.Random;
 import com.vaadin.data.util.BeanItemContainer;
 
 public class PersonContainer extends BeanItemContainer<Person> implements
-        Serializable {
+               Serializable {
 
-    /**
-     * Natural property order for Person bean. Used in tables and forms.
-     */
-    public static final Object[] NATURAL_COL_ORDER = new Object[] {
-            "firstName", "lastName", "email", "phoneNumber", "streetAddress",
-            "postalCode", "city" };
+       /**
+        * Natural property order for Person bean. Used in tables and forms.
+        */
+       public static final Object[] NATURAL_COL_ORDER = new Object[] {
+                       "firstName", "lastName", "email", "phoneNumber", "streetAddress",
+                       "postalCode", "city" };
 
-    /**
-     * "Human readable" captions for properties in same order as in
-     * NATURAL_COL_ORDER.
-     */
-    public static final String[] COL_HEADERS_ENGLISH = new String[] {
-            "First name", "Last name", "Email", "Phone number",
-            "Street Address", "Postal Code", "City" };
+       /**
+        * "Human readable" captions for properties in same order as in
+        * NATURAL_COL_ORDER.
+        */
+       public static final String[] COL_HEADERS_ENGLISH = new String[] {
+                       "First name", "Last name", "Email", "Phone number",
+                       "Street Address", "Postal Code", "City" };
 
-    public PersonContainer() throws InstantiationException,
-            IllegalAccessException {
-        super(Person.class);
-    }
+       public PersonContainer() throws InstantiationException,
+                       IllegalAccessException {
+               super(Person.class);
+       }
 
-    public static PersonContainer createWithTestData() {
-        final String[] fnames = { "Peter", "Alice", "Joshua", "Mike", "Olivia",
-                "Nina", "Alex", "Rita", "Dan", "Umberto", "Henrik", "Rene",
-                "Lisa", "Marge" };
-        final String[] lnames = { "Smith", "Gordon", "Simpson", "Brown",
-                "Clavel", "Simons", "Verne", "Scott", "Allison", "Gates",
-                "Rowling", "Barks", "Ross", "Schneider", "Tate" };
-        final String cities[] = { "Amsterdam", "Berlin", "Helsinki",
-                "Hong Kong", "London", "Luxemburg", "New York", "Oslo",
-                "Paris", "Rome", "Stockholm", "Tokyo", "Turku" };
-        final String streets[] = { "4215 Blandit Av.", "452-8121 Sem Ave",
-                "279-4475 Tellus Road", "4062 Libero. Av.", "7081 Pede. Ave",
-                "6800 Aliquet St.", "P.O. Box 298, 9401 Mauris St.",
-                "161-7279 Augue Ave", "P.O. Box 496, 1390 Sagittis. Rd.",
-                "448-8295 Mi Avenue", "6419 Non Av.",
-                "659-2538 Elementum Street", "2205 Quis St.",
-                "252-5213 Tincidunt St.", "P.O. Box 175, 4049 Adipiscing Rd.",
-                "3217 Nam Ave", "P.O. Box 859, 7661 Auctor St.",
-                "2873 Nonummy Av.", "7342 Mi, Avenue",
-                "539-3914 Dignissim. Rd.", "539-3675 Magna Avenue",
-                "Ap #357-5640 Pharetra Avenue", "416-2983 Posuere Rd.",
-                "141-1287 Adipiscing Avenue", "Ap #781-3145 Gravida St.",
-                "6897 Suscipit Rd.", "8336 Purus Avenue", "2603 Bibendum. Av.",
-                "2870 Vestibulum St.", "Ap #722 Aenean Avenue",
-                "446-968 Augue Ave", "1141 Ultricies Street",
-                "Ap #992-5769 Nunc Street", "6690 Porttitor Avenue",
-                "Ap #105-1700 Risus Street",
-                "P.O. Box 532, 3225 Lacus. Avenue", "736 Metus Street",
-                "414-1417 Fringilla Street", "Ap #183-928 Scelerisque Road",
-                "561-9262 Iaculis Avenue" };
-        PersonContainer c = null;
-        Random r = new Random(0);
-        try {
-            c = new PersonContainer();
-            for (int i = 0; i < 100; i++) {
-                Person p = new Person();
-                p.setFirstName(fnames[r.nextInt(fnames.length)]);
-                p.setLastName(lnames[r.nextInt(lnames.length)]);
-                p.setCity(cities[r.nextInt(cities.length)]);
-                p.setEmail(p.getFirstName().toLowerCase() + "."
-                        + p.getLastName().toLowerCase() + "@vaadin.com");
-                p.setPhoneNumber("+358 02 555 " + r.nextInt(10) + r.nextInt(10)
-                        + r.nextInt(10) + r.nextInt(10));
-                int n = r.nextInt(100000);
-                if (n < 10000) {
-                    n += 10000;
-                }
-                p.setPostalCode(n);
-                p.setStreetAddress(streets[r.nextInt(streets.length)]);
-                c.addItem(p);
-            }
-        } catch (InstantiationException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        } catch (IllegalAccessException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
+       public static PersonContainer createWithTestData() {
+               final String[] fnames = { "Peter", "Alice", "Joshua", "Mike", "Olivia",
+                               "Nina", "Alex", "Rita", "Dan", "Umberto", "Henrik", "Rene",
+                               "Lisa", "Marge" };
+               final String[] lnames = { "Smith", "Gordon", "Simpson", "Brown",
+                               "Clavel", "Simons", "Verne", "Scott", "Allison", "Gates",
+                               "Rowling", "Barks", "Ross", "Schneider", "Tate" };
+               final String cities[] = { "Amsterdam", "Berlin", "Helsinki",
+                               "Hong Kong", "London", "Luxemburg", "New York", "Oslo",
+                               "Paris", "Rome", "Stockholm", "Tokyo", "Turku" };
+               final String streets[] = { "4215 Blandit Av.", "452-8121 Sem Ave",
+                               "279-4475 Tellus Road", "4062 Libero. Av.", "7081 Pede. Ave",
+                               "6800 Aliquet St.", "P.O. Box 298, 9401 Mauris St.",
+                               "161-7279 Augue Ave", "P.O. Box 496, 1390 Sagittis. Rd.",
+                               "448-8295 Mi Avenue", "6419 Non Av.",
+                               "659-2538 Elementum Street", "2205 Quis St.",
+                               "252-5213 Tincidunt St.", "P.O. Box 175, 4049 Adipiscing Rd.",
+                               "3217 Nam Ave", "P.O. Box 859, 7661 Auctor St.",
+                               "2873 Nonummy Av.", "7342 Mi, Avenue",
+                               "539-3914 Dignissim. Rd.", "539-3675 Magna Avenue",
+                               "Ap #357-5640 Pharetra Avenue", "416-2983 Posuere Rd.",
+                               "141-1287 Adipiscing Avenue", "Ap #781-3145 Gravida St.",
+                               "6897 Suscipit Rd.", "8336 Purus Avenue", "2603 Bibendum. Av.",
+                               "2870 Vestibulum St.", "Ap #722 Aenean Avenue",
+                               "446-968 Augue Ave", "1141 Ultricies Street",
+                               "Ap #992-5769 Nunc Street", "6690 Porttitor Avenue",
+                               "Ap #105-1700 Risus Street",
+                               "P.O. Box 532, 3225 Lacus. Avenue", "736 Metus Street",
+                               "414-1417 Fringilla Street", "Ap #183-928 Scelerisque Road",
+                               "561-9262 Iaculis Avenue" };
+               PersonContainer c = null;
+               Random r = new Random(0);
+               try {
+                       c = new PersonContainer();
+                       for (int i = 0; i < 100; i++) {
+                               Person p = new Person();
+                               p.setFirstName(fnames[r.nextInt(fnames.length)]);
+                               p.setLastName(lnames[r.nextInt(lnames.length)]);
+                               p.setCity(cities[r.nextInt(cities.length)]);
+                               p.setEmail(p.getFirstName().toLowerCase() + "."
+                                               + p.getLastName().toLowerCase() + "@vaadin.com");
+                               p.setPhoneNumber("+358 02 555 " + r.nextInt(10) + r.nextInt(10)
+                                               + r.nextInt(10) + r.nextInt(10));
+                               int n = r.nextInt(100000);
+                               if (n < 10000) {
+                                       n += 10000;
+                               }
+                               p.setPostalCode(n);
+                               p.setStreetAddress(streets[r.nextInt(streets.length)]);
+                               c.addItem(p);
+                       }
+               } catch (InstantiationException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               } catch (IllegalAccessException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }
 
-        return c;
-    }
+               return c;
+       }
 
 }
index fd7eb16ae99daa43839cd247bae38f7768e6b344..c5aa3e37ed8022eee8cdce4d0b19a4df646501b6 100644 (file)
@@ -4,40 +4,40 @@ import java.io.Serializable;
 
 public class SearchFilter implements Serializable {
 
-    private final String term;
-    private final Object propertyId;
-    private String searchName;
-
-    public SearchFilter(Object propertyId, String searchTerm, String name) {
-        this.propertyId = propertyId;
-        term = searchTerm;
-        searchName = name;
-    }
-
-    /**
-     * @return the term
-     */
-    public String getTerm() {
-        return term;
-    }
-
-    /**
-     * @return the propertyId
-     */
-    public Object getPropertyId() {
-        return propertyId;
-    }
-
-    /**
-     * @return the name of the search
-     */
-    public String getSearchName() {
-        return searchName;
-    }
-
-    @Override
-    public String toString() {
-        return getSearchName();
-    }
+       private final String term;
+       private final Object propertyId;
+       private String searchName;
+
+       public SearchFilter(Object propertyId, String searchTerm, String name) {
+               this.propertyId = propertyId;
+               term = searchTerm;
+               searchName = name;
+       }
+
+       /**
+        * @return the term
+        */
+       public String getTerm() {
+               return term;
+       }
+
+       /**
+        * @return the propertyId
+        */
+       public Object getPropertyId() {
+               return propertyId;
+       }
+
+       /**
+        * @return the name of the search
+        */
+       public String getSearchName() {
+               return searchName;
+       }
+
+       @Override
+       public String toString() {
+               return getSearchName();
+       }
 
 }
index 131c1ae9fd98d89c85d58d7b518d447be84f67e5..a885ba564038fae31afacaf8a5591a335e193ede 100644 (file)
@@ -6,11 +6,11 @@ import java.util.List;
 
 import com.vaadin.data.Item;
 import com.vaadin.data.util.BeanItem;
+import com.vaadin.data.validator.EmailValidator;
+import com.vaadin.data.validator.RegexpValidator;
 import com.vaadin.demo.tutorial.addressbook.AddressBookApplication;
 import com.vaadin.demo.tutorial.addressbook.data.Person;
 import com.vaadin.demo.tutorial.addressbook.data.PersonContainer;
-import com.vaadin.demo.tutorial.addressbook.validators.EmailValidator;
-import com.vaadin.demo.tutorial.addressbook.validators.PostalCodeValidator;
 import com.vaadin.ui.Button;
 import com.vaadin.ui.ComboBox;
 import com.vaadin.ui.Component;
@@ -89,11 +89,14 @@ public class PersonForm extends Form implements ClickListener {
                                        tf.setNullRepresentation("");
 
                                        /* Add a validator for postalCode and make it required */
-                                       tf.addValidator(new PostalCodeValidator());
+                                       tf
+                                                       .addValidator(new RegexpValidator("[1-9][0-9]{4}",
+                                                                       "Postal code must be a five digit number and cannot start with a zero."));
                                        tf.setRequired(true);
                                } else if (propertyId.equals("email")) {
                                        /* Add a validator for email and make it required */
-                                       field.addValidator(new EmailValidator());
+                                       field.addValidator(new EmailValidator(
+                                                       "Email must contain '@' and have full domain."));
                                        field.setRequired(true);
 
                                }
diff --git a/src/com/vaadin/demo/tutorial/addressbook/validators/EmailValidator.java b/src/com/vaadin/demo/tutorial/addressbook/validators/EmailValidator.java
deleted file mode 100644 (file)
index 0c3068d..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-package com.vaadin.demo.tutorial.addressbook.validators;
-
-import com.vaadin.data.Validator;
-
-public class EmailValidator implements Validator {
-
-       public boolean isValid(Object value) {
-               if (value == null || !(value instanceof String)) {
-                       return false;
-               }
-
-               return ((String) value).matches(".+@.+\\..+");
-       }
-
-       public void validate(Object value) throws InvalidValueException {
-               if (!isValid(value)) {
-                       throw new InvalidValueException(
-                                       "Email must contain '@' and have full domain.");
-               }
-       }
-
-}
diff --git a/src/com/vaadin/demo/tutorial/addressbook/validators/PostalCodeValidator.java b/src/com/vaadin/demo/tutorial/addressbook/validators/PostalCodeValidator.java
deleted file mode 100644 (file)
index bd08ab6..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-package com.vaadin.demo.tutorial.addressbook.validators;
-
-import com.vaadin.data.Validator;
-
-public class PostalCodeValidator implements Validator {
-
-       public boolean isValid(Object value) {
-               if (value == null || !(value instanceof String)) {
-                       return false;
-               }
-
-               return ((String) value).matches("[1-9][0-9]{4}");
-       }
-
-       public void validate(Object value) throws InvalidValueException {
-               if (!isValid(value)) {
-                       throw new InvalidValueException(
-                                       "Postal code must be a five digit number and cannot start with a zero.");
-               }
-       }
-
-}
\ No newline at end of file