瀏覽代碼

Create a PopupDateField by default for Dates (#11159)

Change-Id: I505f8afbc12295f07f2fdbffc459e803629790d7
tags/7.1.0.beta1
Artur Signell 11 年之前
父節點
當前提交
87f3fd9cec

+ 2
- 1
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);

+ 69
- 0
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());
}

}

+ 82
- 0
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());
}

}

Loading…
取消
儲存