aboutsummaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorHenrik Paul <henrik@vaadin.com>2015-01-14 15:40:49 +0200
committerJohannes Dahlström <johannesd@vaadin.com>2015-01-27 10:20:06 +0000
commitabaec0217b3351d6f1835d7095ed2a3958fbfcdb (patch)
treed9e675ea5e57cef1c9a18988b255c5ca8b118b03 /client
parent627c4c40997148f2c55ff7f533669a4284fbba2d (diff)
downloadvaadin-framework-abaec0217b3351d6f1835d7095ed2a3958fbfcdb.tar.gz
vaadin-framework-abaec0217b3351d6f1835d7095ed2a3958fbfcdb.zip
Grid now uses ObjectRenderer by default (#15417)
Change-Id: I2aa8105c0eadbadb29f9aab9e3e3aeb21629f6f3
Diffstat (limited to 'client')
-rw-r--r--client/src/com/vaadin/client/connectors/ObjectRendererConnector.java38
-rw-r--r--client/src/com/vaadin/client/renderers/ObjectRenderer.java36
-rw-r--r--client/src/com/vaadin/client/widgets/Grid.java27
3 files changed, 87 insertions, 14 deletions
diff --git a/client/src/com/vaadin/client/connectors/ObjectRendererConnector.java b/client/src/com/vaadin/client/connectors/ObjectRendererConnector.java
new file mode 100644
index 0000000000..877eaaa569
--- /dev/null
+++ b/client/src/com/vaadin/client/connectors/ObjectRendererConnector.java
@@ -0,0 +1,38 @@
+/*
+ * 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}.
+ * <p>
+ * 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<String> {
+
+ @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
new file mode 100644
index 0000000000..a2c4e7bfc6
--- /dev/null
+++ b/client/src/com/vaadin/client/renderers/ObjectRenderer.java
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ * <p>
+ * If the object is <code>null</code>, then it is rendered as an empty string
+ * instead.
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public class ObjectRenderer implements Renderer<Object> {
+ @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 9445ab77fb..93e94b8447 100644
--- a/client/src/com/vaadin/client/widgets/Grid.java
+++ b/client/src/com/vaadin/client/widgets/Grid.java
@@ -63,6 +63,7 @@ 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;
@@ -2577,13 +2578,18 @@ public class Grid<T> extends ResizeComposite implements
public static abstract class Column<C, T> {
/**
- * Default renderer for GridColumns. Renders everything into text
- * through {@link Object#toString()}.
+ * The default renderer for grid columns.
+ * <p>
+ * The first time this renderer is called, a warning is displayed,
+ * informing the developer to use a manually defined renderer for their
+ * column.
*/
- private final class DefaultTextRenderer implements Renderer<Object> {
+ private final class DefaultObjectRenderer extends ObjectRenderer {
boolean warned = false;
- private final String DEFAULT_RENDERER_WARNING = "This column uses a dummy default TextRenderer. "
- + "A more suitable renderer should be set using the setRenderer() method.";
+ 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 void render(RendererCellReference cell, Object data) {
@@ -2594,14 +2600,7 @@ public class Grid<T> extends ResizeComposite implements
warned = true;
}
- final String text;
- if (data == null) {
- text = "";
- } else {
- text = data.toString();
- }
-
- cell.getElement().setInnerText(text);
+ super.render(cell, data);
}
}
@@ -2633,7 +2632,7 @@ public class Grid<T> extends ResizeComposite implements
* Constructs a new column with a simple TextRenderer.
*/
public Column() {
- setRenderer(new DefaultTextRenderer());
+ setRenderer(new DefaultObjectRenderer());
}
/**