import com.vaadin.ui.Table;
import com.vaadin.ui.TextField;
+/**
+ * This class contains a basic implementation for {@link FieldGroupFieldFactory}
+ * .The class is singleton, use {@link #get()} method to get reference to the
+ * instance.
+ *
+ * @author Vaadin Ltd
+ */
public class DefaultFieldGroupFieldFactory implements FieldGroupFieldFactory {
+ private static final DefaultFieldGroupFieldFactory INSTANCE = new DefaultFieldGroupFieldFactory();
+
public static final Object CAPTION_PROPERTY_ID = "Caption";
+ protected DefaultFieldGroupFieldFactory() {
+ }
+
+ public static DefaultFieldGroupFieldFactory get() {
+ return INSTANCE;
+ }
+
@Override
public <T extends Field> T createField(Class<?> type, Class<T> fieldType) {
if (Enum.class.isAssignableFrom(type)) {
/**
* The field factory used by builder methods.
*/
- private FieldGroupFieldFactory fieldFactory = new DefaultFieldGroupFieldFactory();
+ private FieldGroupFieldFactory fieldFactory = DefaultFieldGroupFieldFactory
+ .get();
/**
* Constructs a field binder. Use {@link #setItemDataSource(Item)} to set a
*/
package com.vaadin.data;
+import java.lang.reflect.Constructor;
import java.util.Date;
import org.junit.Assert;
@Before
public void setupFieldFactory() {
- fieldFactory = new DefaultFieldGroupFieldFactory();
+ fieldFactory = DefaultFieldGroupFieldFactory.get();
+ }
+
+ @Test
+ public void noPublicConstructor() {
+ Class<DefaultFieldGroupFieldFactory> clazz = DefaultFieldGroupFieldFactory.class;
+ Constructor<?>[] constructors = clazz.getConstructors();
+ Assert.assertEquals(
+ "DefaultFieldGroupFieldFactory contains public constructors",
+ 0, constructors.length);
+ }
+
+ @Test
+ public void testSameInstance() {
+ DefaultFieldGroupFieldFactory factory1 = DefaultFieldGroupFieldFactory
+ .get();
+ DefaultFieldGroupFieldFactory factory2 = DefaultFieldGroupFieldFactory
+ .get();
+ Assert.assertTrue(
+ "DefaultFieldGroupFieldFactory.get() method returns different instances",
+ factory1 == factory2);
+ Assert.assertNotNull(
+ "DefaultFieldGroupFieldFactory.get() method returns null",
+ factory1);
}
@Test