summaryrefslogtreecommitdiffstats
path: root/src/com/vaadin/ui
diff options
context:
space:
mode:
authorMatti Tahvonen <matti.tahvonen@itmill.com>2009-05-11 14:34:10 +0000
committerMatti Tahvonen <matti.tahvonen@itmill.com>2009-05-11 14:34:10 +0000
commit064bc4fe71fa23c9e4a3758e8ff824aeb533686d (patch)
treefb14da2180bfe354ec5acb8cc6a5b19fc4f844b1 /src/com/vaadin/ui
parent64d30355cd9f09ba0faff690fd798abc79533a8e (diff)
downloadvaadin-framework-064bc4fe71fa23c9e4a3758e8ff824aeb533686d.tar.gz
vaadin-framework-064bc4fe71fa23c9e4a3758e8ff824aeb533686d.zip
Split old FieldFactory into two smaller interfaces. #2499
svn changeset:7744/svn branch:6.0
Diffstat (limited to 'src/com/vaadin/ui')
-rw-r--r--src/com/vaadin/ui/BaseFieldFactory.java84
-rw-r--r--src/com/vaadin/ui/DefaultFieldFactory.java138
-rw-r--r--src/com/vaadin/ui/FieldFactory.java37
-rw-r--r--src/com/vaadin/ui/Form.java139
-rw-r--r--src/com/vaadin/ui/FormFieldFactory.java24
-rw-r--r--src/com/vaadin/ui/Table.java53
-rw-r--r--src/com/vaadin/ui/TableFieldFactory.java24
7 files changed, 330 insertions, 169 deletions
diff --git a/src/com/vaadin/ui/BaseFieldFactory.java b/src/com/vaadin/ui/BaseFieldFactory.java
index 66a153a287..ea488bb538 100644
--- a/src/com/vaadin/ui/BaseFieldFactory.java
+++ b/src/com/vaadin/ui/BaseFieldFactory.java
@@ -4,8 +4,6 @@
package com.vaadin.ui;
-import java.util.Date;
-
import com.vaadin.data.Container;
import com.vaadin.data.Item;
import com.vaadin.data.Property;
@@ -23,8 +21,11 @@ import com.vaadin.data.Property;
* @version
* @VERSION@
* @since 3.1
+ * @deprecated use {@link DefaultFieldFactory} or own implementations on
+ * {@link FormFieldFactory} or {@link TableFieldFactory} instead.
*/
+@Deprecated
@SuppressWarnings("serial")
public class BaseFieldFactory implements FieldFactory {
@@ -37,42 +38,16 @@ public class BaseFieldFactory implements FieldFactory {
* @param uiContext
* the context where the Field is presented.
*
- * @see com.vaadin.ui.FieldFactory#createField(Class, Component)
+ * @see com.itmill.toolkit.ui.FieldFactory#createField(Class, Component)
*/
public Field createField(Class type, Component uiContext) {
- // Null typed properties can not be edited
- if (type == null) {
- return null;
- }
-
- // Item field
- if (Item.class.isAssignableFrom(type)) {
- return new Form();
- }
-
- // Date field
- if (Date.class.isAssignableFrom(type)) {
- final DateField df = new DateField();
- df.setResolution(DateField.RESOLUTION_DAY);
- return df;
- }
-
- // Boolean field
- if (Boolean.class.isAssignableFrom(type)) {
- final Button button = new Button();
- button.setSwitchMode(true);
- button.setImmediate(false);
- return button;
- }
-
- // Nested form is used by default
- return new TextField();
+ return DefaultFieldFactory.createFieldByPropertyType(type);
}
/**
* Creates the field based on the datasource property.
*
- * @see com.vaadin.ui.FieldFactory#createField(Property, Component)
+ * @see com.itmill.toolkit.ui.FieldFactory#createField(Property, Component)
*/
public Field createField(Property property, Component uiContext) {
if (property != null) {
@@ -85,7 +60,7 @@ public class BaseFieldFactory implements FieldFactory {
/**
* Creates the field based on the item and property id.
*
- * @see com.vaadin.ui.FieldFactory#createField(Item, Object,
+ * @see com.itmill.toolkit.ui.FieldFactory#createField(Item, Object,
* Component)
*/
public Field createField(Item item, Object propertyId, Component uiContext) {
@@ -93,44 +68,9 @@ public class BaseFieldFactory implements FieldFactory {
final Field f = createField(item.getItemProperty(propertyId),
uiContext);
if (f instanceof AbstractComponent) {
- String name = propertyId.toString();
- if (name.length() > 0) {
-
- // If name follows method naming conventions, convert the
- // name to spaced uppercased text. For example, convert
- // "firstName" to "First Name"
- if (name.indexOf(' ') < 0
- && name.charAt(0) == Character.toLowerCase(name
- .charAt(0))
- && name.charAt(0) != Character.toUpperCase(name
- .charAt(0))) {
- StringBuffer out = new StringBuffer();
- out.append(Character.toUpperCase(name.charAt(0)));
- int i = 1;
-
- while (i < name.length()) {
- int j = i;
- for (; j < name.length(); j++) {
- char c = name.charAt(j);
- if (Character.toLowerCase(c) != c
- && Character.toUpperCase(c) == c) {
- break;
- }
- }
- if (j == name.length()) {
- out.append(name.substring(i));
- } else {
- out.append(name.substring(i, j));
- out.append(" " + name.charAt(j));
- }
- i = j + 1;
- }
-
- name = out.toString();
- }
-
- ((AbstractComponent) f).setCaption(name);
- }
+ String name = DefaultFieldFactory
+ .createCaptionByPropertyId(propertyId);
+ f.setCaption(name);
}
return f;
} else {
@@ -139,8 +79,8 @@ public class BaseFieldFactory implements FieldFactory {
}
/**
- * @see com.vaadin.ui.FieldFactory#createField(com.vaadin.data.Container,
- * java.lang.Object, java.lang.Object, com.vaadin.ui.Component)
+ * @see com.itmill.toolkit.ui.FieldFactory#createField(com.itmill.toolkit.data.Container,
+ * java.lang.Object, java.lang.Object, com.itmill.toolkit.ui.Component)
*/
public Field createField(Container container, Object itemId,
Object propertyId, Component uiContext) {
diff --git a/src/com/vaadin/ui/DefaultFieldFactory.java b/src/com/vaadin/ui/DefaultFieldFactory.java
new file mode 100644
index 0000000000..048034a7a9
--- /dev/null
+++ b/src/com/vaadin/ui/DefaultFieldFactory.java
@@ -0,0 +1,138 @@
+package com.vaadin.ui;
+
+import java.util.Date;
+
+import com.vaadin.data.Container;
+import com.vaadin.data.Item;
+import com.vaadin.data.Property;
+
+/**
+ * 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.
+ *
+ * <p>
+ * There are also some static helper methods available for custom built field
+ * factories.
+ *
+ */
+public class DefaultFieldFactory implements FormFieldFactory, TableFieldFactory {
+
+ private static final DefaultFieldFactory instance = new DefaultFieldFactory();
+
+ /**
+ * Singleton method to get an instance of DefaultFieldFactory.
+ *
+ * @return an instance of DefaultFieldFactory
+ */
+ public static DefaultFieldFactory get() {
+ return instance;
+ }
+
+ protected DefaultFieldFactory() {
+ }
+
+ private static final long serialVersionUID = -8051489865928478009L;
+
+ public Field createField(Item item, Object propertyId, Component uiContext) {
+ Class<?> type = item.getItemProperty(propertyId).getType();
+ Field field = createFieldByPropertyType(type);
+ field.setCaption(createCaptionByPropertyId(propertyId));
+ return field;
+ }
+
+ public Field createField(Container container, Object itemId,
+ Object propertyId, Component uiContext) {
+ Property containerProperty = container.getContainerProperty(itemId,
+ propertyId);
+ Class<?> type = containerProperty.getType();
+ Field field = createFieldByPropertyType(type);
+ field.setCaption(createCaptionByPropertyId(propertyId));
+ return field;
+ }
+
+ /**
+ * If name follows method naming conventions, convert the name to spaced
+ * upper case text. For example, convert "firstName" to "First Name"
+ *
+ * @param propertyId
+ * @return the formatted caption string
+ */
+ public static String createCaptionByPropertyId(Object propertyId) {
+ String name = propertyId.toString();
+ if (name.length() > 0) {
+
+ if (name.indexOf(' ') < 0
+ && name.charAt(0) == Character.toLowerCase(name.charAt(0))
+ && name.charAt(0) != Character.toUpperCase(name.charAt(0))) {
+ StringBuffer out = new StringBuffer();
+ out.append(Character.toUpperCase(name.charAt(0)));
+ int i = 1;
+
+ while (i < name.length()) {
+ int j = i;
+ for (; j < name.length(); j++) {
+ char c = name.charAt(j);
+ if (Character.toLowerCase(c) != c
+ && Character.toUpperCase(c) == c) {
+ break;
+ }
+ }
+ if (j == name.length()) {
+ out.append(name.substring(i));
+ } else {
+ out.append(name.substring(i, j));
+ out.append(" " + name.charAt(j));
+ }
+ i = j + 1;
+ }
+
+ name = out.toString();
+ }
+ }
+ return name;
+ }
+
+ /**
+ * Creates fields based on the property type.
+ * <p>
+ * The default field type is {@link TextField}. Other field types generated
+ * by this method:
+ * <p>
+ * <b>Boolean</b>: {@link CheckBox}.<br/>
+ * <b>Date</b>: {@link DateField}(resolution: day).<br/>
+ * <b>Item</b>: {@link Form}. <br/>
+ * <b>default field type</b>: {@link TextField}.
+ * <p>
+ *
+ * @param type
+ * the type of the property
+ * @return the most suitable generic {@link Field} for given type
+ */
+ public static Field createFieldByPropertyType(Class<?> type) {
+ // Null typed properties can not be edited
+ if (type == null) {
+ return null;
+ }
+
+ // Item field
+ if (Item.class.isAssignableFrom(type)) {
+ return new Form();
+ }
+
+ // Date field
+ if (Date.class.isAssignableFrom(type)) {
+ final DateField df = new DateField();
+ df.setResolution(DateField.RESOLUTION_DAY);
+ return df;
+ }
+
+ // Boolean field
+ if (Boolean.class.isAssignableFrom(type)) {
+ return new CheckBox();
+ }
+
+ return new TextField();
+ }
+
+}
diff --git a/src/com/vaadin/ui/FieldFactory.java b/src/com/vaadin/ui/FieldFactory.java
index f0f96386e3..5b0218ac05 100644
--- a/src/com/vaadin/ui/FieldFactory.java
+++ b/src/com/vaadin/ui/FieldFactory.java
@@ -4,10 +4,6 @@
package com.vaadin.ui;
-import java.io.Serializable;
-
-import com.vaadin.data.Container;
-import com.vaadin.data.Item;
import com.vaadin.data.Property;
/**
@@ -18,8 +14,10 @@ import com.vaadin.data.Property;
* @version
* @VERSION@
* @since 3.1
+ * @deprecated use FormFieldFactory or TableFieldFactory or both instead
*/
-public interface FieldFactory extends Serializable {
+@Deprecated
+public interface FieldFactory extends FormFieldFactory, TableFieldFactory {
/**
* Creates a field based on type of data.
@@ -44,33 +42,4 @@ public interface FieldFactory extends Serializable {
*/
Field createField(Property property, Component uiContext);
- /**
- * Creates a field based on the item and property id.
- *
- * @param item
- * the item where the property belongs to.
- * @param propertyId
- * the Id of the property.
- * @param uiContext
- * the component where the field is presented.
- * @return Field the field suitable for editing the specified data.
- */
- Field createField(Item item, Object propertyId, Component uiContext);
-
- /**
- * Creates a field based on the container item id and property id.
- *
- * @param container
- * the Container where the property belongs to.
- * @param itemId
- * the item Id.
- * @param propertyId
- * the Id of the property.
- * @param uiContext
- * the component where the field is presented.
- * @return Field the field suitable for editing the specified data.
- */
- Field createField(Container container, Object itemId, Object propertyId,
- Component uiContext);
-
} \ No newline at end of file
diff --git a/src/com/vaadin/ui/Form.java b/src/com/vaadin/ui/Form.java
index 3922028af0..a256de6389 100644
--- a/src/com/vaadin/ui/Form.java
+++ b/src/com/vaadin/ui/Form.java
@@ -36,16 +36,16 @@ import com.vaadin.terminal.PaintTarget;
*
* <p>
* <code>Form</code> provides customizable editor for classes implementing
- * {@link com.vaadin.data.Item} interface. Also the form itself
- * implements this interface for easier connectivity to other items. To use the
- * form as editor for an item, just connect the item to form with
+ * {@link com.vaadin.data.Item} interface. Also the form itself implements this
+ * interface for easier connectivity to other items. To use the form as editor
+ * for an item, just connect the item to form with
* {@link Form#setItemDataSource(Item)}. If only a part of the item needs to be
* edited, {@link Form#setItemDataSource(Item,Collection)} can be used instead.
* After the item has been connected to the form, the automatically created
* fields can be customized and new fields can be added. If you need to connect
- * a class that does not implement {@link com.vaadin.data.Item}
- * interface, most properties of any class following bean pattern, can be
- * accessed trough {@link com.vaadin.data.util.BeanItem}.
+ * a class that does not implement {@link com.vaadin.data.Item} interface, most
+ * properties of any class following bean pattern, can be accessed trough
+ * {@link com.vaadin.data.util.BeanItem}.
* </p>
*
* @author IT Mill Ltd.
@@ -72,7 +72,7 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item,
/**
* Ordered list of property ids in this editor.
*/
- private final LinkedList propertyIds = new LinkedList();
+ private final LinkedList<Object> propertyIds = new LinkedList<Object>();
/**
* Current buffered source exception.
@@ -92,25 +92,24 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item,
/**
* Mapping from propertyName to corresponding field.
*/
- private final HashMap fields = new HashMap();
+ private final HashMap<Object, Field> fields = new HashMap<Object, Field>();
/**
* Field factory for this form.
*/
- private FieldFactory fieldFactory;
+ private FormFieldFactory fieldFactory;
/**
* Visible item properties.
*/
- private Collection visibleItemProperties;
+ private Collection<Object> visibleItemProperties;
/**
* Form needs to repaint itself if child fields value changes due possible
* change in form validity.
*/
private final ValueChangeListener fieldValueChangeListener = new ValueChangeListener() {
- public void valueChange(
- com.vaadin.data.Property.ValueChangeEvent event) {
+ public void valueChange(com.vaadin.data.Property.ValueChangeEvent event) {
requestRepaint();
}
};
@@ -149,21 +148,22 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item,
* the layout of the form.
*/
public Form(Layout formLayout) {
- this(formLayout, new BaseFieldFactory());
+ this(formLayout, DefaultFieldFactory.get());
}
/**
- * Contructs a new form with given layout and FieldFactory.
+ * Contructs a new form with given {@link Layout} and
+ * {@link FormFieldFactory}.
*
* @param formLayout
* the layout of the form.
* @param fieldFactory
* the FieldFactory of the form.
*/
- public Form(Layout formLayout, FieldFactory fieldFactory) {
+ public Form(Layout formLayout, FormFieldFactory fieldFactory) {
super();
setLayout(formLayout);
- setFieldFactory(fieldFactory);
+ setFormFieldFactory(fieldFactory);
setValidationVisible(false);
setWidth(100, UNITS_PERCENTAGE);
}
@@ -201,7 +201,7 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item,
// getErrorMessage() recursively instead of validate().
ErrorMessage validationError = null;
if (isValidationVisible()) {
- for (final Iterator i = propertyIds.iterator(); i.hasNext();) {
+ for (final Iterator<Object> i = propertyIds.iterator(); i.hasNext();) {
Object f = fields.get(i.next());
if (f instanceof AbstractComponent) {
AbstractComponent field = (AbstractComponent) f;
@@ -274,7 +274,7 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item,
@Override
public void commit() throws Buffered.SourceException {
- LinkedList problems = null;
+ LinkedList<SourceException> problems = null;
// Only commit on valid state if so requested
if (!isInvalidCommitted() && !isValid()) {
@@ -291,16 +291,16 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item,
}
// Try to commit all
- for (final Iterator i = propertyIds.iterator(); i.hasNext();) {
+ for (final Iterator<Object> i = propertyIds.iterator(); i.hasNext();) {
try {
- final Field f = ((Field) fields.get(i.next()));
+ final Field f = (fields.get(i.next()));
// Commit only non-readonly fields.
if (!f.isReadOnly()) {
f.commit();
}
} catch (final Buffered.SourceException e) {
if (problems == null) {
- problems = new LinkedList();
+ problems = new LinkedList<SourceException>();
}
problems.add(e);
}
@@ -318,8 +318,9 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item,
// Commit problems
final Throwable[] causes = new Throwable[problems.size()];
int index = 0;
- for (final Iterator i = problems.iterator(); i.hasNext();) {
- causes[index++] = (Throwable) i.next();
+ for (final Iterator<SourceException> i = problems.iterator(); i
+ .hasNext();) {
+ causes[index++] = i.next();
}
final Buffered.SourceException e = new Buffered.SourceException(this,
causes);
@@ -335,15 +336,15 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item,
@Override
public void discard() throws Buffered.SourceException {
- LinkedList problems = null;
+ LinkedList<SourceException> problems = null;
// Try to discard all changes
- for (final Iterator i = propertyIds.iterator(); i.hasNext();) {
+ for (final Iterator<Object> i = propertyIds.iterator(); i.hasNext();) {
try {
- ((Field) fields.get(i.next())).discard();
+ (fields.get(i.next())).discard();
} catch (final Buffered.SourceException e) {
if (problems == null) {
- problems = new LinkedList();
+ problems = new LinkedList<SourceException>();
}
problems.add(e);
}
@@ -361,8 +362,9 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item,
// Discards problems occurred
final Throwable[] causes = new Throwable[problems.size()];
int index = 0;
- for (final Iterator i = problems.iterator(); i.hasNext();) {
- causes[index++] = (Throwable) i.next();
+ for (final Iterator<SourceException> i = problems.iterator(); i
+ .hasNext();) {
+ causes[index++] = i.next();
}
final Buffered.SourceException e = new Buffered.SourceException(this,
causes);
@@ -377,8 +379,8 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item,
*/
@Override
public boolean isModified() {
- for (final Iterator i = propertyIds.iterator(); i.hasNext();) {
- final Field f = (Field) fields.get(i.next());
+ for (final Iterator<Object> i = propertyIds.iterator(); i.hasNext();) {
+ final Field f = fields.get(i.next());
if (f != null && f.isModified()) {
return true;
}
@@ -413,8 +415,8 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item,
public void setReadThrough(boolean readThrough) {
if (readThrough != this.readThrough) {
this.readThrough = readThrough;
- for (final Iterator i = propertyIds.iterator(); i.hasNext();) {
- ((Field) fields.get(i.next())).setReadThrough(readThrough);
+ for (final Iterator<Object> i = propertyIds.iterator(); i.hasNext();) {
+ (fields.get(i.next())).setReadThrough(readThrough);
}
}
}
@@ -428,8 +430,8 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item,
InvalidValueException {
if (writeThrough != this.writeThrough) {
this.writeThrough = writeThrough;
- for (final Iterator i = propertyIds.iterator(); i.hasNext();) {
- ((Field) fields.get(i.next())).setWriteThrough(writeThrough);
+ for (final Iterator<Object> i = propertyIds.iterator(); i.hasNext();) {
+ (fields.get(i.next())).setWriteThrough(writeThrough);
}
}
}
@@ -452,7 +454,7 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item,
}
// Gets suitable field
- final Field field = fieldFactory.createField(property, this);
+ final Field field = fieldFactory.createField(this, property, this);
if (field == null) {
return false;
}
@@ -532,7 +534,7 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item,
* @see com.vaadin.data.Item#getItemProperty(Object)
*/
public Property getItemProperty(Object id) {
- final Field field = (Field) fields.get(id);
+ final Field field = fields.get(id);
if (field == null) {
return null;
}
@@ -552,7 +554,7 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item,
* the id of the property.
*/
public Field getField(Object propertyId) {
- return (Field) fields.get(propertyId);
+ return fields.get(propertyId);
}
/* Documented in interface */
@@ -567,7 +569,7 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item,
*/
public boolean removeItemProperty(Object id) {
- final Field field = (Field) fields.get(id);
+ final Field field = fields.get(id);
if (field != null) {
propertyIds.remove(id);
@@ -759,7 +761,7 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item,
}
// Gets the old field
- final Field oldField = (Field) fields.get(propertyId);
+ final Field oldField = fields.get(propertyId);
if (oldField == null) {
throw new IllegalArgumentException("Field with given propertyid '"
+ propertyId.toString() + "' can not be found.");
@@ -876,8 +878,8 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item,
@Override
public boolean isValid() {
boolean valid = true;
- for (final Iterator i = propertyIds.iterator(); i.hasNext();) {
- valid &= ((Field) fields.get(i.next())).isValid();
+ for (final Iterator<Object> i = propertyIds.iterator(); i.hasNext();) {
+ valid &= (fields.get(i.next())).isValid();
}
return valid && super.isValid();
}
@@ -890,8 +892,8 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item,
@Override
public void validate() throws InvalidValueException {
super.validate();
- for (final Iterator i = propertyIds.iterator(); i.hasNext();) {
- ((Field) fields.get(i.next())).validate();
+ for (final Iterator<Object> i = propertyIds.iterator(); i.hasNext();) {
+ (fields.get(i.next())).validate();
}
}
@@ -925,7 +927,7 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item,
public void setReadOnly(boolean readOnly) {
super.setReadOnly(readOnly);
for (final Iterator i = propertyIds.iterator(); i.hasNext();) {
- ((Field) fields.get(i.next())).setReadOnly(readOnly);
+ (fields.get(i.next())).setReadOnly(readOnly);
}
}
@@ -938,19 +940,50 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item,
* @param fieldFactory
* the New factory used to create the fields.
* @see Field
- * @see FieldFactory
+ * @see FormFieldFactory
+ * @deprecated use {@link #setFormFieldFactory(FormFieldFactory)} instead
*/
+ @Deprecated
public void setFieldFactory(FieldFactory fieldFactory) {
this.fieldFactory = fieldFactory;
}
/**
+ * Sets the field factory used by this Form to genarate Fields for
+ * properties.
+ *
+ * {@link FormFieldFactory} is used to create fields for form properties.
+ * {@link DefaultFieldFactory} is used by default.
+ *
+ * @param fieldFactory
+ * the new factory used to create the fields.
+ * @see Field
+ * @see FormFieldFactory
+ */
+ public void setFormFieldFactory(FormFieldFactory fieldFactory) {
+ this.fieldFactory = fieldFactory;
+ }
+
+ /**
+ * Get the field factory of the form.
+ *
+ * @return the FormFieldFactory Factory used to create the fields.
+ */
+ public FormFieldFactory getFormFieldFactory() {
+ return fieldFactory;
+ }
+
+ /**
* Get the field factory of the form.
*
* @return the FieldFactory Factory used to create the fields.
*/
public FieldFactory getFieldFactory() {
- return fieldFactory;
+ if (fieldFactory instanceof FieldFactory) {
+ return (FieldFactory) fieldFactory;
+
+ }
+ return null;
}
/**
@@ -1063,7 +1096,7 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item,
* the visibleProperties to set.
*/
public void setVisibleItemProperties(Object[] visibleProperties) {
- LinkedList v = new LinkedList();
+ LinkedList<Object> v = new LinkedList<Object>();
for (int i = 0; i < visibleProperties.length; i++) {
v.add(visibleProperties[i]);
}
@@ -1103,8 +1136,8 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item,
@Override
public void setImmediate(boolean immediate) {
super.setImmediate(immediate);
- for (Iterator i = fields.values().iterator(); i.hasNext();) {
- Field f = (Field) i.next();
+ for (Iterator<Field> i = fields.values().iterator(); i.hasNext();) {
+ Field f = i.next();
if (f instanceof AbstractComponent) {
((AbstractComponent) f).setImmediate(immediate);
}
@@ -1115,8 +1148,8 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item,
@Override
protected boolean isEmpty() {
- for (Iterator i = fields.values().iterator(); i.hasNext();) {
- Field f = (Field) i.next();
+ for (Iterator<Field> i = fields.values().iterator(); i.hasNext();) {
+ Field f = i.next();
if (f instanceof AbstractField) {
if (!((AbstractField) f).isEmpty()) {
return false;
@@ -1145,7 +1178,7 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item,
*/
public Layout getFooter() {
if (formFooter == null) {
- formFooter = new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL);
+ formFooter = new HorizontalLayout();
formFooter.setParent(this);
}
return formFooter;
diff --git a/src/com/vaadin/ui/FormFieldFactory.java b/src/com/vaadin/ui/FormFieldFactory.java
new file mode 100644
index 0000000000..fafe9caac7
--- /dev/null
+++ b/src/com/vaadin/ui/FormFieldFactory.java
@@ -0,0 +1,24 @@
+package com.vaadin.ui;
+
+import java.io.Serializable;
+
+import com.vaadin.data.Item;
+
+public interface FormFieldFactory extends Serializable {
+ /**
+ * Creates a field based on the item, property id and the component where
+ * the Field will be placed in.
+ *
+ * @param item
+ * the item where the property belongs to.
+ * @param propertyId
+ * the Id of the property.
+ * @param uiContext
+ * the component where the field is presented, most commonly this
+ * is {@link Form}. uiContext will not necessary be the parent
+ * component of the field, but the one that is responsible for
+ * creating it.
+ * @return Field the field suitable for editing the specified data.
+ */
+ Field createField(Item item, Object propertyId, Component uiContext);
+}
diff --git a/src/com/vaadin/ui/Table.java b/src/com/vaadin/ui/Table.java
index 8df31ace01..de1e744da2 100644
--- a/src/com/vaadin/ui/Table.java
+++ b/src/com/vaadin/ui/Table.java
@@ -263,7 +263,7 @@ public class Table extends AbstractSelect implements Action.Container,
/**
* Table cell editor factory.
*/
- private FieldFactory fieldFactory = new BaseFieldFactory();
+ private TableFieldFactory fieldFactory = DefaultFieldFactory.get();
/**
* Is table editable.
@@ -1931,8 +1931,7 @@ public class Table extends AbstractSelect implements Action.Container,
/*
* (non-Javadoc)
*
- * @see
- * com.vaadin.ui.AbstractSelect#paintContent(com.vaadin.
+ * @see com.vaadin.ui.AbstractSelect#paintContent(com.vaadin.
* terminal.PaintTarget)
*/
@Override
@@ -2324,7 +2323,7 @@ public class Table extends AbstractSelect implements Action.Container,
* @param property
* the Property to be presented.
* @return Object Either formatted value or Component for field.
- * @see #setFieldFactory(FieldFactory)
+ * @see #setTableFieldFactory(TableFieldFactory)
*/
protected Object getPropertyValue(Object rowId, Object colId,
Property property) {
@@ -2530,8 +2529,8 @@ public class Table extends AbstractSelect implements Action.Container,
* the class of the property.
* @param defaultValue
* the default value given for all existing items.
- * @see com.vaadin.data.Container#addContainerProperty(Object,
- * Class, Object)
+ * @see com.vaadin.data.Container#addContainerProperty(Object, Class,
+ * Object)
*/
@Override
public boolean addContainerProperty(Object propertyId, Class type,
@@ -2575,8 +2574,8 @@ public class Table extends AbstractSelect implements Action.Container,
* the Alignment of the column. Null implies align left.
* @throws UnsupportedOperationException
* if the operation is not supported.
- * @see com.vaadin.data.Container#addContainerProperty(Object,
- * Class, Object)
+ * @see com.vaadin.data.Container#addContainerProperty(Object, Class,
+ * Object)
*/
public boolean addContainerProperty(Object propertyId, Class type,
Object defaultValue, String columnHeader, Resource columnIcon,
@@ -2837,15 +2836,48 @@ public class Table extends AbstractSelect implements Action.Container,
}
/**
+ * Sets the TableFieldFactory that is used to create editor for table cells.
+ *
+ * The TableFieldFactory is only used if the Table is editable. By default
+ * the DefaultFieldFactory is used.
+ *
+ * @param fieldFactory
+ * the field factory to set.
+ * @see #isEditable
+ * @see DefaultFieldFactory
+ */
+ public void setTableFieldFactory(TableFieldFactory fieldFactory) {
+ this.fieldFactory = fieldFactory;
+ }
+
+ /**
+ * Gets the TableFieldFactory that is used to create editor for table cells.
+ *
+ * The FieldFactory is only used if the Table is editable.
+ *
+ * @return TableFieldFactory used to create the Field instances.
+ * @see #isEditable
+ */
+ public TableFieldFactory getTableFieldFactory() {
+ return fieldFactory;
+ }
+
+ /**
* Gets the FieldFactory that is used to create editor for table cells.
*
* The FieldFactory is only used if the Table is editable.
*
* @return FieldFactory used to create the Field instances.
* @see #isEditable
+ * @deprecated use {@link #getTableFieldFactory()} instead
*/
+ @Deprecated
public FieldFactory getFieldFactory() {
- return fieldFactory;
+ if (fieldFactory instanceof FieldFactory) {
+ return (FieldFactory) fieldFactory;
+
+ }
+ return null;
}
/**
@@ -2858,8 +2890,9 @@ public class Table extends AbstractSelect implements Action.Container,
* the field factory to set.
* @see #isEditable
* @see BaseFieldFactory
- *
+ * @deprecated use {@link #setTableFieldFactory(TableFieldFactory)} instead
*/
+ @Deprecated
public void setFieldFactory(FieldFactory fieldFactory) {
this.fieldFactory = fieldFactory;
diff --git a/src/com/vaadin/ui/TableFieldFactory.java b/src/com/vaadin/ui/TableFieldFactory.java
new file mode 100644
index 0000000000..5acd6869ba
--- /dev/null
+++ b/src/com/vaadin/ui/TableFieldFactory.java
@@ -0,0 +1,24 @@
+package com.vaadin.ui;
+
+import java.io.Serializable;
+
+import com.vaadin.data.Container;
+
+public interface TableFieldFactory extends Serializable {
+ /**
+ * Creates a field based on the container item id and property id.
+ *
+ * @param container
+ * the Container where the property belongs to.
+ * @param itemId
+ * the item Id.
+ * @param propertyId
+ * the Id of the property.
+ * @param uiContext
+ * the component where the field is presented.
+ * @return Field the field suitable for editing the specified data.
+ */
+ Field createField(Container container, Object itemId, Object propertyId,
+ Component uiContext);
+
+}