]> source.dussan.org Git - vaadin-framework.git/commitdiff
removed deprecated field factories from example codes, added licence tags, improved...
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Thu, 14 May 2009 06:18:01 +0000 (06:18 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Thu, 14 May 2009 06:18:01 +0000 (06:18 +0000)
svn changeset:7785/svn branch:6.0

src/com/vaadin/demo/featurebrowser/FormExample.java
src/com/vaadin/demo/sampler/features/form/FormPojoExample.java
src/com/vaadin/demo/tutorial/addressbook/ui/PersonForm.java
src/com/vaadin/ui/AbsoluteLayout.java
src/com/vaadin/ui/DefaultFieldFactory.java
src/com/vaadin/ui/FieldFactory.java
src/com/vaadin/ui/FormFieldFactory.java
src/com/vaadin/ui/TableFieldFactory.java

index 182e6346d1789e6d4225ca38977d2fb2fad2264a..e0888975b57124bc565e3a3b5c021c009738e2ce 100644 (file)
@@ -4,10 +4,10 @@ import com.vaadin.data.Item;
 import com.vaadin.data.Validator;
 import com.vaadin.data.Validator.InvalidValueException;
 import com.vaadin.data.util.BeanItem;
-import com.vaadin.ui.BaseFieldFactory;
 import com.vaadin.ui.Button;
 import com.vaadin.ui.Component;
 import com.vaadin.ui.CustomComponent;
+import com.vaadin.ui.DefaultFieldFactory;
 import com.vaadin.ui.Field;
 import com.vaadin.ui.Form;
 import com.vaadin.ui.HorizontalLayout;
@@ -69,7 +69,7 @@ public class FormExample extends CustomComponent {
 
             // Use custom field factory to modify the defaults on how the
             // components are created
-            setFieldFactory(new MyFieldFactory());
+            setFormFieldFactory(new MyFieldFactory());
 
             // Add Commit and Discard controls to the form.
 
@@ -137,7 +137,7 @@ public class FormExample extends CustomComponent {
      * This is example on how to customize field creation. Any kind of field
      * components could be created on the fly.
      */
-    static class MyFieldFactory extends BaseFieldFactory {
+    static class MyFieldFactory extends DefaultFieldFactory {
 
         @Override
         public Field createField(Item item, Object propertyId,
index e8e0ebb4b2ef02d5f3b8f9a6d6f61aba02c08745..1b29af31f4b817f9f0274766f2da9e913880a6bc 100644 (file)
@@ -10,10 +10,10 @@ import com.vaadin.data.Validator;
 import com.vaadin.data.util.BeanItem;
 import com.vaadin.data.validator.StringLengthValidator;
 import com.vaadin.demo.sampler.ExampleUtil;
-import com.vaadin.ui.BaseFieldFactory;
 import com.vaadin.ui.Button;
 import com.vaadin.ui.ComboBox;
 import com.vaadin.ui.Component;
+import com.vaadin.ui.DefaultFieldFactory;
 import com.vaadin.ui.Field;
 import com.vaadin.ui.Form;
 import com.vaadin.ui.HorizontalLayout;
@@ -39,7 +39,7 @@ public class FormPojoExample extends VerticalLayout {
         personForm.setInvalidCommitted(false); // no invalid values in datamodel
 
         // FieldFactory for customizing the fields and adding validators
-        personForm.setFieldFactory(new PersonFieldFactory());
+        personForm.setFormFieldFactory(new PersonFieldFactory());
         personForm.setItemDataSource(personItem); // bind to POJO via BeanItem
 
         // Determines which properties are shown, and in which order:
@@ -97,7 +97,7 @@ public class FormPojoExample extends VerticalLayout {
         getWindow().showNotification(n);
     }
 
-    private class PersonFieldFactory extends BaseFieldFactory {
+    private class PersonFieldFactory extends DefaultFieldFactory {
 
         final ComboBox countries = new ComboBox("Country");
 
index 212c921ed026faa878d7347fe1311cb23916146c..c15bcd17ba807cbbbbf5a1ce0ccfad4c15be0a01 100644 (file)
@@ -11,10 +11,10 @@ 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.BaseFieldFactory;
 import com.vaadin.ui.Button;
 import com.vaadin.ui.ComboBox;
 import com.vaadin.ui.Component;
+import com.vaadin.ui.DefaultFieldFactory;
 import com.vaadin.ui.Field;
 import com.vaadin.ui.Form;
 import com.vaadin.ui.HorizontalLayout;
@@ -24,153 +24,153 @@ import com.vaadin.ui.Button.ClickListener;
 
 public class PersonForm extends Form implements ClickListener {
 
-       private Button save = new Button("Save", (ClickListener) this);
-       private Button cancel = new Button("Cancel", (ClickListener) this);
-       private Button edit = new Button("Edit", (ClickListener) this);
-       private final ComboBox cities = new ComboBox("City");
-
-       private AddressBookApplication app;
-       private boolean newContactMode = false;
-       private Person newPerson = null;
-
-       public PersonForm(AddressBookApplication app) {
-               this.app = app;
-
-               /*
-                * Enable buffering so that commit() must be called for the form before
-                * input is written to the data. (Form input is not written immediately
-                * through to the underlying object.)
-                */
-               setWriteThrough(false);
-
-               HorizontalLayout footer = new HorizontalLayout();
-               footer.setSpacing(true);
-               footer.addComponent(save);
-               footer.addComponent(cancel);
-               footer.addComponent(edit);
-               footer.setVisible(false);
-
-               setFooter(footer);
-
-               /* Allow the user to enter new cities */
-               cities.setNewItemsAllowed(true);
-               /* We do not want to use null values */
-               cities.setNullSelectionAllowed(false);
-               /* Add an empty city used for selecting no city */
-               cities.addItem("");
-
-               /* Populate cities select using the cities in the data container */
-               PersonContainer ds = app.getDataSource();
-               for (Iterator<Person> it = ds.getItemIds().iterator(); it.hasNext();) {
-                       String city = (it.next()).getCity();
-                       cities.addItem(city);
-               }
-
-               /*
-                * Field factory for overriding how the component for city selection is
-                * created
-                */
-               setFieldFactory(new BaseFieldFactory() {
-                       @Override
-                       public Field createField(Item item, Object propertyId,
-                                       Component uiContext) {
-                               if (propertyId.equals("city")) {
-                                       cities.setWidth("200px");
-                                       return cities;
-                               }
-
-                               Field field = super.createField(item, propertyId, uiContext);
-                               if (propertyId.equals("postalCode")) {
-                                       TextField tf = (TextField) field;
-                                       /*
-                                        * We do not want to display "null" to the user when the
-                                        * field is empty
-                                        */
-                                       tf.setNullRepresentation("");
-
-                                       /* Add a validator for postalCode and make it required */
-                                       tf.addValidator(new PostalCodeValidator());
-                                       tf.setRequired(true);
-                               } else if (propertyId.equals("email")) {
-                                       /* Add a validator for email and make it required */
-                                       field.addValidator(new EmailValidator());
-                                       field.setRequired(true);
-
-                               }
-
-                               field.setWidth("200px");
-                               return field;
-                       }
-               });
-       }
-
-       public void buttonClick(ClickEvent event) {
-               Button source = event.getButton();
-
-               if (source == save) {
-                       /* If the given input is not valid there is no point in continuing */
-                       if (!isValid()) {
-                               return;
-                       }
-
-                       commit();
-                       if (newContactMode) {
-                               /* We need to add the new person to the container */
-                               Item addedItem = app.getDataSource().addItem(newPerson);
-                               /*
-                                * We must update the form to use the Item from our datasource
-                                * as we are now in edit mode (no longer in add mode)
-                                */
-                               setItemDataSource(addedItem);
-
-                               newContactMode = false;
-                       }
-                       setReadOnly(true);
-               } else if (source == cancel) {
-                       if (newContactMode) {
-                               newContactMode = false;
-                               /* Clear the form and make it invisible */
-                               setItemDataSource(null);
-                       } else {
-                               discard();
-                       }
-                       setReadOnly(true);
-               } else if (source == edit) {
-                       setReadOnly(false);
-               }
-       }
-
-       @Override
-       public void setItemDataSource(Item newDataSource) {
-               newContactMode = false;
-
-               if (newDataSource != null) {
-                       List<Object> orderedProperties = Arrays
-                                       .asList(PersonContainer.NATURAL_COL_ORDER);
-                       super.setItemDataSource(newDataSource, orderedProperties);
-
-                       setReadOnly(true);
-                       getFooter().setVisible(true);
-               } else {
-                       super.setItemDataSource(null);
-                       getFooter().setVisible(false);
-               }
-       }
-
-       @Override
-       public void setReadOnly(boolean readOnly) {
-               super.setReadOnly(readOnly);
-               save.setVisible(!readOnly);
-               cancel.setVisible(!readOnly);
-               edit.setVisible(readOnly);
-       }
-
-       public void addContact() {
-               // Create a temporary item for the form
-               newPerson = new Person();
-               setItemDataSource(new BeanItem(newPerson));
-               newContactMode = true;
-               setReadOnly(false);
-       }
+    private Button save = new Button("Save", (ClickListener) this);
+    private Button cancel = new Button("Cancel", (ClickListener) this);
+    private Button edit = new Button("Edit", (ClickListener) this);
+    private final ComboBox cities = new ComboBox("City");
+
+    private AddressBookApplication app;
+    private boolean newContactMode = false;
+    private Person newPerson = null;
+
+    public PersonForm(AddressBookApplication app) {
+        this.app = app;
+
+        /*
+         * Enable buffering so that commit() must be called for the form before
+         * input is written to the data. (Form input is not written immediately
+         * through to the underlying object.)
+         */
+        setWriteThrough(false);
+
+        HorizontalLayout footer = new HorizontalLayout();
+        footer.setSpacing(true);
+        footer.addComponent(save);
+        footer.addComponent(cancel);
+        footer.addComponent(edit);
+        footer.setVisible(false);
+
+        setFooter(footer);
+
+        /* Allow the user to enter new cities */
+        cities.setNewItemsAllowed(true);
+        /* We do not want to use null values */
+        cities.setNullSelectionAllowed(false);
+        /* Add an empty city used for selecting no city */
+        cities.addItem("");
+
+        /* Populate cities select using the cities in the data container */
+        PersonContainer ds = app.getDataSource();
+        for (Iterator<Person> it = ds.getItemIds().iterator(); it.hasNext();) {
+            String city = (it.next()).getCity();
+            cities.addItem(city);
+        }
+
+        /*
+         * Field factory for overriding how the component for city selection is
+         * created
+         */
+        setFormFieldFactory(new DefaultFieldFactory() {
+            @Override
+            public Field createField(Item item, Object propertyId,
+                    Component uiContext) {
+                if (propertyId.equals("city")) {
+                    cities.setWidth("200px");
+                    return cities;
+                }
+
+                Field field = super.createField(item, propertyId, uiContext);
+                if (propertyId.equals("postalCode")) {
+                    TextField tf = (TextField) field;
+                    /*
+                     * We do not want to display "null" to the user when the
+                     * field is empty
+                     */
+                    tf.setNullRepresentation("");
+
+                    /* Add a validator for postalCode and make it required */
+                    tf.addValidator(new PostalCodeValidator());
+                    tf.setRequired(true);
+                } else if (propertyId.equals("email")) {
+                    /* Add a validator for email and make it required */
+                    field.addValidator(new EmailValidator());
+                    field.setRequired(true);
+
+                }
+
+                field.setWidth("200px");
+                return field;
+            }
+        });
+    }
+
+    public void buttonClick(ClickEvent event) {
+        Button source = event.getButton();
+
+        if (source == save) {
+            /* If the given input is not valid there is no point in continuing */
+            if (!isValid()) {
+                return;
+            }
+
+            commit();
+            if (newContactMode) {
+                /* We need to add the new person to the container */
+                Item addedItem = app.getDataSource().addItem(newPerson);
+                /*
+                 * We must update the form to use the Item from our datasource
+                 * as we are now in edit mode (no longer in add mode)
+                 */
+                setItemDataSource(addedItem);
+
+                newContactMode = false;
+            }
+            setReadOnly(true);
+        } else if (source == cancel) {
+            if (newContactMode) {
+                newContactMode = false;
+                /* Clear the form and make it invisible */
+                setItemDataSource(null);
+            } else {
+                discard();
+            }
+            setReadOnly(true);
+        } else if (source == edit) {
+            setReadOnly(false);
+        }
+    }
+
+    @Override
+    public void setItemDataSource(Item newDataSource) {
+        newContactMode = false;
+
+        if (newDataSource != null) {
+            List<Object> orderedProperties = Arrays
+                    .asList(PersonContainer.NATURAL_COL_ORDER);
+            super.setItemDataSource(newDataSource, orderedProperties);
+
+            setReadOnly(true);
+            getFooter().setVisible(true);
+        } else {
+            super.setItemDataSource(null);
+            getFooter().setVisible(false);
+        }
+    }
+
+    @Override
+    public void setReadOnly(boolean readOnly) {
+        super.setReadOnly(readOnly);
+        save.setVisible(!readOnly);
+        cancel.setVisible(!readOnly);
+        edit.setVisible(readOnly);
+    }
+
+    public void addContact() {
+        // Create a temporary item for the form
+        newPerson = new Person();
+        setItemDataSource(new BeanItem(newPerson));
+        newContactMode = true;
+        setReadOnly(false);
+    }
 
 }
\ No newline at end of file
index 0852d7bc50c9143cc6a32257595a8bb74d719e19..d9f40d7253e598cd9e1e1e400e0ee958c70dec5b 100644 (file)
@@ -1,3 +1,6 @@
+/* 
+@ITMillApache2LicenseForJavaFiles@
+ */
 package com.vaadin.ui;
 
 import java.io.Serializable;
index 048034a7a9bc90f34457c31225400069822a2b0f..aa8bd794f64af5fae8239da714f0b3ab7fd644a7 100644 (file)
@@ -1,3 +1,6 @@
+/* 
+@ITMillApache2LicenseForJavaFiles@
+ */
 package com.vaadin.ui;
 
 import java.util.Date;
@@ -7,7 +10,7 @@ import com.vaadin.data.Item;
 import com.vaadin.data.Property;
 
 /**
- * This class contains basic implementation for both {@link FormFieldFactory}
+ * This class contains basic implementation for both {@link FormFieldFactory}
  * and {@link TableFieldFactory}. The class is singleton, use {@link #get()}
  * method to get reference to the instance.
  * 
index 5b0218ac0538bbfb1eb4010c3337d910edeef351..0bdd30612f1ceb298336f22c2205d20f349b3c07 100644 (file)
@@ -14,7 +14,8 @@ import com.vaadin.data.Property;
  * @version
  * @VERSION@
  * @since 3.1
- * @deprecated use FormFieldFactory or TableFieldFactory or both instead
+ * @deprecated FieldFactory was split into two lighter interfaces in 6.0 Use
+ *             FormFieldFactory or TableFieldFactory or both instead.
  */
 @Deprecated
 public interface FieldFactory extends FormFieldFactory, TableFieldFactory {
index fafe9caac71cf6457063c11280b90917a3c8f20c..a0dac130f8d80f2947f3e383c302b85d7102c89b 100644 (file)
@@ -1,13 +1,30 @@
+/* 
+@ITMillApache2LicenseForJavaFiles@
+ */
 package com.vaadin.ui;
 
 import java.io.Serializable;
 
 import com.vaadin.data.Item;
 
+/**
+ * Factory interface for creating new Field-instances based on {@link Item},
+ * property id and uiContext (the component responsible for displaying fields).
+ * Currently this interface is used by {@link Form}, but might later be used by
+ * some other components for {@link Field} generation.
+ * 
+ * <p>
+ * 
+ * @author IT Mill Ltd.
+ * @version
+ * @VERSION@
+ * @since 6.0
+ * @see TableFieldFactory
+ */
 public interface FormFieldFactory extends Serializable {
     /**
-     * Creates a field based on the item, property id and the component where
-     * the Field will be placed in.
+     * Creates a field based on the item, property id and the component (most
+     * commonly {@link Form}) where the Field will be presented.
      * 
      * @param item
      *            the item where the property belongs to.
index 5acd6869ba2f9f47752153df871f5b124b725d01..1b876ef863fc28522496214b0a1af2bca178cbe3 100644 (file)
@@ -1,12 +1,32 @@
+/* 
+@ITMillApache2LicenseForJavaFiles@
+ */
 package com.vaadin.ui;
 
 import java.io.Serializable;
 
 import com.vaadin.data.Container;
 
+/**
+ * Factory interface for creating new Field-instances based on Container
+ * (datasource), item id, property id and uiContext (the component responsible
+ * for displaying fields). Currently this interface is used by {@link Table},
+ * but might later be used by some other components for {@link Field}
+ * generation.
+ * 
+ * <p>
+ * 
+ * @author IT Mill Ltd.
+ * @version
+ * @VERSION@
+ * @since 6.0
+ * @see FormFieldFactory
+ */
 public interface TableFieldFactory extends Serializable {
     /**
-     * Creates a field based on the container item id and property id.
+     * Creates a field based on the Container, item id, property id and the
+     * component responsible for displaying the field (most commonly
+     * {@link Table}).
      * 
      * @param container
      *            the Container where the property belongs to.
@@ -16,7 +36,7 @@ public interface TableFieldFactory extends Serializable {
      *            the Id of the property.
      * @param uiContext
      *            the component where the field is presented.
-     * @return Field the field suitable for editing the specified data.
+     * @return A field suitable for editing the specified data.
      */
     Field createField(Container container, Object itemId, Object propertyId,
             Component uiContext);