aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2013-03-15 10:07:08 +0200
committerVaadin Code Review <review@vaadin.com>2013-03-18 12:31:26 +0000
commit87f3fd9cec9d0e8641261b13728c1a20206242fc (patch)
treeb2efd4824af4caed693b1f782c31b13a2a87e971
parent331b3c446e73fafea1e1699fe3dfc44dc8023ae5 (diff)
downloadvaadin-framework-87f3fd9cec9d0e8641261b13728c1a20206242fc.tar.gz
vaadin-framework-87f3fd9cec9d0e8641261b13728c1a20206242fc.zip
Create a PopupDateField by default for Dates (#11159)
Change-Id: I505f8afbc12295f07f2fdbffc459e803629790d7
-rw-r--r--server/src/com/vaadin/data/fieldgroup/DefaultFieldGroupFieldFactory.java3
-rw-r--r--server/tests/src/com/vaadin/data/DefaultFieldGroupFieldFactoryTest.java69
-rw-r--r--server/tests/src/com/vaadin/data/fieldgroup/FieldGroupDate.java82
3 files changed, 153 insertions, 1 deletions
diff --git a/server/src/com/vaadin/data/fieldgroup/DefaultFieldGroupFieldFactory.java b/server/src/com/vaadin/data/fieldgroup/DefaultFieldGroupFieldFactory.java
index ff6b1d3aee..c1e4b4933e 100644
--- a/server/src/com/vaadin/data/fieldgroup/DefaultFieldGroupFieldFactory.java
+++ b/server/src/com/vaadin/data/fieldgroup/DefaultFieldGroupFieldFactory.java
@@ -83,7 +83,8 @@ public class DefaultFieldGroupFieldFactory implements FieldGroupFieldFactory {
if (InlineDateField.class.isAssignableFrom(fieldType)) {
field = new InlineDateField();
- } else if (DateField.class.isAssignableFrom(fieldType)) {
+ } else if (DateField.class.isAssignableFrom(fieldType)
+ || fieldType == Field.class) {
field = new PopupDateField();
} else if (AbstractTextField.class.isAssignableFrom(fieldType)) {
field = createAbstractTextField((Class<? extends AbstractTextField>) fieldType);
diff --git a/server/tests/src/com/vaadin/data/DefaultFieldGroupFieldFactoryTest.java b/server/tests/src/com/vaadin/data/DefaultFieldGroupFieldFactoryTest.java
new file mode 100644
index 0000000000..b319c13e4e
--- /dev/null
+++ b/server/tests/src/com/vaadin/data/DefaultFieldGroupFieldFactoryTest.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2000-2013 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.data;
+
+import java.util.Date;
+
+import junit.framework.Assert;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.vaadin.data.fieldgroup.DefaultFieldGroupFieldFactory;
+import com.vaadin.ui.DateField;
+import com.vaadin.ui.Field;
+import com.vaadin.ui.InlineDateField;
+import com.vaadin.ui.PopupDateField;
+import com.vaadin.ui.TextField;
+
+public class DefaultFieldGroupFieldFactoryTest {
+
+ private DefaultFieldGroupFieldFactory fieldFactory;
+
+ @Before
+ public void setupFieldFactory() {
+ fieldFactory = new DefaultFieldGroupFieldFactory();
+ }
+
+ @Test
+ public void testDateGenerationForPopupDateField() {
+ Field f = fieldFactory.createField(Date.class, DateField.class);
+ Assert.assertNotNull(f);
+ Assert.assertEquals(PopupDateField.class, f.getClass());
+ }
+
+ @Test
+ public void testDateGenerationForInlineDateField() {
+ Field f = fieldFactory.createField(Date.class, InlineDateField.class);
+ Assert.assertNotNull(f);
+ Assert.assertEquals(InlineDateField.class, f.getClass());
+ }
+
+ @Test
+ public void testDateGenerationForTextField() {
+ Field f = fieldFactory.createField(Date.class, TextField.class);
+ Assert.assertNotNull(f);
+ Assert.assertEquals(TextField.class, f.getClass());
+ }
+
+ @Test
+ public void testDateGenerationForField() {
+ Field f = fieldFactory.createField(Date.class, Field.class);
+ Assert.assertNotNull(f);
+ Assert.assertEquals(PopupDateField.class, f.getClass());
+ }
+
+}
diff --git a/server/tests/src/com/vaadin/data/fieldgroup/FieldGroupDate.java b/server/tests/src/com/vaadin/data/fieldgroup/FieldGroupDate.java
new file mode 100644
index 0000000000..e11b6e50f8
--- /dev/null
+++ b/server/tests/src/com/vaadin/data/fieldgroup/FieldGroupDate.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2000-2013 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.data.fieldgroup;
+
+import java.util.Date;
+
+import junit.framework.Assert;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.vaadin.data.util.BeanItem;
+import com.vaadin.ui.Field;
+import com.vaadin.ui.PopupDateField;
+
+public class FieldGroupDate {
+
+ private FieldGroup fieldGroup;
+
+ public class TestBean {
+ private Date javaDate;
+ private java.sql.Date sqlDate;
+
+ public TestBean(Date javaDate, java.sql.Date sqlDate) {
+ super();
+ this.javaDate = javaDate;
+ this.sqlDate = sqlDate;
+ }
+
+ public java.sql.Date getSqlDate() {
+ return sqlDate;
+ }
+
+ public void setSqlDate(java.sql.Date sqlDate) {
+ this.sqlDate = sqlDate;
+ }
+
+ public Date getJavaDate() {
+ return javaDate;
+ }
+
+ public void setJavaDate(Date date) {
+ javaDate = date;
+ }
+ }
+
+ @SuppressWarnings("deprecation")
+ @Before
+ public void setup() {
+ fieldGroup = new FieldGroup();
+ fieldGroup.setItemDataSource(new BeanItem<TestBean>(new TestBean(
+ new Date(2010, 5, 7), new java.sql.Date(2011, 6, 8))));
+ }
+
+ @Test
+ public void testBuildAndBindDate() {
+ Field f = fieldGroup.buildAndBind("javaDate");
+ Assert.assertNotNull(f);
+ Assert.assertEquals(PopupDateField.class, f.getClass());
+ }
+
+ @Test
+ public void testBuildAndBindSqlDate() {
+ Field f = fieldGroup.buildAndBind("sqlDate");
+ Assert.assertNotNull(f);
+ Assert.assertEquals(PopupDateField.class, f.getClass());
+ }
+
+}