summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2015-02-04 17:00:23 +0200
committerVaadin Code Review <review@vaadin.com>2015-02-05 12:27:27 +0000
commitb5b98e47441aa4ac587de097b22b25cc4852a4ec (patch)
treee32e7d71a2b1c2cf90d9810b075cb87cb112cdde /server
parentb66c005a16b8141c14d50c2f1bed5a694e5c92c3 (diff)
downloadvaadin-framework-b5b98e47441aa4ac587de097b22b25cc4852a4ec.tar.gz
vaadin-framework-b5b98e47441aa4ac587de097b22b25cc4852a4ec.zip
Revert "Grid now uses ObjectRenderer by default (#15417)"
This reverts commit abaec0217b3351d6f1835d7095ed2a3958fbfcdb. Change-Id: I7f8de3ee803b6de1957ad04b5b1b3bf210783826
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/ui/Grid.java58
-rw-r--r--server/src/com/vaadin/ui/renderer/ObjectRenderer.java46
-rw-r--r--server/tests/src/com/vaadin/tests/server/renderer/RendererTest.java25
3 files changed, 26 insertions, 103 deletions
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 <T> boolean internalSetRenderer(Renderer<T> renderer) {
Converter<? extends T, ?> 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.
- * <p>
- * If the object is <code>null</code>, then it is rendered as an empty string
- * instead.
- *
- * @since
- * @author Vaadin Ltd
- */
-public class ObjectRenderer extends AbstractRenderer<Object> {
-
- /**
- * Creates a new <code>toString</code> 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