+++ /dev/null
-/*
- * 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();
- }
-}
+++ /dev/null
-/*
- * 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);
- }
-}
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;
public static abstract class Column<C, T> {
/**
- * 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.
+ * Default renderer for GridColumns. Renders everything into text
+ * through {@link Object#toString()}.
*/
- private final class DefaultObjectRenderer extends ObjectRenderer {
+ private final class DefaultTextRenderer implements Renderer<Object> {
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) {
warned = true;
}
- super.render(cell, data);
+ final String text;
+ if (data == null) {
+ text = "";
+ } else {
+ text = data.toString();
+ }
+
+ cell.getElement().setInnerText(text);
}
}
* Constructs a new column with a simple TextRenderer.
*/
public Column() {
- setRenderer(new DefaultObjectRenderer());
+ setRenderer(new DefaultTextRenderer());
}
/**
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;
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());
}
/**
* @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;
}
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() + ")");
}
}
return converter;
}
- @SuppressWarnings("unchecked")
private <T> boolean internalSetRenderer(Renderer<T> renderer) {
Converter<? extends T, ?> converter;
+++ /dev/null
-/*
- * 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);
- }
-}
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;
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;
private static class TestBean {
int i = 42;
-
- @Override
- public String toString() {
- return "TestBean [" + i + "]";
- }
}
private static class ExtendedBean extends TestBean {
@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());
}
@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());
@Test
public void testEncodingWithoutConverter() throws Exception {
- assertEquals("TestBean [42]", render(baz, new TestBean()).asString());
+ assertEquals("", render(baz, new TestBean()).asString());
}
@Test
+++ /dev/null
-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));
- }
-}
+++ /dev/null
-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());
- }
-}