diff options
author | Matti Tahvonen <matti.tahvonen@itmill.com> | 2009-05-14 06:18:01 +0000 |
---|---|---|
committer | Matti Tahvonen <matti.tahvonen@itmill.com> | 2009-05-14 06:18:01 +0000 |
commit | b50c298fc41841dc0df674377caf7386ea9c7c64 (patch) | |
tree | 530fb9fa497d94df8134bcbf5d7bdbf98e8ed84a /src | |
parent | 9d62235e1de6d68b546153db3d01cb8d76e28ad7 (diff) | |
download | vaadin-framework-b50c298fc41841dc0df674377caf7386ea9c7c64.tar.gz vaadin-framework-b50c298fc41841dc0df674377caf7386ea9c7c64.zip |
removed deprecated field factories from example codes, added licence tags, improved javadocs
svn changeset:7785/svn branch:6.0
Diffstat (limited to 'src')
-rw-r--r-- | src/com/vaadin/demo/featurebrowser/FormExample.java | 6 | ||||
-rw-r--r-- | src/com/vaadin/demo/sampler/features/form/FormPojoExample.java | 6 | ||||
-rw-r--r-- | src/com/vaadin/demo/tutorial/addressbook/ui/PersonForm.java | 298 | ||||
-rw-r--r-- | src/com/vaadin/ui/AbsoluteLayout.java | 3 | ||||
-rw-r--r-- | src/com/vaadin/ui/DefaultFieldFactory.java | 5 | ||||
-rw-r--r-- | src/com/vaadin/ui/FieldFactory.java | 3 | ||||
-rw-r--r-- | src/com/vaadin/ui/FormFieldFactory.java | 21 | ||||
-rw-r--r-- | src/com/vaadin/ui/TableFieldFactory.java | 24 |
8 files changed, 205 insertions, 161 deletions
diff --git a/src/com/vaadin/demo/featurebrowser/FormExample.java b/src/com/vaadin/demo/featurebrowser/FormExample.java index 182e6346d1..e0888975b5 100644 --- a/src/com/vaadin/demo/featurebrowser/FormExample.java +++ b/src/com/vaadin/demo/featurebrowser/FormExample.java @@ -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, diff --git a/src/com/vaadin/demo/sampler/features/form/FormPojoExample.java b/src/com/vaadin/demo/sampler/features/form/FormPojoExample.java index e8e0ebb4b2..1b29af31f4 100644 --- a/src/com/vaadin/demo/sampler/features/form/FormPojoExample.java +++ b/src/com/vaadin/demo/sampler/features/form/FormPojoExample.java @@ -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"); diff --git a/src/com/vaadin/demo/tutorial/addressbook/ui/PersonForm.java b/src/com/vaadin/demo/tutorial/addressbook/ui/PersonForm.java index 212c921ed0..c15bcd17ba 100644 --- a/src/com/vaadin/demo/tutorial/addressbook/ui/PersonForm.java +++ b/src/com/vaadin/demo/tutorial/addressbook/ui/PersonForm.java @@ -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 diff --git a/src/com/vaadin/ui/AbsoluteLayout.java b/src/com/vaadin/ui/AbsoluteLayout.java index 0852d7bc50..d9f40d7253 100644 --- a/src/com/vaadin/ui/AbsoluteLayout.java +++ b/src/com/vaadin/ui/AbsoluteLayout.java @@ -1,3 +1,6 @@ +/* +@ITMillApache2LicenseForJavaFiles@ + */ package com.vaadin.ui; import java.io.Serializable; diff --git a/src/com/vaadin/ui/DefaultFieldFactory.java b/src/com/vaadin/ui/DefaultFieldFactory.java index 048034a7a9..aa8bd794f6 100644 --- a/src/com/vaadin/ui/DefaultFieldFactory.java +++ b/src/com/vaadin/ui/DefaultFieldFactory.java @@ -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 a basic implementation for both {@link FormFieldFactory} * and {@link TableFieldFactory}. The class is singleton, use {@link #get()} * method to get reference to the instance. * diff --git a/src/com/vaadin/ui/FieldFactory.java b/src/com/vaadin/ui/FieldFactory.java index 5b0218ac05..0bdd30612f 100644 --- a/src/com/vaadin/ui/FieldFactory.java +++ b/src/com/vaadin/ui/FieldFactory.java @@ -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 { diff --git a/src/com/vaadin/ui/FormFieldFactory.java b/src/com/vaadin/ui/FormFieldFactory.java index fafe9caac7..a0dac130f8 100644 --- a/src/com/vaadin/ui/FormFieldFactory.java +++ b/src/com/vaadin/ui/FormFieldFactory.java @@ -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. diff --git a/src/com/vaadin/ui/TableFieldFactory.java b/src/com/vaadin/ui/TableFieldFactory.java index 5acd6869ba..1b876ef863 100644 --- a/src/com/vaadin/ui/TableFieldFactory.java +++ b/src/com/vaadin/ui/TableFieldFactory.java @@ -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); |