diff options
author | Johannes Dahlström <johannesd@vaadin.com> | 2015-06-01 17:09:04 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2015-06-03 13:53:22 +0000 |
commit | 8da6cbdd0268214dbcf9cf05eb052e6d02c13c94 (patch) | |
tree | 2d1aea096d5e2b0a67f0e28405f22092b6fb768c /uitest | |
parent | df0a4ae5bc6f5588827ca877175aaaf33b4671bd (diff) | |
download | vaadin-framework-8da6cbdd0268214dbcf9cf05eb052e6d02c13c94.tar.gz vaadin-framework-8da6cbdd0268214dbcf9cf05eb052e6d02c13c94.zip |
Allow arbitrary serializable types as Renderer data type (#15410)
Change-Id: If535c5603116be204e11936f9186ce3856b74b03
Diffstat (limited to 'uitest')
6 files changed, 90 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/components/grid/BeanRenderer.java b/uitest/src/com/vaadin/tests/components/grid/BeanRenderer.java new file mode 100644 index 0000000000..3e25f45283 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/BeanRenderer.java @@ -0,0 +1,25 @@ +/* + * Copyright 2000-2014 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.tests.components.grid; + +import com.vaadin.tests.widgetset.client.SimpleTestBean; +import com.vaadin.ui.Grid.AbstractRenderer; + +public class BeanRenderer extends AbstractRenderer<SimpleTestBean> { + public BeanRenderer() { + super(SimpleTestBean.class, ""); + } +} diff --git a/uitest/src/com/vaadin/tests/components/grid/CustomRenderer.java b/uitest/src/com/vaadin/tests/components/grid/CustomRenderer.java index f7d14bbff6..171d3f2a5e 100644 --- a/uitest/src/com/vaadin/tests/components/grid/CustomRenderer.java +++ b/uitest/src/com/vaadin/tests/components/grid/CustomRenderer.java @@ -22,6 +22,7 @@ import com.vaadin.data.util.IndexedContainer; import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.AbstractTestUI; import com.vaadin.tests.widgetset.TestingWidgetSet; +import com.vaadin.tests.widgetset.client.SimpleTestBean; import com.vaadin.ui.Grid; import com.vaadin.ui.Grid.SelectionMode; import com.vaadin.ui.Label; @@ -31,6 +32,7 @@ public class CustomRenderer extends AbstractTestUI { private static final Object INT_ARRAY_PROPERTY = "int array"; private static final Object VOID_PROPERTY = "void"; + private static final Object BEAN_PROPERTY = "pojo"; static final Object ITEM_ID = "itemId1"; static final String DEBUG_LABEL_ID = "debuglabel"; @@ -42,6 +44,8 @@ public class CustomRenderer extends AbstractTestUI { container.addContainerProperty(INT_ARRAY_PROPERTY, int[].class, new int[] {}); container.addContainerProperty(VOID_PROPERTY, Void.class, null); + container.addContainerProperty(BEAN_PROPERTY, SimpleTestBean.class, + null); Item item = container.addItem(ITEM_ID); @@ -50,14 +54,25 @@ public class CustomRenderer extends AbstractTestUI { .getItemProperty(INT_ARRAY_PROPERTY); propertyIntArray.setValue(new int[] { 1, 1, 2, 3, 5, 8, 13 }); + @SuppressWarnings("unchecked") + Property<SimpleTestBean> propertyPojo = item + .getItemProperty(BEAN_PROPERTY); + SimpleTestBean bean = new SimpleTestBean(); + bean.setValue(42); + propertyPojo.setValue(bean); + Label debugLabel = new Label(INIT_DEBUG_LABEL_CAPTION); debugLabel.setId(DEBUG_LABEL_ID); Grid grid = new Grid(container); + grid.getColumn(INT_ARRAY_PROPERTY).setRenderer(new IntArrayRenderer()); grid.getColumn(VOID_PROPERTY).setRenderer( new RowAwareRenderer(debugLabel)); + grid.getColumn(BEAN_PROPERTY).setRenderer(new BeanRenderer()); + grid.setSelectionMode(SelectionMode.NONE); + addComponent(grid); addComponent(debugLabel); } diff --git a/uitest/src/com/vaadin/tests/components/grid/CustomRendererTest.java b/uitest/src/com/vaadin/tests/components/grid/CustomRendererTest.java index b17416df2a..7d706ecd30 100644 --- a/uitest/src/com/vaadin/tests/components/grid/CustomRendererTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/CustomRendererTest.java @@ -52,6 +52,13 @@ public class CustomRendererTest extends MultiBrowserTest { findDebugLabel().getText()); } + @Test + public void testBeanRenderer() throws Exception { + openTestURL(); + + assertEquals("SimpleTestBean(42)", findGrid().getCell(0, 2).getText()); + } + private GridElement findGrid() { List<GridElement> elements = $(GridElement.class).all(); return elements.get(0); diff --git a/uitest/src/com/vaadin/tests/serialization/EncodeResultDisplayTest.java b/uitest/src/com/vaadin/tests/serialization/EncodeResultDisplayTest.java index dc69114f8e..662a033745 100644 --- a/uitest/src/com/vaadin/tests/serialization/EncodeResultDisplayTest.java +++ b/uitest/src/com/vaadin/tests/serialization/EncodeResultDisplayTest.java @@ -27,6 +27,7 @@ public class EncodeResultDisplayTest extends SingleBrowserTest { int logRow = 0; + Assert.assertEquals("Void: null", getLogRow(logRow++)); Assert.assertEquals("SimpleTestBean: {\"value\":5}", getLogRow(logRow++)); Assert.assertEquals("List: [\"Three\",\"Four\"]", getLogRow(logRow++)); diff --git a/uitest/src/com/vaadin/tests/widgetset/client/EncoderResultDisplayConnector.java b/uitest/src/com/vaadin/tests/widgetset/client/EncoderResultDisplayConnector.java index 8cc22de900..f2e9710404 100644 --- a/uitest/src/com/vaadin/tests/widgetset/client/EncoderResultDisplayConnector.java +++ b/uitest/src/com/vaadin/tests/widgetset/client/EncoderResultDisplayConnector.java @@ -57,6 +57,9 @@ public class EncoderResultDisplayConnector extends AbstractExtensionConnector { new Type(List.class.getName(), new Type[] { TypeData .getType(String.class) })); reportEncode(new SimpleTestBean(5)); + + reportEncode(Void.class.getSimpleName(), null, + TypeData.getType(Void.class)); } private void reportEncode(Object value) { diff --git a/uitest/src/com/vaadin/tests/widgetset/client/grid/PojoRendererConnector.java b/uitest/src/com/vaadin/tests/widgetset/client/grid/PojoRendererConnector.java new file mode 100644 index 0000000000..04dd08d274 --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/client/grid/PojoRendererConnector.java @@ -0,0 +1,39 @@ +/* + * Copyright 2000-2014 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.tests.widgetset.client.grid; + +import com.vaadin.client.connectors.AbstractRendererConnector; +import com.vaadin.client.renderers.Renderer; +import com.vaadin.client.widget.grid.RendererCellReference; +import com.vaadin.shared.ui.Connect; +import com.vaadin.tests.widgetset.client.SimpleTestBean; + +@Connect(com.vaadin.tests.components.grid.BeanRenderer.class) +public class PojoRendererConnector extends + AbstractRendererConnector<SimpleTestBean> { + + public static class BeanRenderer implements Renderer<SimpleTestBean> { + @Override + public void render(RendererCellReference cell, SimpleTestBean bean) { + cell.getElement().setInnerText(bean.toString()); + } + } + + @Override + public BeanRenderer getRenderer() { + return (BeanRenderer) super.getRenderer(); + } +} |