]> source.dussan.org Git - vaadin-framework.git/commitdiff
Move Renderers to com.vaadin.ui.renderer package (#13334)
authorTeemu Suo-Anttila <teemusa@vaadin.com>
Thu, 11 Dec 2014 11:42:06 +0000 (13:42 +0200)
committerVaadin Code Review <review@vaadin.com>
Thu, 11 Dec 2014 12:37:20 +0000 (12:37 +0000)
Change-Id: I80370f05cfa8123d64728abd5ede9642931e0cd8

35 files changed:
client/src/com/vaadin/client/connectors/ButtonRendererConnector.java
client/src/com/vaadin/client/connectors/DateRendererConnector.java
client/src/com/vaadin/client/connectors/ImageRendererConnector.java
client/src/com/vaadin/client/connectors/NumberRendererConnector.java
client/src/com/vaadin/client/connectors/ProgressBarRendererConnector.java
client/src/com/vaadin/client/connectors/TextRendererConnector.java
client/src/com/vaadin/client/connectors/UnsafeHtmlRendererConnector.java
server/src/com/vaadin/data/RpcDataProviderExtension.java
server/src/com/vaadin/ui/Grid.java
server/src/com/vaadin/ui/components/grid/Renderer.java [deleted file]
server/src/com/vaadin/ui/components/grid/renderers/ButtonRenderer.java [deleted file]
server/src/com/vaadin/ui/components/grid/renderers/ClickableRenderer.java [deleted file]
server/src/com/vaadin/ui/components/grid/renderers/DateRenderer.java [deleted file]
server/src/com/vaadin/ui/components/grid/renderers/HtmlRenderer.java [deleted file]
server/src/com/vaadin/ui/components/grid/renderers/ImageRenderer.java [deleted file]
server/src/com/vaadin/ui/components/grid/renderers/NumberRenderer.java [deleted file]
server/src/com/vaadin/ui/components/grid/renderers/ProgressBarRenderer.java [deleted file]
server/src/com/vaadin/ui/components/grid/renderers/TextRenderer.java [deleted file]
server/src/com/vaadin/ui/renderer/ButtonRenderer.java [new file with mode: 0644]
server/src/com/vaadin/ui/renderer/ClickableRenderer.java [new file with mode: 0644]
server/src/com/vaadin/ui/renderer/DateRenderer.java [new file with mode: 0644]
server/src/com/vaadin/ui/renderer/HtmlRenderer.java [new file with mode: 0644]
server/src/com/vaadin/ui/renderer/ImageRenderer.java [new file with mode: 0644]
server/src/com/vaadin/ui/renderer/NumberRenderer.java [new file with mode: 0644]
server/src/com/vaadin/ui/renderer/ProgressBarRenderer.java [new file with mode: 0644]
server/src/com/vaadin/ui/renderer/Renderer.java [new file with mode: 0644]
server/src/com/vaadin/ui/renderer/TextRenderer.java [new file with mode: 0644]
server/tests/src/com/vaadin/tests/server/component/grid/ImageRendererTest.java [deleted file]
server/tests/src/com/vaadin/tests/server/component/grid/RendererTest.java [deleted file]
server/tests/src/com/vaadin/tests/server/renderer/ImageRendererTest.java [new file with mode: 0644]
server/tests/src/com/vaadin/tests/server/renderer/RendererTest.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/grid/GridColspans.java
uitest/src/com/vaadin/tests/components/grid/GridColumnAutoWidth.java
uitest/src/com/vaadin/tests/components/grid/WidgetRenderers.java
uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java

index 45556d6176c6426c4435a059eba8b4abb65945ab..e4f850fb48aac7bcbec7ab35bd216f4d26bde05e 100644 (file)
@@ -27,7 +27,7 @@ import com.vaadin.shared.ui.Connect;
  * @since
  * @author Vaadin Ltd
  */
-@Connect(com.vaadin.ui.components.grid.renderers.ButtonRenderer.class)
+@Connect(com.vaadin.ui.renderer.ButtonRenderer.class)
 public class ButtonRendererConnector extends ClickableRendererConnector<String> {
 
     @Override
index b9fad95f0d32a6053bab477de0b6032867c00bc2..2df8184eaf5eab56e2d30c38c47f0ec56d65bb9e 100644 (file)
@@ -28,7 +28,7 @@ import com.vaadin.shared.ui.Connect;
  * @since
  * @author Vaadin Ltd
  */
-@Connect(com.vaadin.ui.components.grid.renderers.DateRenderer.class)
+@Connect(com.vaadin.ui.renderer.DateRenderer.class)
 public class DateRendererConnector extends TextRendererConnector {
     // No implementation needed
 }
index 33e108cd1e4f77f7ec8e9ee1902222cae5c04fe5..c5dfd97f69f2c100c223c61e9b7cc09ceb847c9a 100644 (file)
@@ -31,7 +31,7 @@ import com.vaadin.shared.ui.Connect;
  * @since
  * @author Vaadin Ltd
  */
-@Connect(com.vaadin.ui.components.grid.renderers.ImageRenderer.class)
+@Connect(com.vaadin.ui.renderer.ImageRenderer.class)
 public class ImageRendererConnector extends ClickableRendererConnector<String> {
 
     @Override
index cf8ef3e0762be0e4ea6f0c0ffa4c5ff009d5e9d1..68c96d21bc2337b1536df7862ea52c49996c0c90 100644 (file)
@@ -29,7 +29,7 @@ import com.vaadin.shared.ui.Connect;
  * @since
  * @author Vaadin Ltd
  */
-@Connect(com.vaadin.ui.components.grid.renderers.NumberRenderer.class)
+@Connect(com.vaadin.ui.renderer.NumberRenderer.class)
 public class NumberRendererConnector extends TextRendererConnector {
     // no implementation needed
 }
index ec7e8d0d08cb68e4918a0a1360b8de05c4c2de52..c3dfa66dbd877ce969f8ad7f486c61a8199551d0 100644 (file)
@@ -24,7 +24,7 @@ import com.vaadin.shared.ui.Connect;
  * @since
  * @author Vaadin Ltd
  */
-@Connect(com.vaadin.ui.components.grid.renderers.ProgressBarRenderer.class)
+@Connect(com.vaadin.ui.renderer.ProgressBarRenderer.class)
 public class ProgressBarRendererConnector extends
         AbstractRendererConnector<Double> {
 
index 6af095c54091e915cd98b120cd154557d961fd7b..53aee8349782a535957aeaaa4f0be24fd4c960f7 100644 (file)
@@ -24,7 +24,7 @@ import com.vaadin.shared.ui.Connect;
  * @since
  * @author Vaadin Ltd
  */
-@Connect(com.vaadin.ui.components.grid.renderers.TextRenderer.class)
+@Connect(com.vaadin.ui.renderer.TextRenderer.class)
 public class TextRendererConnector extends AbstractRendererConnector<String> {
 
     @Override
index d696b5021463033788bec0be70ec1e5d93c470dd..fd93dfd9e2b088150989bef002da850342d1fc7c 100644 (file)
@@ -25,7 +25,7 @@ import com.vaadin.shared.ui.Connect;
  * @since
  * @author Vaadin Ltd
  */
-@Connect(com.vaadin.ui.components.grid.renderers.HtmlRenderer.class)
+@Connect(com.vaadin.ui.renderer.HtmlRenderer.class)
 public class UnsafeHtmlRendererConnector extends
         AbstractRendererConnector<String> {
 
index aa0d6b37169e96457423b8c82ad8b8a4c81c6a03..9f7c783537af2ed97c74d17fa1f2479f28dfeab7 100644 (file)
@@ -52,7 +52,7 @@ import com.vaadin.shared.ui.grid.Range;
 import com.vaadin.ui.Grid;
 import com.vaadin.ui.Grid.CellStyleGenerator;
 import com.vaadin.ui.Grid.Column;
-import com.vaadin.ui.components.grid.Renderer;
+import com.vaadin.ui.renderer.Renderer;
 
 import elemental.json.Json;
 import elemental.json.JsonArray;
@@ -439,8 +439,8 @@ public class RpcDataProviderExtension extends AbstractExtension {
          * @param removedPropertyIds
          *            the property ids that have been removed from the container
          */
-        public void propertiesRemoved(
-                @SuppressWarnings("unused") Collection<Object> removedPropertyIds) {
+        public void propertiesRemoved(@SuppressWarnings("unused")
+        Collection<Object> removedPropertyIds) {
             /*
              * no-op, for now.
              * 
index 3896c532682b38afd25ded806781ece19b12bfe2..7a6e6abef27a478077b52276f4f6e6f94816e85e 100644 (file)
@@ -77,10 +77,8 @@ import com.vaadin.shared.ui.grid.ScrollDestination;
 import com.vaadin.shared.ui.grid.SortDirection;
 import com.vaadin.shared.ui.grid.SortEventOriginator;
 import com.vaadin.shared.util.SharedUtil;
-import com.vaadin.ui.components.grid.Renderer;
 import com.vaadin.ui.components.grid.SortOrderChangeEvent;
 import com.vaadin.ui.components.grid.SortOrderChangeListener;
-import com.vaadin.ui.components.grid.renderers.TextRenderer;
 import com.vaadin.ui.components.grid.selection.MultiSelectionModel;
 import com.vaadin.ui.components.grid.selection.NoSelectionModel;
 import com.vaadin.ui.components.grid.selection.SelectionChangeEvent;
@@ -90,6 +88,8 @@ import com.vaadin.ui.components.grid.selection.SelectionModel;
 import com.vaadin.ui.components.grid.selection.SingleSelectionModel;
 import com.vaadin.ui.components.grid.sort.Sort;
 import com.vaadin.ui.components.grid.sort.SortOrder;
+import com.vaadin.ui.renderer.Renderer;
+import com.vaadin.ui.renderer.TextRenderer;
 import com.vaadin.util.ReflectTools;
 
 import elemental.json.Json;
diff --git a/server/src/com/vaadin/ui/components/grid/Renderer.java b/server/src/com/vaadin/ui/components/grid/Renderer.java
deleted file mode 100644 (file)
index 1e63610..0000000
+++ /dev/null
@@ -1,69 +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.components.grid;
-
-import com.vaadin.server.ClientConnector;
-import com.vaadin.server.Extension;
-
-import elemental.json.JsonValue;
-
-/**
- * A ClientConnector for controlling client-side
- * {@link com.vaadin.client.ui.grid.Renderer Grid renderers}. Renderers
- * currently extend the Extension interface, but this fact should be regarded as
- * an implementation detail and subject to change in a future major or minor
- * Vaadin revision.
- * 
- * @param <T>
- *            the type this renderer knows how to present
- * 
- * @since
- * @author Vaadin Ltd
- */
-public interface Renderer<T> extends Extension {
-
-    /**
-     * Returns the class literal corresponding to the presentation type T.
-     * 
-     * @return the class literal of T
-     */
-    Class<T> getPresentationType();
-
-    /**
-     * Encodes the given value into a {@link JsonValue}.
-     * 
-     * @param value
-     *            the value to encode
-     * @return a JSON representation of the given value
-     */
-    JsonValue encode(T value);
-
-    /**
-     * This method is inherited from Extension but should never be called
-     * directly with a Renderer.
-     */
-    @Override
-    @Deprecated
-    void remove();
-
-    /**
-     * This method is inherited from Extension but should never be called
-     * directly with a Renderer.
-     */
-    @Override
-    @Deprecated
-    void setParent(ClientConnector parent);
-}
diff --git a/server/src/com/vaadin/ui/components/grid/renderers/ButtonRenderer.java b/server/src/com/vaadin/ui/components/grid/renderers/ButtonRenderer.java
deleted file mode 100644 (file)
index dece41c..0000000
+++ /dev/null
@@ -1,45 +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.components.grid.renderers;
-
-/**
- * A Renderer that displays a button with a textual caption. The value of the
- * corresponding property is used as the caption. Click listeners can be added
- * to the renderer, invoked when any of the rendered buttons is clicked.
- * 
- * @since
- * @author Vaadin Ltd
- */
-public class ButtonRenderer extends ClickableRenderer<String> {
-
-    /**
-     * Creates a new button renderer.
-     */
-    public ButtonRenderer() {
-        super(String.class);
-    }
-
-    /**
-     * Creates a new button renderer and adds the given click listener to it.
-     * 
-     * @param listener
-     *            the click listener to register
-     */
-    public ButtonRenderer(RendererClickListener listener) {
-        this();
-        addClickListener(listener);
-    }
-}
diff --git a/server/src/com/vaadin/ui/components/grid/renderers/ClickableRenderer.java b/server/src/com/vaadin/ui/components/grid/renderers/ClickableRenderer.java
deleted file mode 100644 (file)
index c08ef73..0000000
+++ /dev/null
@@ -1,121 +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.components.grid.renderers;
-
-import java.lang.reflect.Method;
-
-import com.vaadin.event.ConnectorEventListener;
-import com.vaadin.event.MouseEvents.ClickEvent;
-import com.vaadin.shared.MouseEventDetails;
-import com.vaadin.shared.ui.grid.renderers.RendererClickRpc;
-import com.vaadin.ui.Grid;
-import com.vaadin.ui.Grid.AbstractRenderer;
-import com.vaadin.util.ReflectTools;
-
-/**
- * An abstract superclass for Renderers that render clickable items. Click
- * listeners can be added to a renderer to be notified when any of the rendered
- * items is clicked.
- * 
- * @param <T>
- *            the type presented by the renderer
- * 
- * @since
- * @author Vaadin Ltd
- */
-public class ClickableRenderer<T> extends AbstractRenderer<T> {
-
-    /**
-     * An interface for listening to {@link RendererClickEvent renderer click
-     * events}.
-     * 
-     * @see {@link ButtonRenderer#addClickListener(RendererClickListener)}
-     */
-    public interface RendererClickListener extends ConnectorEventListener {
-
-        static final Method CLICK_METHOD = ReflectTools.findMethod(
-                RendererClickListener.class, "click", RendererClickEvent.class);
-
-        /**
-         * Called when a rendered button is clicked.
-         * 
-         * @param event
-         *            the event representing the click
-         */
-        void click(RendererClickEvent event);
-    }
-
-    /**
-     * An event fired when a button rendered by a ButtonRenderer is clicked.
-     */
-    public static class RendererClickEvent extends ClickEvent {
-
-        private Object itemId;
-
-        protected RendererClickEvent(Grid source, Object itemId,
-                MouseEventDetails mouseEventDetails) {
-            super(source, mouseEventDetails);
-            this.itemId = itemId;
-        }
-
-        /**
-         * Returns the item ID of the row where the click event originated.
-         * 
-         * @return the item ID of the clicked row
-         */
-        public Object getItemId() {
-            return itemId;
-        }
-    }
-
-    protected ClickableRenderer(Class<T> presentationType) {
-        super(presentationType);
-        registerRpc(new RendererClickRpc() {
-            @Override
-            public void click(int row, int column,
-                    MouseEventDetails mouseDetails) {
-
-                Grid grid = (Grid) getParent();
-                Object itemId = grid.getContainerDataSource().getIdByIndex(row);
-                // TODO map column index to property ID or send column ID
-                // instead of index from the client
-                fireEvent(new RendererClickEvent(grid, itemId, mouseDetails));
-            }
-        });
-    }
-
-    /**
-     * Adds a click listener to this button renderer. The listener is invoked
-     * every time one of the buttons rendered by this renderer is clicked.
-     * 
-     * @param listener
-     *            the click listener to be added
-     */
-    public void addClickListener(RendererClickListener listener) {
-        addListener(RendererClickEvent.class, listener,
-                RendererClickListener.CLICK_METHOD);
-    }
-
-    /**
-     * Removes the given click listener from this renderer.
-     * 
-     * @param listener
-     *            the click listener to be removed
-     */
-    public void removeClickListener(RendererClickListener listener) {
-        removeListener(RendererClickEvent.class, listener);
-    }
-}
diff --git a/server/src/com/vaadin/ui/components/grid/renderers/DateRenderer.java b/server/src/com/vaadin/ui/components/grid/renderers/DateRenderer.java
deleted file mode 100644 (file)
index 94eeab7..0000000
+++ /dev/null
@@ -1,156 +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.components.grid.renderers;
-
-import java.text.DateFormat;
-import java.util.Date;
-import java.util.Locale;
-
-import com.vaadin.ui.Grid.AbstractRenderer;
-
-import elemental.json.JsonValue;
-
-/**
- * A renderer for presenting date values.
- * 
- * @since
- * @author Vaadin Ltd
- */
-public class DateRenderer extends AbstractRenderer<Date> {
-    private final Locale locale;
-    private final String formatString;
-    private final DateFormat dateFormat;
-
-    /**
-     * Creates a new date renderer.
-     * <p>
-     * The renderer is configured to render with the {@link Date#toString()}
-     * representation for the default locale.
-     */
-    public DateRenderer() {
-        this(Locale.getDefault());
-    }
-
-    /**
-     * Creates a new date renderer.
-     * <p>
-     * The renderer is configured to render with the {@link Date#toString()}
-     * representation for the given locale.
-     * 
-     * @param locale
-     *            the locale in which to present dates
-     * @throws IllegalArgumentException
-     *             if {@code locale} is {@code null}
-     */
-    public DateRenderer(Locale locale) throws IllegalArgumentException {
-        this("%s", locale);
-    }
-
-    /**
-     * Creates a new date renderer.
-     * <p>
-     * The renderer is configured to render with the given string format, as
-     * displayed in the default locale.
-     * 
-     * @param formatString
-     *            the format string with which to format the date
-     * @throws IllegalArgumentException
-     *             if {@code formatString} is {@code null}
-     * @see <a
-     *      href="http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html#syntax">Format
-     *      String Syntax</a>
-     */
-    public DateRenderer(String formatString) throws IllegalArgumentException {
-        this(formatString, Locale.getDefault());
-    }
-
-    /**
-     * Creates a new date renderer.
-     * <p>
-     * The renderer is configured to render with the given string format, as
-     * displayed in the given locale.
-     * 
-     * @param formatString
-     *            the format string to format the date with
-     * @param locale
-     *            the locale to use
-     * @throws IllegalArgumentException
-     *             if either argument is {@code null}
-     * @see <a
-     *      href="http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html#syntax">Format
-     *      String Syntax</a>
-     */
-    public DateRenderer(String formatString, Locale locale)
-            throws IllegalArgumentException {
-        super(Date.class);
-
-        if (formatString == null) {
-            throw new IllegalArgumentException("format string may not be null");
-        }
-
-        if (locale == null) {
-            throw new IllegalArgumentException("locale may not be null");
-        }
-
-        this.locale = locale;
-        this.formatString = formatString;
-        dateFormat = null;
-    }
-
-    /**
-     * Creates a new date renderer.
-     * <p>
-     * The renderer is configured to render with he given date format.
-     * 
-     * @param dateFormat
-     *            the date format to use when rendering dates
-     * @throws IllegalArgumentException
-     *             if {@code dateFormat} is {@code null}
-     */
-    public DateRenderer(DateFormat dateFormat) throws IllegalArgumentException {
-        super(Date.class);
-        if (dateFormat == null) {
-            throw new IllegalArgumentException("date format may not be null");
-        }
-
-        locale = null;
-        formatString = null;
-        this.dateFormat = dateFormat;
-    }
-
-    @Override
-    public JsonValue encode(Date value) {
-        String dateString;
-        if (dateFormat != null) {
-            dateString = dateFormat.format(value);
-        } else {
-            dateString = String.format(locale, formatString, value);
-        }
-        return encode(dateString, String.class);
-    }
-
-    @Override
-    public String toString() {
-        final String fieldInfo;
-        if (dateFormat != null) {
-            fieldInfo = "dateFormat: " + dateFormat.toString();
-        } else {
-            fieldInfo = "locale: " + locale + ", formatString: " + formatString;
-        }
-
-        return String.format("%s [%s]", getClass().getSimpleName(), fieldInfo);
-    }
-}
diff --git a/server/src/com/vaadin/ui/components/grid/renderers/HtmlRenderer.java b/server/src/com/vaadin/ui/components/grid/renderers/HtmlRenderer.java
deleted file mode 100644 (file)
index 6507792..0000000
+++ /dev/null
@@ -1,33 +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.components.grid.renderers;
-
-import com.vaadin.ui.Grid.AbstractRenderer;
-
-/**
- * A renderer for presenting HTML content.
- * 
- * @since
- * @author Vaadin Ltd
- */
-public class HtmlRenderer extends AbstractRenderer<String> {
-    /**
-     * Creates a new HTML renderer.
-     */
-    public HtmlRenderer() {
-        super(String.class);
-    }
-}
diff --git a/server/src/com/vaadin/ui/components/grid/renderers/ImageRenderer.java b/server/src/com/vaadin/ui/components/grid/renderers/ImageRenderer.java
deleted file mode 100644 (file)
index be57a5e..0000000
+++ /dev/null
@@ -1,67 +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.components.grid.renderers;
-
-import com.vaadin.server.ExternalResource;
-import com.vaadin.server.Resource;
-import com.vaadin.server.ResourceReference;
-import com.vaadin.server.ThemeResource;
-import com.vaadin.shared.communication.URLReference;
-
-import elemental.json.JsonValue;
-
-/**
- * A renderer for presenting images.
- * <p>
- * The image for each rendered cell is read from a Resource-typed property in
- * the data source. Only {@link ExternalResource}s and {@link ThemeResource}s
- * are currently supported.
- * 
- * @since
- * @author Vaadin Ltd
- */
-public class ImageRenderer extends ClickableRenderer<Resource> {
-
-    /**
-     * Creates a new image renderer.
-     */
-    public ImageRenderer() {
-        super(Resource.class);
-    }
-
-    /**
-     * Creates a new image renderer and adds the given click listener to it.
-     * 
-     * @param listener
-     *            the click listener to register
-     */
-    public ImageRenderer(RendererClickListener listener) {
-        this();
-        addClickListener(listener);
-    }
-
-    @Override
-    public JsonValue encode(Resource resource) {
-        if (!(resource instanceof ExternalResource || resource instanceof ThemeResource)) {
-            throw new IllegalArgumentException(
-                    "ImageRenderer only supports ExternalResource and ThemeResource ("
-                            + resource.getClass().getSimpleName() + "given )");
-        }
-
-        return encode(ResourceReference.create(resource, this, null),
-                URLReference.class);
-    }
-}
diff --git a/server/src/com/vaadin/ui/components/grid/renderers/NumberRenderer.java b/server/src/com/vaadin/ui/components/grid/renderers/NumberRenderer.java
deleted file mode 100644 (file)
index 955b36d..0000000
+++ /dev/null
@@ -1,163 +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.components.grid.renderers;
-
-import java.text.NumberFormat;
-import java.util.Locale;
-
-import com.vaadin.ui.Grid.AbstractRenderer;
-
-import elemental.json.JsonValue;
-
-/**
- * A renderer for presenting number values.
- * 
- * @since
- * @author Vaadin Ltd
- */
-public class NumberRenderer extends AbstractRenderer<Number> {
-    private final Locale locale;
-    private final NumberFormat numberFormat;
-    private final String formatString;
-
-    /**
-     * Creates a new number renderer.
-     * <p>
-     * The renderer is configured to render with the number's natural string
-     * representation in the default locale.
-     */
-    public NumberRenderer() {
-        this(Locale.getDefault());
-    }
-
-    /**
-     * Creates a new number renderer.
-     * <p>
-     * The renderer is configured to render the number as defined with the given
-     * number format.
-     * 
-     * @param numberFormat
-     *            the number format with which to display numbers
-     * @throws IllegalArgumentException
-     *             if {@code numberFormat} is {@code null}
-     */
-    public NumberRenderer(NumberFormat numberFormat)
-            throws IllegalArgumentException {
-        super(Number.class);
-
-        if (numberFormat == null) {
-            throw new IllegalArgumentException("Number format may not be null");
-        }
-
-        locale = null;
-        this.numberFormat = numberFormat;
-        formatString = null;
-    }
-
-    /**
-     * Creates a new number renderer.
-     * <p>
-     * The renderer is configured to render with the number's natural string
-     * representation in the given locale.
-     * 
-     * @param locale
-     *            the locale in which to display numbers
-     * @throws IllegalArgumentException
-     *             if {@code locale} is {@code null}
-     */
-    public NumberRenderer(Locale locale) throws IllegalArgumentException {
-        this("%s", locale);
-    }
-
-    /**
-     * Creates a new number renderer.
-     * <p>
-     * The renderer is configured to render with the given format string in the
-     * default locale.
-     * 
-     * @param formatString
-     *            the format string with which to format the number
-     * @throws IllegalArgumentException
-     *             if {@code formatString} is {@code null}
-     * @see <a
-     *      href="http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html#syntax">Format
-     *      String Syntax</a>
-     */
-    public NumberRenderer(String formatString) throws IllegalArgumentException {
-        this(formatString, Locale.getDefault());
-    }
-
-    /**
-     * Creates a new number renderer.
-     * <p>
-     * The renderer is configured to render with the given format string in the
-     * given locale.
-     * 
-     * @param formatString
-     *            the format string with which to format the number
-     * @param locale
-     *            the locale in which to present numbers
-     * @throws IllegalArgumentException
-     *             if either argument is {@code null}
-     * @see <a
-     *      href="http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html#syntax">Format
-     *      String Syntax</a>
-     */
-    public NumberRenderer(String formatString, Locale locale) {
-        super(Number.class);
-
-        if (formatString == null) {
-            throw new IllegalArgumentException("Format string may not be null");
-        }
-
-        if (locale == null) {
-            throw new IllegalArgumentException("Locale may not be null");
-        }
-
-        this.locale = locale;
-        numberFormat = null;
-        this.formatString = formatString;
-    }
-
-    @Override
-    public JsonValue encode(Number value) {
-        String stringValue;
-        if (formatString != null && locale != null) {
-            stringValue = String.format(locale, formatString, value);
-        } else if (numberFormat != null) {
-            stringValue = numberFormat.format(value);
-        } else {
-            throw new IllegalStateException(String.format("Internal bug: "
-                    + "%s is in an illegal state: "
-                    + "[locale: %s, numberFormat: %s, formatString: %s]",
-                    getClass().getSimpleName(), locale, numberFormat,
-                    formatString));
-        }
-        return encode(stringValue, String.class);
-    }
-
-    @Override
-    public String toString() {
-        final String fieldInfo;
-        if (numberFormat != null) {
-            fieldInfo = "numberFormat: " + numberFormat.toString();
-        } else {
-            fieldInfo = "locale: " + locale + ", formatString: " + formatString;
-        }
-
-        return String.format("%s [%s]", getClass().getSimpleName(), fieldInfo);
-    }
-}
diff --git a/server/src/com/vaadin/ui/components/grid/renderers/ProgressBarRenderer.java b/server/src/com/vaadin/ui/components/grid/renderers/ProgressBarRenderer.java
deleted file mode 100644 (file)
index 7021916..0000000
+++ /dev/null
@@ -1,44 +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.components.grid.renderers;
-
-import com.vaadin.ui.Grid.AbstractRenderer;
-
-import elemental.json.JsonValue;
-
-/**
- * A renderer that represents a double values as a graphical progress bar.
- * 
- * @since
- * @author Vaadin Ltd
- */
-public class ProgressBarRenderer extends AbstractRenderer<Double> {
-
-    /**
-     * Creates a new text renderer
-     */
-    public ProgressBarRenderer() {
-        super(Double.class);
-    }
-
-    @Override
-    public JsonValue encode(Double value) {
-        if (value != null) {
-            value = Math.max(Math.min(value, 1), 0);
-        }
-        return super.encode(value);
-    }
-}
diff --git a/server/src/com/vaadin/ui/components/grid/renderers/TextRenderer.java b/server/src/com/vaadin/ui/components/grid/renderers/TextRenderer.java
deleted file mode 100644 (file)
index 554d57f..0000000
+++ /dev/null
@@ -1,34 +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.components.grid.renderers;
-
-import com.vaadin.ui.Grid.AbstractRenderer;
-
-/**
- * A renderer for presenting simple plain-text string values.
- * 
- * @since
- * @author Vaadin Ltd
- */
-public class TextRenderer extends AbstractRenderer<String> {
-
-    /**
-     * Creates a new text renderer
-     */
-    public TextRenderer() {
-        super(String.class);
-    }
-}
diff --git a/server/src/com/vaadin/ui/renderer/ButtonRenderer.java b/server/src/com/vaadin/ui/renderer/ButtonRenderer.java
new file mode 100644 (file)
index 0000000..4a7a86d
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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;
+
+/**
+ * A Renderer that displays a button with a textual caption. The value of the
+ * corresponding property is used as the caption. Click listeners can be added
+ * to the renderer, invoked when any of the rendered buttons is clicked.
+ * 
+ * @since
+ * @author Vaadin Ltd
+ */
+public class ButtonRenderer extends ClickableRenderer<String> {
+
+    /**
+     * Creates a new button renderer.
+     */
+    public ButtonRenderer() {
+        super(String.class);
+    }
+
+    /**
+     * Creates a new button renderer and adds the given click listener to it.
+     * 
+     * @param listener
+     *            the click listener to register
+     */
+    public ButtonRenderer(RendererClickListener listener) {
+        this();
+        addClickListener(listener);
+    }
+}
diff --git a/server/src/com/vaadin/ui/renderer/ClickableRenderer.java b/server/src/com/vaadin/ui/renderer/ClickableRenderer.java
new file mode 100644 (file)
index 0000000..0d745ab
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+ * 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 java.lang.reflect.Method;
+
+import com.vaadin.event.ConnectorEventListener;
+import com.vaadin.event.MouseEvents.ClickEvent;
+import com.vaadin.shared.MouseEventDetails;
+import com.vaadin.shared.ui.grid.renderers.RendererClickRpc;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.Grid.AbstractRenderer;
+import com.vaadin.util.ReflectTools;
+
+/**
+ * An abstract superclass for Renderers that render clickable items. Click
+ * listeners can be added to a renderer to be notified when any of the rendered
+ * items is clicked.
+ * 
+ * @param <T>
+ *            the type presented by the renderer
+ * 
+ * @since
+ * @author Vaadin Ltd
+ */
+public class ClickableRenderer<T> extends AbstractRenderer<T> {
+
+    /**
+     * An interface for listening to {@link RendererClickEvent renderer click
+     * events}.
+     * 
+     * @see {@link ButtonRenderer#addClickListener(RendererClickListener)}
+     */
+    public interface RendererClickListener extends ConnectorEventListener {
+
+        static final Method CLICK_METHOD = ReflectTools.findMethod(
+                RendererClickListener.class, "click", RendererClickEvent.class);
+
+        /**
+         * Called when a rendered button is clicked.
+         * 
+         * @param event
+         *            the event representing the click
+         */
+        void click(RendererClickEvent event);
+    }
+
+    /**
+     * An event fired when a button rendered by a ButtonRenderer is clicked.
+     */
+    public static class RendererClickEvent extends ClickEvent {
+
+        private Object itemId;
+
+        protected RendererClickEvent(Grid source, Object itemId,
+                MouseEventDetails mouseEventDetails) {
+            super(source, mouseEventDetails);
+            this.itemId = itemId;
+        }
+
+        /**
+         * Returns the item ID of the row where the click event originated.
+         * 
+         * @return the item ID of the clicked row
+         */
+        public Object getItemId() {
+            return itemId;
+        }
+    }
+
+    protected ClickableRenderer(Class<T> presentationType) {
+        super(presentationType);
+        registerRpc(new RendererClickRpc() {
+            @Override
+            public void click(int row, int column,
+                    MouseEventDetails mouseDetails) {
+
+                Grid grid = (Grid) getParent();
+                Object itemId = grid.getContainerDataSource().getIdByIndex(row);
+                // TODO map column index to property ID or send column ID
+                // instead of index from the client
+                fireEvent(new RendererClickEvent(grid, itemId, mouseDetails));
+            }
+        });
+    }
+
+    /**
+     * Adds a click listener to this button renderer. The listener is invoked
+     * every time one of the buttons rendered by this renderer is clicked.
+     * 
+     * @param listener
+     *            the click listener to be added
+     */
+    public void addClickListener(RendererClickListener listener) {
+        addListener(RendererClickEvent.class, listener,
+                RendererClickListener.CLICK_METHOD);
+    }
+
+    /**
+     * Removes the given click listener from this renderer.
+     * 
+     * @param listener
+     *            the click listener to be removed
+     */
+    public void removeClickListener(RendererClickListener listener) {
+        removeListener(RendererClickEvent.class, listener);
+    }
+}
diff --git a/server/src/com/vaadin/ui/renderer/DateRenderer.java b/server/src/com/vaadin/ui/renderer/DateRenderer.java
new file mode 100644 (file)
index 0000000..4d1d702
--- /dev/null
@@ -0,0 +1,156 @@
+/*
+ * 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 java.text.DateFormat;
+import java.util.Date;
+import java.util.Locale;
+
+import com.vaadin.ui.Grid.AbstractRenderer;
+
+import elemental.json.JsonValue;
+
+/**
+ * A renderer for presenting date values.
+ * 
+ * @since
+ * @author Vaadin Ltd
+ */
+public class DateRenderer extends AbstractRenderer<Date> {
+    private final Locale locale;
+    private final String formatString;
+    private final DateFormat dateFormat;
+
+    /**
+     * Creates a new date renderer.
+     * <p>
+     * The renderer is configured to render with the {@link Date#toString()}
+     * representation for the default locale.
+     */
+    public DateRenderer() {
+        this(Locale.getDefault());
+    }
+
+    /**
+     * Creates a new date renderer.
+     * <p>
+     * The renderer is configured to render with the {@link Date#toString()}
+     * representation for the given locale.
+     * 
+     * @param locale
+     *            the locale in which to present dates
+     * @throws IllegalArgumentException
+     *             if {@code locale} is {@code null}
+     */
+    public DateRenderer(Locale locale) throws IllegalArgumentException {
+        this("%s", locale);
+    }
+
+    /**
+     * Creates a new date renderer.
+     * <p>
+     * The renderer is configured to render with the given string format, as
+     * displayed in the default locale.
+     * 
+     * @param formatString
+     *            the format string with which to format the date
+     * @throws IllegalArgumentException
+     *             if {@code formatString} is {@code null}
+     * @see <a
+     *      href="http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html#syntax">Format
+     *      String Syntax</a>
+     */
+    public DateRenderer(String formatString) throws IllegalArgumentException {
+        this(formatString, Locale.getDefault());
+    }
+
+    /**
+     * Creates a new date renderer.
+     * <p>
+     * The renderer is configured to render with the given string format, as
+     * displayed in the given locale.
+     * 
+     * @param formatString
+     *            the format string to format the date with
+     * @param locale
+     *            the locale to use
+     * @throws IllegalArgumentException
+     *             if either argument is {@code null}
+     * @see <a
+     *      href="http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html#syntax">Format
+     *      String Syntax</a>
+     */
+    public DateRenderer(String formatString, Locale locale)
+            throws IllegalArgumentException {
+        super(Date.class);
+
+        if (formatString == null) {
+            throw new IllegalArgumentException("format string may not be null");
+        }
+
+        if (locale == null) {
+            throw new IllegalArgumentException("locale may not be null");
+        }
+
+        this.locale = locale;
+        this.formatString = formatString;
+        dateFormat = null;
+    }
+
+    /**
+     * Creates a new date renderer.
+     * <p>
+     * The renderer is configured to render with he given date format.
+     * 
+     * @param dateFormat
+     *            the date format to use when rendering dates
+     * @throws IllegalArgumentException
+     *             if {@code dateFormat} is {@code null}
+     */
+    public DateRenderer(DateFormat dateFormat) throws IllegalArgumentException {
+        super(Date.class);
+        if (dateFormat == null) {
+            throw new IllegalArgumentException("date format may not be null");
+        }
+
+        locale = null;
+        formatString = null;
+        this.dateFormat = dateFormat;
+    }
+
+    @Override
+    public JsonValue encode(Date value) {
+        String dateString;
+        if (dateFormat != null) {
+            dateString = dateFormat.format(value);
+        } else {
+            dateString = String.format(locale, formatString, value);
+        }
+        return encode(dateString, String.class);
+    }
+
+    @Override
+    public String toString() {
+        final String fieldInfo;
+        if (dateFormat != null) {
+            fieldInfo = "dateFormat: " + dateFormat.toString();
+        } else {
+            fieldInfo = "locale: " + locale + ", formatString: " + formatString;
+        }
+
+        return String.format("%s [%s]", getClass().getSimpleName(), fieldInfo);
+    }
+}
diff --git a/server/src/com/vaadin/ui/renderer/HtmlRenderer.java b/server/src/com/vaadin/ui/renderer/HtmlRenderer.java
new file mode 100644 (file)
index 0000000..bdab519
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * 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;
+
+/**
+ * A renderer for presenting HTML content.
+ * 
+ * @since
+ * @author Vaadin Ltd
+ */
+public class HtmlRenderer extends AbstractRenderer<String> {
+    /**
+     * Creates a new HTML renderer.
+     */
+    public HtmlRenderer() {
+        super(String.class);
+    }
+}
diff --git a/server/src/com/vaadin/ui/renderer/ImageRenderer.java b/server/src/com/vaadin/ui/renderer/ImageRenderer.java
new file mode 100644 (file)
index 0000000..87a044c
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * 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.server.ExternalResource;
+import com.vaadin.server.Resource;
+import com.vaadin.server.ResourceReference;
+import com.vaadin.server.ThemeResource;
+import com.vaadin.shared.communication.URLReference;
+
+import elemental.json.JsonValue;
+
+/**
+ * A renderer for presenting images.
+ * <p>
+ * The image for each rendered cell is read from a Resource-typed property in
+ * the data source. Only {@link ExternalResource}s and {@link ThemeResource}s
+ * are currently supported.
+ * 
+ * @since
+ * @author Vaadin Ltd
+ */
+public class ImageRenderer extends ClickableRenderer<Resource> {
+
+    /**
+     * Creates a new image renderer.
+     */
+    public ImageRenderer() {
+        super(Resource.class);
+    }
+
+    /**
+     * Creates a new image renderer and adds the given click listener to it.
+     * 
+     * @param listener
+     *            the click listener to register
+     */
+    public ImageRenderer(RendererClickListener listener) {
+        this();
+        addClickListener(listener);
+    }
+
+    @Override
+    public JsonValue encode(Resource resource) {
+        if (!(resource instanceof ExternalResource || resource instanceof ThemeResource)) {
+            throw new IllegalArgumentException(
+                    "ImageRenderer only supports ExternalResource and ThemeResource ("
+                            + resource.getClass().getSimpleName() + "given )");
+        }
+
+        return encode(ResourceReference.create(resource, this, null),
+                URLReference.class);
+    }
+}
diff --git a/server/src/com/vaadin/ui/renderer/NumberRenderer.java b/server/src/com/vaadin/ui/renderer/NumberRenderer.java
new file mode 100644 (file)
index 0000000..9af5c4c
--- /dev/null
@@ -0,0 +1,163 @@
+/*
+ * 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 java.text.NumberFormat;
+import java.util.Locale;
+
+import com.vaadin.ui.Grid.AbstractRenderer;
+
+import elemental.json.JsonValue;
+
+/**
+ * A renderer for presenting number values.
+ * 
+ * @since
+ * @author Vaadin Ltd
+ */
+public class NumberRenderer extends AbstractRenderer<Number> {
+    private final Locale locale;
+    private final NumberFormat numberFormat;
+    private final String formatString;
+
+    /**
+     * Creates a new number renderer.
+     * <p>
+     * The renderer is configured to render with the number's natural string
+     * representation in the default locale.
+     */
+    public NumberRenderer() {
+        this(Locale.getDefault());
+    }
+
+    /**
+     * Creates a new number renderer.
+     * <p>
+     * The renderer is configured to render the number as defined with the given
+     * number format.
+     * 
+     * @param numberFormat
+     *            the number format with which to display numbers
+     * @throws IllegalArgumentException
+     *             if {@code numberFormat} is {@code null}
+     */
+    public NumberRenderer(NumberFormat numberFormat)
+            throws IllegalArgumentException {
+        super(Number.class);
+
+        if (numberFormat == null) {
+            throw new IllegalArgumentException("Number format may not be null");
+        }
+
+        locale = null;
+        this.numberFormat = numberFormat;
+        formatString = null;
+    }
+
+    /**
+     * Creates a new number renderer.
+     * <p>
+     * The renderer is configured to render with the number's natural string
+     * representation in the given locale.
+     * 
+     * @param locale
+     *            the locale in which to display numbers
+     * @throws IllegalArgumentException
+     *             if {@code locale} is {@code null}
+     */
+    public NumberRenderer(Locale locale) throws IllegalArgumentException {
+        this("%s", locale);
+    }
+
+    /**
+     * Creates a new number renderer.
+     * <p>
+     * The renderer is configured to render with the given format string in the
+     * default locale.
+     * 
+     * @param formatString
+     *            the format string with which to format the number
+     * @throws IllegalArgumentException
+     *             if {@code formatString} is {@code null}
+     * @see <a
+     *      href="http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html#syntax">Format
+     *      String Syntax</a>
+     */
+    public NumberRenderer(String formatString) throws IllegalArgumentException {
+        this(formatString, Locale.getDefault());
+    }
+
+    /**
+     * Creates a new number renderer.
+     * <p>
+     * The renderer is configured to render with the given format string in the
+     * given locale.
+     * 
+     * @param formatString
+     *            the format string with which to format the number
+     * @param locale
+     *            the locale in which to present numbers
+     * @throws IllegalArgumentException
+     *             if either argument is {@code null}
+     * @see <a
+     *      href="http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html#syntax">Format
+     *      String Syntax</a>
+     */
+    public NumberRenderer(String formatString, Locale locale) {
+        super(Number.class);
+
+        if (formatString == null) {
+            throw new IllegalArgumentException("Format string may not be null");
+        }
+
+        if (locale == null) {
+            throw new IllegalArgumentException("Locale may not be null");
+        }
+
+        this.locale = locale;
+        numberFormat = null;
+        this.formatString = formatString;
+    }
+
+    @Override
+    public JsonValue encode(Number value) {
+        String stringValue;
+        if (formatString != null && locale != null) {
+            stringValue = String.format(locale, formatString, value);
+        } else if (numberFormat != null) {
+            stringValue = numberFormat.format(value);
+        } else {
+            throw new IllegalStateException(String.format("Internal bug: "
+                    + "%s is in an illegal state: "
+                    + "[locale: %s, numberFormat: %s, formatString: %s]",
+                    getClass().getSimpleName(), locale, numberFormat,
+                    formatString));
+        }
+        return encode(stringValue, String.class);
+    }
+
+    @Override
+    public String toString() {
+        final String fieldInfo;
+        if (numberFormat != null) {
+            fieldInfo = "numberFormat: " + numberFormat.toString();
+        } else {
+            fieldInfo = "locale: " + locale + ", formatString: " + formatString;
+        }
+
+        return String.format("%s [%s]", getClass().getSimpleName(), fieldInfo);
+    }
+}
diff --git a/server/src/com/vaadin/ui/renderer/ProgressBarRenderer.java b/server/src/com/vaadin/ui/renderer/ProgressBarRenderer.java
new file mode 100644 (file)
index 0000000..cb688b1
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * 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 that represents a double values as a graphical progress bar.
+ * 
+ * @since
+ * @author Vaadin Ltd
+ */
+public class ProgressBarRenderer extends AbstractRenderer<Double> {
+
+    /**
+     * Creates a new text renderer
+     */
+    public ProgressBarRenderer() {
+        super(Double.class);
+    }
+
+    @Override
+    public JsonValue encode(Double value) {
+        if (value != null) {
+            value = Math.max(Math.min(value, 1), 0);
+        }
+        return super.encode(value);
+    }
+}
diff --git a/server/src/com/vaadin/ui/renderer/Renderer.java b/server/src/com/vaadin/ui/renderer/Renderer.java
new file mode 100644 (file)
index 0000000..6adddd1
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * 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.server.ClientConnector;
+import com.vaadin.server.Extension;
+
+import elemental.json.JsonValue;
+
+/**
+ * A ClientConnector for controlling client-side
+ * {@link com.vaadin.client.ui.grid.Renderer Grid renderers}. Renderers
+ * currently extend the Extension interface, but this fact should be regarded as
+ * an implementation detail and subject to change in a future major or minor
+ * Vaadin revision.
+ * 
+ * @param <T>
+ *            the type this renderer knows how to present
+ * 
+ * @since
+ * @author Vaadin Ltd
+ */
+public interface Renderer<T> extends Extension {
+
+    /**
+     * Returns the class literal corresponding to the presentation type T.
+     * 
+     * @return the class literal of T
+     */
+    Class<T> getPresentationType();
+
+    /**
+     * Encodes the given value into a {@link JsonValue}.
+     * 
+     * @param value
+     *            the value to encode
+     * @return a JSON representation of the given value
+     */
+    JsonValue encode(T value);
+
+    /**
+     * This method is inherited from Extension but should never be called
+     * directly with a Renderer.
+     */
+    @Override
+    @Deprecated
+    void remove();
+
+    /**
+     * This method is inherited from Extension but should never be called
+     * directly with a Renderer.
+     */
+    @Override
+    @Deprecated
+    void setParent(ClientConnector parent);
+}
diff --git a/server/src/com/vaadin/ui/renderer/TextRenderer.java b/server/src/com/vaadin/ui/renderer/TextRenderer.java
new file mode 100644 (file)
index 0000000..42bd02f
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * 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;
+
+/**
+ * A renderer for presenting simple plain-text string values.
+ * 
+ * @since
+ * @author Vaadin Ltd
+ */
+public class TextRenderer extends AbstractRenderer<String> {
+
+    /**
+     * Creates a new text renderer
+     */
+    public TextRenderer() {
+        super(String.class);
+    }
+}
diff --git a/server/tests/src/com/vaadin/tests/server/component/grid/ImageRendererTest.java b/server/tests/src/com/vaadin/tests/server/component/grid/ImageRendererTest.java
deleted file mode 100644 (file)
index cdf386e..0000000
+++ /dev/null
@@ -1,85 +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.tests.server.component.grid;
-
-import static org.junit.Assert.assertEquals;
-
-import java.io.File;
-
-import org.easymock.EasyMock;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.vaadin.server.ClassResource;
-import com.vaadin.server.ExternalResource;
-import com.vaadin.server.FileResource;
-import com.vaadin.server.FontAwesome;
-import com.vaadin.server.ThemeResource;
-import com.vaadin.ui.Grid;
-import com.vaadin.ui.UI;
-import com.vaadin.ui.components.grid.renderers.ImageRenderer;
-
-import elemental.json.JsonObject;
-import elemental.json.JsonValue;
-
-public class ImageRendererTest {
-
-    private ImageRenderer renderer;
-
-    @Before
-    public void setUp() {
-        UI mockUI = EasyMock.createNiceMock(UI.class);
-        EasyMock.replay(mockUI);
-
-        Grid grid = new Grid();
-        grid.setParent(mockUI);
-
-        renderer = new ImageRenderer();
-        renderer.setParent(grid);
-    }
-
-    @Test
-    public void testThemeResource() {
-        JsonValue v = renderer.encode(new ThemeResource("foo.png"));
-        assertEquals("theme://foo.png", getUrl(v));
-    }
-
-    @Test
-    public void testExternalResource() {
-        JsonValue v = renderer.encode(new ExternalResource(
-                "http://example.com/foo.png"));
-        assertEquals("http://example.com/foo.png", getUrl(v));
-    }
-
-    @Test(expected = IllegalArgumentException.class)
-    public void testFileResource() {
-        renderer.encode(new FileResource(new File("/tmp/foo.png")));
-    }
-
-    @Test(expected = IllegalArgumentException.class)
-    public void testClassResource() {
-        renderer.encode(new ClassResource("img/foo.png"));
-    }
-
-    @Test(expected = IllegalArgumentException.class)
-    public void testFontIcon() {
-        renderer.encode(FontAwesome.AMBULANCE);
-    }
-
-    private String getUrl(JsonValue v) {
-        return ((JsonObject) v).get("uRL").asString();
-    }
-}
diff --git a/server/tests/src/com/vaadin/tests/server/component/grid/RendererTest.java b/server/tests/src/com/vaadin/tests/server/component/grid/RendererTest.java
deleted file mode 100644 (file)
index c2779bf..0000000
+++ /dev/null
@@ -1,209 +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.tests.server.component.grid;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-
-import java.util.Locale;
-
-import org.easymock.EasyMock;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.vaadin.data.Item;
-import com.vaadin.data.RpcDataProviderExtension;
-import com.vaadin.data.util.IndexedContainer;
-import com.vaadin.data.util.converter.Converter;
-import com.vaadin.data.util.converter.StringToIntegerConverter;
-import com.vaadin.server.VaadinSession;
-import com.vaadin.tests.util.AlwaysLockedVaadinSession;
-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.components.grid.renderers.TextRenderer;
-
-import elemental.json.JsonValue;
-
-public class RendererTest {
-
-    private static class TestBean {
-        int i = 42;
-    }
-
-    private static class ExtendedBean extends TestBean {
-        float f = 3.14f;
-    }
-
-    private static class TestRenderer extends TextRenderer {
-        @Override
-        public JsonValue encode(String value) {
-            return super.encode("renderer(" + value + ")");
-        }
-    }
-
-    private static class TestConverter implements Converter<String, TestBean> {
-
-        @Override
-        public TestBean convertToModel(String value,
-                Class<? extends TestBean> targetType, Locale locale)
-                throws ConversionException {
-            return null;
-        }
-
-        @Override
-        public String convertToPresentation(TestBean value,
-                Class<? extends String> targetType, Locale locale)
-                throws ConversionException {
-            if (value instanceof ExtendedBean) {
-                return "ExtendedBean(" + value.i + ", "
-                        + ((ExtendedBean) value).f + ")";
-            } else {
-                return "TestBean(" + value.i + ")";
-            }
-        }
-
-        @Override
-        public Class<TestBean> getModelType() {
-            return TestBean.class;
-        }
-
-        @Override
-        public Class<String> getPresentationType() {
-            return String.class;
-        }
-    }
-
-    private Grid grid;
-
-    private Column foo;
-    private Column bar;
-    private Column baz;
-    private Column bah;
-
-    @Before
-    public void setUp() {
-        VaadinSession.setCurrent(new AlwaysLockedVaadinSession(null));
-
-        IndexedContainer c = new IndexedContainer();
-
-        c.addContainerProperty("foo", Integer.class, 0);
-        c.addContainerProperty("bar", String.class, "");
-        c.addContainerProperty("baz", TestBean.class, null);
-        c.addContainerProperty("bah", ExtendedBean.class, null);
-
-        Object id = c.addItem();
-        Item item = c.getItem(id);
-        item.getItemProperty("foo").setValue(123);
-        item.getItemProperty("bar").setValue("321");
-        item.getItemProperty("baz").setValue(new TestBean());
-        item.getItemProperty("bah").setValue(new ExtendedBean());
-
-        UI ui = EasyMock.createNiceMock(UI.class);
-        ConnectorTracker ct = EasyMock.createNiceMock(ConnectorTracker.class);
-        EasyMock.expect(ui.getConnectorTracker()).andReturn(ct).anyTimes();
-        EasyMock.replay(ui, ct);
-
-        grid = new Grid(c);
-        grid.setParent(ui);
-
-        foo = grid.getColumn("foo");
-        bar = grid.getColumn("bar");
-        baz = grid.getColumn("baz");
-        bah = grid.getColumn("bah");
-    }
-
-    @Test
-    public void testDefaultRendererAndConverter() throws Exception {
-        assertSame(TextRenderer.class, foo.getRenderer().getClass());
-        assertSame(StringToIntegerConverter.class, foo.getConverter()
-                .getClass());
-
-        assertSame(TextRenderer.class, bar.getRenderer().getClass());
-        // String->String; converter not needed
-        assertNull(bar.getConverter());
-
-        assertSame(TextRenderer.class, baz.getRenderer().getClass());
-        // MyBean->String; converter not found
-        assertNull(baz.getConverter());
-    }
-
-    @Test
-    public void testFindCompatibleConverter() throws Exception {
-        foo.setRenderer(renderer());
-        assertSame(StringToIntegerConverter.class, foo.getConverter()
-                .getClass());
-
-        bar.setRenderer(renderer());
-        assertNull(bar.getConverter());
-    }
-
-    @Test(expected = IllegalArgumentException.class)
-    public void testCannotFindConverter() {
-        baz.setRenderer(renderer());
-    }
-
-    @Test
-    public void testExplicitConverter() throws Exception {
-        baz.setRenderer(renderer(), converter());
-        bah.setRenderer(renderer(), converter());
-    }
-
-    @Test
-    public void testEncoding() throws Exception {
-        assertEquals("42", render(foo, 42).asString());
-        foo.setRenderer(renderer());
-        assertEquals("renderer(42)", render(foo, 42).asString());
-
-        assertEquals("2.72", render(bar, "2.72").asString());
-        bar.setRenderer(new TestRenderer());
-        assertEquals("renderer(2.72)", render(bar, "2.72").asString());
-    }
-
-    @Test
-    public void testEncodingWithoutConverter() throws Exception {
-        assertEquals("", render(baz, new TestBean()).asString());
-    }
-
-    @Test
-    public void testBeanEncoding() throws Exception {
-        baz.setRenderer(renderer(), converter());
-        bah.setRenderer(renderer(), converter());
-
-        assertEquals("renderer(TestBean(42))", render(baz, new TestBean())
-                .asString());
-        assertEquals("renderer(ExtendedBean(42, 3.14))",
-                render(baz, new ExtendedBean()).asString());
-
-        assertEquals("renderer(ExtendedBean(42, 3.14))",
-                render(bah, new ExtendedBean()).asString());
-    }
-
-    private TestConverter converter() {
-        return new TestConverter();
-    }
-
-    private TestRenderer renderer() {
-        return new TestRenderer();
-    }
-
-    private JsonValue render(Column column, Object value) {
-        return RpcDataProviderExtension.encodeValue(value,
-                column.getRenderer(), column.getConverter(), grid.getLocale());
-    }
-}
diff --git a/server/tests/src/com/vaadin/tests/server/renderer/ImageRendererTest.java b/server/tests/src/com/vaadin/tests/server/renderer/ImageRendererTest.java
new file mode 100644 (file)
index 0000000..08f0452
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * 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.server.renderer;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.vaadin.server.ClassResource;
+import com.vaadin.server.ExternalResource;
+import com.vaadin.server.FileResource;
+import com.vaadin.server.FontAwesome;
+import com.vaadin.server.ThemeResource;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.UI;
+import com.vaadin.ui.renderer.ImageRenderer;
+
+import elemental.json.JsonObject;
+import elemental.json.JsonValue;
+
+public class ImageRendererTest {
+
+    private ImageRenderer renderer;
+
+    @Before
+    public void setUp() {
+        UI mockUI = EasyMock.createNiceMock(UI.class);
+        EasyMock.replay(mockUI);
+
+        Grid grid = new Grid();
+        grid.setParent(mockUI);
+
+        renderer = new ImageRenderer();
+        renderer.setParent(grid);
+    }
+
+    @Test
+    public void testThemeResource() {
+        JsonValue v = renderer.encode(new ThemeResource("foo.png"));
+        assertEquals("theme://foo.png", getUrl(v));
+    }
+
+    @Test
+    public void testExternalResource() {
+        JsonValue v = renderer.encode(new ExternalResource(
+                "http://example.com/foo.png"));
+        assertEquals("http://example.com/foo.png", getUrl(v));
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testFileResource() {
+        renderer.encode(new FileResource(new File("/tmp/foo.png")));
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testClassResource() {
+        renderer.encode(new ClassResource("img/foo.png"));
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testFontIcon() {
+        renderer.encode(FontAwesome.AMBULANCE);
+    }
+
+    private String getUrl(JsonValue v) {
+        return ((JsonObject) v).get("uRL").asString();
+    }
+}
diff --git a/server/tests/src/com/vaadin/tests/server/renderer/RendererTest.java b/server/tests/src/com/vaadin/tests/server/renderer/RendererTest.java
new file mode 100644 (file)
index 0000000..464d409
--- /dev/null
@@ -0,0 +1,209 @@
+/*
+ * 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.server.renderer;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+
+import java.util.Locale;
+
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.vaadin.data.Item;
+import com.vaadin.data.RpcDataProviderExtension;
+import com.vaadin.data.util.IndexedContainer;
+import com.vaadin.data.util.converter.Converter;
+import com.vaadin.data.util.converter.StringToIntegerConverter;
+import com.vaadin.server.VaadinSession;
+import com.vaadin.tests.util.AlwaysLockedVaadinSession;
+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.TextRenderer;
+
+import elemental.json.JsonValue;
+
+public class RendererTest {
+
+    private static class TestBean {
+        int i = 42;
+    }
+
+    private static class ExtendedBean extends TestBean {
+        float f = 3.14f;
+    }
+
+    private static class TestRenderer extends TextRenderer {
+        @Override
+        public JsonValue encode(String value) {
+            return super.encode("renderer(" + value + ")");
+        }
+    }
+
+    private static class TestConverter implements Converter<String, TestBean> {
+
+        @Override
+        public TestBean convertToModel(String value,
+                Class<? extends TestBean> targetType, Locale locale)
+                throws ConversionException {
+            return null;
+        }
+
+        @Override
+        public String convertToPresentation(TestBean value,
+                Class<? extends String> targetType, Locale locale)
+                throws ConversionException {
+            if (value instanceof ExtendedBean) {
+                return "ExtendedBean(" + value.i + ", "
+                        + ((ExtendedBean) value).f + ")";
+            } else {
+                return "TestBean(" + value.i + ")";
+            }
+        }
+
+        @Override
+        public Class<TestBean> getModelType() {
+            return TestBean.class;
+        }
+
+        @Override
+        public Class<String> getPresentationType() {
+            return String.class;
+        }
+    }
+
+    private Grid grid;
+
+    private Column foo;
+    private Column bar;
+    private Column baz;
+    private Column bah;
+
+    @Before
+    public void setUp() {
+        VaadinSession.setCurrent(new AlwaysLockedVaadinSession(null));
+
+        IndexedContainer c = new IndexedContainer();
+
+        c.addContainerProperty("foo", Integer.class, 0);
+        c.addContainerProperty("bar", String.class, "");
+        c.addContainerProperty("baz", TestBean.class, null);
+        c.addContainerProperty("bah", ExtendedBean.class, null);
+
+        Object id = c.addItem();
+        Item item = c.getItem(id);
+        item.getItemProperty("foo").setValue(123);
+        item.getItemProperty("bar").setValue("321");
+        item.getItemProperty("baz").setValue(new TestBean());
+        item.getItemProperty("bah").setValue(new ExtendedBean());
+
+        UI ui = EasyMock.createNiceMock(UI.class);
+        ConnectorTracker ct = EasyMock.createNiceMock(ConnectorTracker.class);
+        EasyMock.expect(ui.getConnectorTracker()).andReturn(ct).anyTimes();
+        EasyMock.replay(ui, ct);
+
+        grid = new Grid(c);
+        grid.setParent(ui);
+
+        foo = grid.getColumn("foo");
+        bar = grid.getColumn("bar");
+        baz = grid.getColumn("baz");
+        bah = grid.getColumn("bah");
+    }
+
+    @Test
+    public void testDefaultRendererAndConverter() throws Exception {
+        assertSame(TextRenderer.class, foo.getRenderer().getClass());
+        assertSame(StringToIntegerConverter.class, foo.getConverter()
+                .getClass());
+
+        assertSame(TextRenderer.class, bar.getRenderer().getClass());
+        // String->String; converter not needed
+        assertNull(bar.getConverter());
+
+        assertSame(TextRenderer.class, baz.getRenderer().getClass());
+        // MyBean->String; converter not found
+        assertNull(baz.getConverter());
+    }
+
+    @Test
+    public void testFindCompatibleConverter() throws Exception {
+        foo.setRenderer(renderer());
+        assertSame(StringToIntegerConverter.class, foo.getConverter()
+                .getClass());
+
+        bar.setRenderer(renderer());
+        assertNull(bar.getConverter());
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testCannotFindConverter() {
+        baz.setRenderer(renderer());
+    }
+
+    @Test
+    public void testExplicitConverter() throws Exception {
+        baz.setRenderer(renderer(), converter());
+        bah.setRenderer(renderer(), converter());
+    }
+
+    @Test
+    public void testEncoding() throws Exception {
+        assertEquals("42", render(foo, 42).asString());
+        foo.setRenderer(renderer());
+        assertEquals("renderer(42)", render(foo, 42).asString());
+
+        assertEquals("2.72", render(bar, "2.72").asString());
+        bar.setRenderer(new TestRenderer());
+        assertEquals("renderer(2.72)", render(bar, "2.72").asString());
+    }
+
+    @Test
+    public void testEncodingWithoutConverter() throws Exception {
+        assertEquals("", render(baz, new TestBean()).asString());
+    }
+
+    @Test
+    public void testBeanEncoding() throws Exception {
+        baz.setRenderer(renderer(), converter());
+        bah.setRenderer(renderer(), converter());
+
+        assertEquals("renderer(TestBean(42))", render(baz, new TestBean())
+                .asString());
+        assertEquals("renderer(ExtendedBean(42, 3.14))",
+                render(baz, new ExtendedBean()).asString());
+
+        assertEquals("renderer(ExtendedBean(42, 3.14))",
+                render(bah, new ExtendedBean()).asString());
+    }
+
+    private TestConverter converter() {
+        return new TestConverter();
+    }
+
+    private TestRenderer renderer() {
+        return new TestRenderer();
+    }
+
+    private JsonValue render(Column column, Object value) {
+        return RpcDataProviderExtension.encodeValue(value,
+                column.getRenderer(), column.getConverter(), grid.getLocale());
+    }
+}
index 4c23c3bcab000f8c0aabf677d69cf0d1f3abd45c..f61a39a1f27fb779cd502cdfb6562f3a98cd60b8 100644 (file)
@@ -25,7 +25,7 @@ import com.vaadin.ui.Button.ClickEvent;
 import com.vaadin.ui.Grid;
 import com.vaadin.ui.Grid.FooterRow;
 import com.vaadin.ui.Grid.HeaderRow;
-import com.vaadin.ui.components.grid.renderers.NumberRenderer;
+import com.vaadin.ui.renderer.NumberRenderer;
 
 public class GridColspans extends AbstractTestUI {
 
index 6c61846e0e74b17451601da0e9ad9d8c562e2bee..5d9f4285a10594ca46409a25e63143cede6ba709 100644 (file)
@@ -22,7 +22,7 @@ import com.vaadin.tests.components.AbstractTestUI;
 import com.vaadin.ui.Grid;
 import com.vaadin.ui.Grid.Column;
 import com.vaadin.ui.Grid.SelectionMode;
-import com.vaadin.ui.components.grid.renderers.HtmlRenderer;
+import com.vaadin.ui.renderer.HtmlRenderer;
 
 public class GridColumnAutoWidth extends AbstractTestUI {
     @Override
index 8c6037938c2285998067630a6b097861de9130ab..de6fb30e1c9610c2a2bc31430004891a7208fb75 100644 (file)
@@ -25,11 +25,11 @@ import com.vaadin.ui.Button;
 import com.vaadin.ui.Button.ClickEvent;
 import com.vaadin.ui.Grid;
 import com.vaadin.ui.Grid.SelectionMode;
-import com.vaadin.ui.components.grid.renderers.ButtonRenderer;
-import com.vaadin.ui.components.grid.renderers.ClickableRenderer.RendererClickEvent;
-import com.vaadin.ui.components.grid.renderers.ClickableRenderer.RendererClickListener;
-import com.vaadin.ui.components.grid.renderers.ImageRenderer;
-import com.vaadin.ui.components.grid.renderers.ProgressBarRenderer;
+import com.vaadin.ui.renderer.ButtonRenderer;
+import com.vaadin.ui.renderer.ClickableRenderer.RendererClickEvent;
+import com.vaadin.ui.renderer.ClickableRenderer.RendererClickListener;
+import com.vaadin.ui.renderer.ImageRenderer;
+import com.vaadin.ui.renderer.ProgressBarRenderer;
 
 public class WidgetRenderers extends AbstractTestUI {
 
index f03a1ae607d61d60f8fa3cb0810f47b92cf44183..88579154dc6f2293585bb4e487b66d821987bd5b 100644 (file)
@@ -46,13 +46,12 @@ import com.vaadin.ui.Grid.HeaderRow;
 import com.vaadin.ui.Grid.SelectionMode;
 import com.vaadin.ui.components.grid.SortOrderChangeEvent;
 import com.vaadin.ui.components.grid.SortOrderChangeListener;
-import com.vaadin.ui.components.grid.renderers.DateRenderer;
-import com.vaadin.ui.components.grid.renderers.HtmlRenderer;
-import com.vaadin.ui.components.grid.renderers.NumberRenderer;
 import com.vaadin.ui.components.grid.selection.MultiSelectionModel;
-import com.vaadin.ui.components.grid.selection.SelectionModel;
 import com.vaadin.ui.components.grid.sort.Sort;
 import com.vaadin.ui.components.grid.sort.SortOrder;
+import com.vaadin.ui.renderer.DateRenderer;
+import com.vaadin.ui.renderer.HtmlRenderer;
+import com.vaadin.ui.renderer.NumberRenderer;
 
 /**
  * Tests the basic features like columns, footers and headers
@@ -267,8 +266,8 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
                             grid.setSelectionMode(SelectionMode.MULTI);
                         }
 
-                        ((MultiSelectionModel) grid.getSelectionModel()).setSelectionLimit(limit
-                                .intValue());
+                        ((MultiSelectionModel) grid.getSelectionModel())
+                                .setSelectionLimit(limit.intValue());
                     }
                 });