From b5b98e47441aa4ac587de097b22b25cc4852a4ec Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 4 Feb 2015 17:00:23 +0200 Subject: [PATCH] Revert "Grid now uses ObjectRenderer by default (#15417)" This reverts commit abaec0217b3351d6f1835d7095ed2a3958fbfcdb. Change-Id: I7f8de3ee803b6de1957ad04b5b1b3bf210783826 --- .../connectors/ObjectRendererConnector.java | 38 ------------ .../client/renderers/ObjectRenderer.java | 36 ------------ .../src/com/vaadin/client/widgets/Grid.java | 27 ++++----- server/src/com/vaadin/ui/Grid.java | 58 +++++++------------ .../vaadin/ui/renderer/ObjectRenderer.java | 46 --------------- .../tests/server/renderer/RendererTest.java | 25 ++------ .../grid/GridUndefinedObjectConverter.java | 37 ------------ .../GridUndefinedObjectConverterTest.java | 25 -------- 8 files changed, 40 insertions(+), 252 deletions(-) delete mode 100644 client/src/com/vaadin/client/connectors/ObjectRendererConnector.java delete mode 100644 client/src/com/vaadin/client/renderers/ObjectRenderer.java delete mode 100644 server/src/com/vaadin/ui/renderer/ObjectRenderer.java delete mode 100644 uitest/src/com/vaadin/tests/components/grid/GridUndefinedObjectConverter.java delete mode 100644 uitest/src/com/vaadin/tests/components/grid/GridUndefinedObjectConverterTest.java diff --git a/client/src/com/vaadin/client/connectors/ObjectRendererConnector.java b/client/src/com/vaadin/client/connectors/ObjectRendererConnector.java deleted file mode 100644 index 877eaaa569..0000000000 --- a/client/src/com/vaadin/client/connectors/ObjectRendererConnector.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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.client.connectors; - -import com.vaadin.client.renderers.TextRenderer; -import com.vaadin.shared.ui.Connect; - -/** - * A connector for {@link com.vaadin.ui.renderer.ObjectRenderer the server side - * ObjectRenderer}. - *

- * This uses a {@link TextRenderer} to actually render the contents, as the - * object is already converted into a string server-side. - * - * @since - * @author Vaadin Ltd - */ -@Connect(com.vaadin.ui.renderer.ObjectRenderer.class) -public class ObjectRendererConnector extends AbstractRendererConnector { - - @Override - public TextRenderer getRenderer() { - return (TextRenderer) super.getRenderer(); - } -} diff --git a/client/src/com/vaadin/client/renderers/ObjectRenderer.java b/client/src/com/vaadin/client/renderers/ObjectRenderer.java deleted file mode 100644 index a2c4e7bfc6..0000000000 --- a/client/src/com/vaadin/client/renderers/ObjectRenderer.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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.client.renderers; - -import com.vaadin.client.widget.grid.RendererCellReference; - -/** - * A renderer for displaying an object to a string using the - * {@link Object#toString()} method. - *

- * If the object is null, then it is rendered as an empty string - * instead. - * - * @since - * @author Vaadin Ltd - */ -public class ObjectRenderer implements Renderer { - @Override - public void render(RendererCellReference cell, Object data) { - String text = (data != null) ? data.toString() : ""; - cell.getElement().setInnerText(text); - } -} diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java index aee1c1fcc8..a870a732b5 100644 --- a/client/src/com/vaadin/client/widgets/Grid.java +++ b/client/src/com/vaadin/client/widgets/Grid.java @@ -65,7 +65,6 @@ import com.vaadin.client.WidgetUtil; import com.vaadin.client.data.DataChangeHandler; import com.vaadin.client.data.DataSource; import com.vaadin.client.renderers.ComplexRenderer; -import com.vaadin.client.renderers.ObjectRenderer; import com.vaadin.client.renderers.Renderer; import com.vaadin.client.renderers.WidgetRenderer; import com.vaadin.client.ui.SubPartAware; @@ -2693,18 +2692,13 @@ public class Grid extends ResizeComposite implements public static abstract class Column { /** - * The default renderer for grid columns. - *

- * The first time this renderer is called, a warning is displayed, - * informing the developer to use a manually defined renderer for their - * column. + * Default renderer for GridColumns. Renders everything into text + * through {@link Object#toString()}. */ - private final class DefaultObjectRenderer extends ObjectRenderer { + private final class DefaultTextRenderer implements Renderer { boolean warned = false; - private final String DEFAULT_RENDERER_WARNING = "This column uses " - + "a dummy default ObjectRenderer. A more suitable " - + "renderer should be set using the setRenderer() " - + "method."; + private final String DEFAULT_RENDERER_WARNING = "This column uses a dummy default TextRenderer. " + + "A more suitable renderer should be set using the setRenderer() method."; @Override public void render(RendererCellReference cell, Object data) { @@ -2715,7 +2709,14 @@ public class Grid extends ResizeComposite implements warned = true; } - super.render(cell, data); + final String text; + if (data == null) { + text = ""; + } else { + text = data.toString(); + } + + cell.getElement().setInnerText(text); } } @@ -2747,7 +2748,7 @@ public class Grid extends ResizeComposite implements * Constructs a new column with a simple TextRenderer. */ public Column() { - setRenderer(new DefaultObjectRenderer()); + setRenderer(new DefaultTextRenderer()); } /** diff --git a/server/src/com/vaadin/ui/Grid.java b/server/src/com/vaadin/ui/Grid.java index f3c3bfa26b..125cc5a05a 100644 --- a/server/src/com/vaadin/ui/Grid.java +++ b/server/src/com/vaadin/ui/Grid.java @@ -91,8 +91,8 @@ import com.vaadin.shared.ui.grid.HeightMode; import com.vaadin.shared.ui.grid.ScrollDestination; import com.vaadin.shared.util.SharedUtil; import com.vaadin.ui.Notification.Type; -import com.vaadin.ui.renderer.ObjectRenderer; import com.vaadin.ui.renderer.Renderer; +import com.vaadin.ui.renderer.TextRenderer; import com.vaadin.util.ReflectTools; import elemental.json.Json; @@ -1968,25 +1968,7 @@ public class Grid extends AbstractComponent implements SelectionNotifier, this.grid = grid; this.state = state; this.propertyId = propertyId; - - internalSetRenderer(new ObjectRenderer() { - private boolean warned = false; - private final String DEFAULT_RENDERER_WARNING = "This column uses " - + "a dummy default ObjectRenderer. A more suitable " - + "renderer should be set using the setRenderer() " - + "method."; - - @Override - public JsonValue encode(Object value) { - if (!warned && !(value instanceof String)) { - getLogger().warning( - Column.this.toString() + ": " - + DEFAULT_RENDERER_WARNING); - warned = true; - } - return super.encode(value); - } - }); + internalSetRenderer(new TextRenderer()); } /** @@ -2150,13 +2132,13 @@ public class Grid extends AbstractComponent implements SelectionNotifier, * @see #setConverter(Converter) */ public Column setRenderer(Renderer renderer) { - boolean success = internalSetRenderer(renderer); - if (!success) { - throw new IllegalArgumentException("Could not find a " - + "converter for converting from the model type " - + getModelType() + " to the renderer presentation " - + "type " + renderer.getPresentationType() + " (in " - + toString() + ")"); + if (!internalSetRenderer(renderer)) { + throw new IllegalArgumentException( + "Could not find a converter for converting from the model type " + + getModelType() + + " to the renderer presentation type " + + renderer.getPresentationType() + " (in " + + toString() + ")"); } return this; } @@ -2209,19 +2191,20 @@ public class Grid extends AbstractComponent implements SelectionNotifier, Class modelType = getModelType(); if (converter != null) { if (!converter.getModelType().isAssignableFrom(modelType)) { - throw new IllegalArgumentException("The converter model " - + "type " + converter.getModelType() + " is not " - + "compatible with the property type " + modelType - + " (in " + toString() + ")"); + throw new IllegalArgumentException( + "The converter model type " + + converter.getModelType() + + " is not compatible with the property type " + + modelType + " (in " + toString() + ")"); } else if (!getRenderer().getPresentationType() .isAssignableFrom(converter.getPresentationType())) { - throw new IllegalArgumentException("The converter " - + "presentation type " - + converter.getPresentationType() + " is not " - + "compatible with the renderer presentation " - + "type " + getRenderer().getPresentationType() - + " (in " + toString() + ")"); + throw new IllegalArgumentException( + "The converter presentation type " + + converter.getPresentationType() + + " is not compatible with the renderer presentation type " + + getRenderer().getPresentationType() + + " (in " + toString() + ")"); } } @@ -2281,7 +2264,6 @@ public class Grid extends AbstractComponent implements SelectionNotifier, return converter; } - @SuppressWarnings("unchecked") private boolean internalSetRenderer(Renderer renderer) { Converter converter; diff --git a/server/src/com/vaadin/ui/renderer/ObjectRenderer.java b/server/src/com/vaadin/ui/renderer/ObjectRenderer.java deleted file mode 100644 index 9f8b44162c..0000000000 --- a/server/src/com/vaadin/ui/renderer/ObjectRenderer.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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.ui.renderer; - -import com.vaadin.ui.Grid.AbstractRenderer; - -import elemental.json.JsonValue; - -/** - * A renderer for displaying an object to a string using the - * {@link Object#toString()} method. - *

- * If the object is null, then it is rendered as an empty string - * instead. - * - * @since - * @author Vaadin Ltd - */ -public class ObjectRenderer extends AbstractRenderer { - - /** - * Creates a new toString renderer. - */ - public ObjectRenderer() { - super(Object.class); - } - - @Override - public JsonValue encode(Object value) { - String text = (value != null) ? value.toString() : ""; - return super.encode(text); - } -} diff --git a/server/tests/src/com/vaadin/tests/server/renderer/RendererTest.java b/server/tests/src/com/vaadin/tests/server/renderer/RendererTest.java index 767c72f5d9..464d409543 100644 --- a/server/tests/src/com/vaadin/tests/server/renderer/RendererTest.java +++ b/server/tests/src/com/vaadin/tests/server/renderer/RendererTest.java @@ -18,7 +18,6 @@ package com.vaadin.tests.server.renderer; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; import java.util.Locale; @@ -37,7 +36,6 @@ import com.vaadin.ui.ConnectorTracker; import com.vaadin.ui.Grid; import com.vaadin.ui.Grid.Column; import com.vaadin.ui.UI; -import com.vaadin.ui.renderer.ObjectRenderer; import com.vaadin.ui.renderer.TextRenderer; import elemental.json.JsonValue; @@ -46,11 +44,6 @@ public class RendererTest { private static class TestBean { int i = 42; - - @Override - public String toString() { - return "TestBean [" + i + "]"; - } } private static class ExtendedBean extends TestBean { @@ -137,16 +130,15 @@ public class RendererTest { @Test public void testDefaultRendererAndConverter() throws Exception { - assertTrue("Foo default renderer should be a type of ObjectRenderer", - foo.getRenderer() instanceof ObjectRenderer); + assertSame(TextRenderer.class, foo.getRenderer().getClass()); + assertSame(StringToIntegerConverter.class, foo.getConverter() + .getClass()); - assertTrue("Bar default renderer should be a type of ObjectRenderer", - bar.getRenderer() instanceof ObjectRenderer); + assertSame(TextRenderer.class, bar.getRenderer().getClass()); // String->String; converter not needed assertNull(bar.getConverter()); - assertTrue("Baz default renderer should be a type of ObjectRenderer", - baz.getRenderer() instanceof ObjectRenderer); + assertSame(TextRenderer.class, baz.getRenderer().getClass()); // MyBean->String; converter not found assertNull(baz.getConverter()); } @@ -174,11 +166,6 @@ public class RendererTest { @Test public void testEncoding() throws Exception { - /* - * For some strange reason, this test seems to fail locally, but not on - * TeamCity. - */ - assertEquals("42", render(foo, 42).asString()); foo.setRenderer(renderer()); assertEquals("renderer(42)", render(foo, 42).asString()); @@ -190,7 +177,7 @@ public class RendererTest { @Test public void testEncodingWithoutConverter() throws Exception { - assertEquals("TestBean [42]", render(baz, new TestBean()).asString()); + assertEquals("", render(baz, new TestBean()).asString()); } @Test diff --git a/uitest/src/com/vaadin/tests/components/grid/GridUndefinedObjectConverter.java b/uitest/src/com/vaadin/tests/components/grid/GridUndefinedObjectConverter.java deleted file mode 100644 index fba2bbf698..0000000000 --- a/uitest/src/com/vaadin/tests/components/grid/GridUndefinedObjectConverter.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.vaadin.tests.components.grid; - -import com.vaadin.data.util.IndexedContainer; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.Grid; - -public class GridUndefinedObjectConverter extends AbstractTestUI { - private static class Pojo { - private final String content; - - public Pojo(String content) { - this.content = content; - } - - @Override - public String toString() { - return "Pojo:" + content; - } - } - - @Override - @SuppressWarnings("all") - protected void setup(VaadinRequest request) { - IndexedContainer container = new IndexedContainer(); - container.addContainerProperty("pojo", Pojo.class, new Pojo("foo")); - container.addContainerProperty("pojo object ", Object.class, new Pojo( - "bar")); - container.addContainerProperty("int", Integer.class, 1); - container.addContainerProperty("int object", Object.class, 2); - container.addContainerProperty("string", String.class, "foo"); - container.addContainerProperty("string object", Object.class, "bar"); - container.addItem(); - - addComponent(new Grid(container)); - } -} diff --git a/uitest/src/com/vaadin/tests/components/grid/GridUndefinedObjectConverterTest.java b/uitest/src/com/vaadin/tests/components/grid/GridUndefinedObjectConverterTest.java deleted file mode 100644 index 401bfda885..0000000000 --- a/uitest/src/com/vaadin/tests/components/grid/GridUndefinedObjectConverterTest.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.vaadin.tests.components.grid; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -import com.vaadin.testbench.elements.GridElement; -import com.vaadin.tests.annotations.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; - -@TestCategory("grid") -public class GridUndefinedObjectConverterTest extends MultiBrowserTest { - @Test - public void testDefaultToStringRendering() { - openTestURL(); - - GridElement grid = $(GridElement.class).first(); - assertEquals("pojo", "Pojo:foo", grid.getCell(0, 0).getText()); - assertEquals("pojo object", "Pojo:bar", grid.getCell(0, 1).getText()); - assertEquals("int", "1", grid.getCell(0, 2).getText()); - assertEquals("int object", "2", grid.getCell(0, 3).getText()); - assertEquals("string", "foo", grid.getCell(0, 4).getText()); - assertEquals("string object", "bar", grid.getCell(0, 5).getText()); - } -} -- 2.39.5