summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2013-02-12 09:15:21 +0200
committerArtur Signell <artur@vaadin.com>2013-02-12 09:15:40 +0200
commit6624c7fedf44b1097eb09f78d016ba471aa3dc12 (patch)
treeb982d5acc71f8f1bb80aabf988bca6aaefdf44de
parent12996f599cf5284b4c2994764e26e700011e1a64 (diff)
downloadvaadin-framework-6624c7fedf44b1097eb09f78d016ba471aa3dc12.tar.gz
vaadin-framework-6624c7fedf44b1097eb09f78d016ba471aa3dc12.zip
Added support for Dates to DefaultFieldGroupFieldFactory (#8539)
Change-Id: I61b45b4bb988878d86a913d383764ce7c17c3bf9
-rw-r--r--server/src/com/vaadin/data/fieldgroup/DefaultFieldGroupFieldFactory.java25
-rw-r--r--uitest/src/com/vaadin/tests/fieldgroup/DateForm.html42
-rw-r--r--uitest/src/com/vaadin/tests/fieldgroup/DateForm.java150
3 files changed, 217 insertions, 0 deletions
diff --git a/server/src/com/vaadin/data/fieldgroup/DefaultFieldGroupFieldFactory.java b/server/src/com/vaadin/data/fieldgroup/DefaultFieldGroupFieldFactory.java
index 9ced6588f5..ff6b1d3aee 100644
--- a/server/src/com/vaadin/data/fieldgroup/DefaultFieldGroupFieldFactory.java
+++ b/server/src/com/vaadin/data/fieldgroup/DefaultFieldGroupFieldFactory.java
@@ -15,18 +15,23 @@
*/
package com.vaadin.data.fieldgroup;
+import java.util.Date;
import java.util.EnumSet;
import com.vaadin.data.Item;
import com.vaadin.data.fieldgroup.FieldGroup.BindException;
+import com.vaadin.ui.AbstractField;
import com.vaadin.ui.AbstractSelect;
import com.vaadin.ui.AbstractTextField;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.ComboBox;
+import com.vaadin.ui.DateField;
import com.vaadin.ui.Field;
+import com.vaadin.ui.InlineDateField;
import com.vaadin.ui.ListSelect;
import com.vaadin.ui.NativeSelect;
import com.vaadin.ui.OptionGroup;
+import com.vaadin.ui.PopupDateField;
import com.vaadin.ui.RichTextArea;
import com.vaadin.ui.Table;
import com.vaadin.ui.TextField;
@@ -39,6 +44,8 @@ public class DefaultFieldGroupFieldFactory implements FieldGroupFieldFactory {
public <T extends Field> T createField(Class<?> type, Class<T> fieldType) {
if (Enum.class.isAssignableFrom(type)) {
return createEnumField(type, fieldType);
+ } else if (Date.class.isAssignableFrom(type)) {
+ return createDateField(type, fieldType);
} else if (Boolean.class.isAssignableFrom(type)
|| boolean.class.isAssignableFrom(type)) {
return createBooleanField(fieldType);
@@ -70,6 +77,24 @@ public class DefaultFieldGroupFieldFactory implements FieldGroupFieldFactory {
return null;
}
+ private <T extends Field> T createDateField(Class<?> type,
+ Class<T> fieldType) {
+ AbstractField field;
+
+ if (InlineDateField.class.isAssignableFrom(fieldType)) {
+ field = new InlineDateField();
+ } else if (DateField.class.isAssignableFrom(fieldType)) {
+ field = new PopupDateField();
+ } else if (AbstractTextField.class.isAssignableFrom(fieldType)) {
+ field = createAbstractTextField((Class<? extends AbstractTextField>) fieldType);
+ } else {
+ return null;
+ }
+
+ field.setImmediate(true);
+ return (T) field;
+ }
+
protected AbstractSelect createCompatibleSelect(
Class<? extends AbstractSelect> fieldType) {
AbstractSelect select;
diff --git a/uitest/src/com/vaadin/tests/fieldgroup/DateForm.html b/uitest/src/com/vaadin/tests/fieldgroup/DateForm.html
new file mode 100644
index 0000000000..f141091805
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/fieldgroup/DateForm.html
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="http://localhost:8888/" />
+<title>New Test</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">New Test</td></tr>
+</thead><tbody>
+<tr>
+ <td>open</td>
+ <td>/run/com.vaadin.tests.fieldgroup.DateForm?restartApplication</td>
+ <td></td>
+</tr>
+<tr>
+ <td>assertValue</td>
+ <td>vaadin=runcomvaadintestsfieldgroupDateForm::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VPopupCalendar[0]#field</td>
+ <td>1/20/84</td>
+</tr>
+<tr>
+ <td>assertValue</td>
+ <td>vaadin=runcomvaadintestsfieldgroupDateForm::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VPopupCalendar[0]#field</td>
+ <td>1/20/84</td>
+</tr>
+<tr>
+ <td>assertCSSClass</td>
+ <td>vaadin=runcomvaadintestsfieldgroupDateForm::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[3]/VDateFieldCalendar[0]/VCalendarPanel[0]#day20</td>
+ <td>v-inline-datefield-calendarpanel-day-selected</td>
+</tr>
+<tr>
+ <td>assertValue</td>
+ <td>vaadin=runcomvaadintestsfieldgroupDateForm::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[4]/VTextField[0]</td>
+ <td>Jan 20, 1984 4:34:49 PM</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
diff --git a/uitest/src/com/vaadin/tests/fieldgroup/DateForm.java b/uitest/src/com/vaadin/tests/fieldgroup/DateForm.java
new file mode 100644
index 0000000000..0d906a086b
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/fieldgroup/DateForm.java
@@ -0,0 +1,150 @@
+package com.vaadin.tests.fieldgroup;
+
+import java.util.Date;
+
+import com.vaadin.data.fieldgroup.BeanFieldGroup;
+import com.vaadin.data.fieldgroup.FieldGroup;
+import com.vaadin.data.fieldgroup.FieldGroup.CommitException;
+import com.vaadin.data.fieldgroup.PropertyId;
+import com.vaadin.data.util.BeanItem;
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.tests.data.bean.Person;
+import com.vaadin.tests.util.Log;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.DateField;
+import com.vaadin.ui.InlineDateField;
+import com.vaadin.ui.Notification;
+import com.vaadin.ui.PopupDateField;
+import com.vaadin.ui.TextField;
+
+public class DateForm extends TestBase {
+
+ private Log log = new Log(5);
+ @PropertyId("date1")
+ private DateField dateField;
+ @PropertyId("date2")
+ private PopupDateField popupDateField;
+ @PropertyId("date3")
+ private InlineDateField inlineDateField;
+ @PropertyId("date4")
+ private TextField textField;
+
+ public static class DateObject {
+ private Date date1, date2, date3, date4;
+
+ public DateObject(Date date1, Date date2, Date date3, Date date4) {
+ super();
+ this.date1 = date1;
+ this.date2 = date2;
+ this.date3 = date3;
+ this.date4 = date4;
+ }
+
+ public Date getDate1() {
+ return date1;
+ }
+
+ public void setDate1(Date date1) {
+ this.date1 = date1;
+ }
+
+ public Date getDate2() {
+ return date2;
+ }
+
+ public void setDate2(Date date2) {
+ this.date2 = date2;
+ }
+
+ public Date getDate3() {
+ return date3;
+ }
+
+ public void setDate3(Date date3) {
+ this.date3 = date3;
+ }
+
+ public Date getDate4() {
+ return date4;
+ }
+
+ public void setDate4(Date date4) {
+ this.date4 = date4;
+ }
+
+ }
+
+ @Override
+ protected void setup() {
+ addComponent(log);
+ final FieldGroup fieldGroup = new BeanFieldGroup<DateObject>(
+ DateObject.class);
+ fieldGroup.setBuffered(true);
+
+ fieldGroup.buildAndBindMemberFields(this);
+ textField.setWidth("20em");
+ addComponent(dateField);
+ addComponent(popupDateField);
+ addComponent(inlineDateField);
+ addComponent(textField);
+
+ Button commitButton = new Button("Commit", new Button.ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ String msg = "Commit succesful";
+ try {
+ fieldGroup.commit();
+ } catch (CommitException e) {
+ msg = "Commit failed: " + e.getMessage();
+ }
+ Notification.show(msg);
+ log.log(msg);
+
+ }
+ });
+ Button discardButton = new Button("Discard",
+ new Button.ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ fieldGroup.discard();
+ log.log("Discarded changes");
+
+ }
+ });
+ Button showBean = new Button("Show bean values",
+ new Button.ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ log.log(getPerson(fieldGroup).toString());
+
+ }
+ });
+ addComponent(commitButton);
+ addComponent(discardButton);
+ addComponent(showBean);
+
+ DateObject d = new DateObject(new Date(443457289789L), new Date(
+ 443457289789L), new Date(443457289789L),
+ new Date(443457289789L));
+ fieldGroup.setItemDataSource(new BeanItem<DateObject>(d));
+ }
+
+ public static Person getPerson(FieldGroup binder) {
+ return ((BeanItem<Person>) binder.getItemDataSource()).getBean();
+ }
+
+ @Override
+ protected String getDescription() {
+ return "Ensure FieldGroupFieldFactory supports Dates";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 8539;
+ }
+
+}