--- /dev/null
+/*
+ * Copyright 2000-2016 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.google.web.bindery.event.shared.HandlerRegistration;
+import com.vaadin.client.renderers.ButtonRenderer;
+import com.vaadin.client.renderers.ClickableRenderer.RendererClickHandler;
+import com.vaadin.shared.ui.Connect;
+
+import elemental.json.JsonObject;
+
+/**
+ * A connector for {@link ButtonRenderer}.
+ *
+ * @since 7.4
+ * @author Vaadin Ltd
+ */
+@Connect(com.vaadin.ui.renderers.ButtonRenderer.class)
+public class ButtonRendererConnector
+ extends ClickableRendererConnector<String> {
+
+ @Override
+ public ButtonRenderer getRenderer() {
+ return (ButtonRenderer) super.getRenderer();
+ }
+
+ @Override
+ protected HandlerRegistration addClickHandler(
+ RendererClickHandler<JsonObject> handler) {
+ return getRenderer().addClickHandler(handler);
+ }
+}
--- /dev/null
+/*
+ * Copyright 2000-2016 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.google.web.bindery.event.shared.HandlerRegistration;
+import com.vaadin.client.MouseEventDetailsBuilder;
+import com.vaadin.client.connectors.grid.AbstractGridRendererConnector;
+import com.vaadin.client.renderers.ClickableRenderer.RendererClickEvent;
+import com.vaadin.client.renderers.ClickableRenderer.RendererClickHandler;
+import com.vaadin.shared.ui.grid.renderers.RendererClickRpc;
+
+import elemental.json.JsonObject;
+
+/**
+ * An abstract base class for {@link ClickableRenderer} connectors.
+ *
+ * @param <T>
+ * the presentation type of the renderer
+ *
+ * @since 7.4
+ * @author Vaadin Ltd
+ */
+public abstract class ClickableRendererConnector<T>
+ extends AbstractGridRendererConnector<T> {
+
+ private HandlerRegistration clickRegistration;
+
+ @Override
+ protected void init() {
+ clickRegistration = addClickHandler(
+ new RendererClickHandler<JsonObject>() {
+ @Override
+ public void onClick(RendererClickEvent<JsonObject> event) {
+ getRpcProxy(RendererClickRpc.class).click(
+ getRowKey(event.getCell().getRow()),
+ getColumnId(event.getCell().getColumn()),
+ MouseEventDetailsBuilder.buildMouseEventDetails(
+ event.getNativeEvent()));
+ }
+ });
+ }
+
+ @Override
+ public void onUnregister() {
+ clickRegistration.removeHandler();
+ }
+
+ protected abstract HandlerRegistration addClickHandler(
+ RendererClickHandler<JsonObject> handler);
+}
--- /dev/null
+/*
+ * Copyright 2000-2016 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.google.web.bindery.event.shared.HandlerRegistration;
+import com.vaadin.client.communication.JsonDecoder;
+import com.vaadin.client.metadata.TypeDataStore;
+import com.vaadin.client.renderers.ClickableRenderer.RendererClickHandler;
+import com.vaadin.client.renderers.ImageRenderer;
+import com.vaadin.shared.communication.URLReference;
+import com.vaadin.shared.ui.Connect;
+
+import elemental.json.JsonObject;
+import elemental.json.JsonValue;
+
+/**
+ * A connector for {@link ImageRenderer}.
+ *
+ * @since 7.4
+ * @author Vaadin Ltd
+ */
+@Connect(com.vaadin.ui.renderers.ImageRenderer.class)
+public class ImageRendererConnector extends ClickableRendererConnector<String> {
+
+ @Override
+ public ImageRenderer getRenderer() {
+ return (ImageRenderer) super.getRenderer();
+ }
+
+ @Override
+ public String decode(JsonValue value) {
+ URLReference reference = (URLReference) JsonDecoder.decodeValue(
+ TypeDataStore.getType(URLReference.class), value, null,
+ getConnection());
+
+ return reference != null ? reference.getURL() : null;
+ }
+
+ @Override
+ protected HandlerRegistration addClickHandler(
+ RendererClickHandler<JsonObject> handler) {
+ return getRenderer().addClickHandler(handler);
+ }
+}
package com.vaadin.client.connectors.grid;
+import com.vaadin.client.ServerConnector;
import com.vaadin.client.connectors.AbstractRendererConnector;
+import com.vaadin.client.widgets.Grid.Column;
+import com.vaadin.shared.data.DataCommunicatorConstants;
+
+import elemental.json.JsonObject;
/**
* An abstract base class for renderer connectors. A renderer connector is used
*/
public abstract class AbstractGridRendererConnector<T>
extends AbstractRendererConnector<T> {
- // getRowKey and getColumnId will be needed here later on
+
+ /**
+ * Gets the row key for a row object.
+ * <p>
+ * In case this renderer wants be able to identify a row in such a way that
+ * the server also understands it, the row key is used for that. Rows are
+ * identified by unified keys between the client and the server.
+ *
+ * @param row
+ * the row object
+ * @return the row key for the given row
+ */
+ protected String getRowKey(JsonObject row) {
+ return row.getString(DataCommunicatorConstants.KEY);
+ }
+
+ /**
+ * Gets the column id for a column.
+ * <p>
+ * In case this renderer wants be able to identify a column in such a way
+ * that the server also understands it, the column id is used for that.
+ * Columns are identified by unified ids between the client and the server.
+ *
+ * @param column
+ * the column object
+ * @return the column id for the given column
+ */
+ protected String getColumnId(Column<?, JsonObject> column) {
+ final ServerConnector parent = getParent();
+ if (parent instanceof ColumnConnector) {
+ final ServerConnector parentGrid = parent.getParent();
+ if (parentGrid instanceof GridConnector) {
+ return ((GridConnector) parentGrid).getColumnId(column);
+ }
+ }
+ throw new IllegalStateException(
+ "Renderers can only be used with a Grid.");
+ }
}
private SpaceSelectHandler<JsonObject> spaceSelectHandler;
private ClickSelectHandler<JsonObject> clickSelectHandler;
+ /**
+ * Gets the string identifier of a {@link Column} in this grid.
+ *
+ * @param column
+ * the column for which the identifier is to be retrieved for
+ * @return the string identifying the given column in this grid
+ */
+ public String getColumnId(Grid.Column<?, ?> column) {
+ return columnToIdMap.get(column);
+ }
+
@Override
@SuppressWarnings("unchecked")
public Grid<JsonObject> getWidget() {
@Override
public void setChildComponents(List<ComponentConnector> children) {
- this.childComponents = children;
+ childComponents = children;
}
import com.vaadin.shared.ui.grid.GridServerRpc;
import com.vaadin.shared.ui.grid.GridState;
import com.vaadin.shared.ui.grid.HeightMode;
+import com.vaadin.ui.renderers.AbstractRenderer;
import com.vaadin.ui.renderers.Renderer;
import com.vaadin.ui.renderers.TextRenderer;
}
/**
- * Adds a new column to this {@link Grid} with given header caption,
+ * Adds a new column to this {@link Grid} with given header caption, typed
* renderer and value provider.
*
* @param caption
* the value provider
* @param renderer
* the column value class
+ * @param <T>
+ * the type of this grid
* @param <V>
* the column value type
*
* @return the new column
+ *
+ * @see {@link AbstractRenderer}
*/
public <V> Column<T, V> addColumn(String caption,
- Function<T, ? extends V> valueProvider, Renderer<V> renderer) {
- Column<T, V> c = new Column<>(caption, valueProvider, renderer);
+ Function<T, ? extends V> valueProvider,
+ AbstractRenderer<? super T, V> renderer) {
+ Column<T, V> column = new Column<>(caption, valueProvider, renderer);
- c.extend(this);
- c.setId(columnKeys.key(c));
- columnSet.add(c);
- addDataGenerator(c);
+ column.extend(this);
+ column.setId(columnKeys.key(column));
+ columnSet.add(column);
+ addDataGenerator(column);
- return c;
+ return column;
}
/**
return Collections.unmodifiableSet(columnSet);
}
+ /**
+ * Gets a {@link Column} of this grid by its identifying string.
+ *
+ * @param columnId
+ * the identifier of the column to get
+ * @return the column corresponding to the given column id
+ */
+ public Column<T, ?> getColumn(String columnId) {
+ return columnKeys.get(columnId);
+ }
+
@Override
public Iterator<Component> iterator() {
return Collections.unmodifiableSet(extensionComponents).iterator();
import com.vaadin.server.AbstractClientConnector;
import com.vaadin.server.AbstractExtension;
import com.vaadin.server.JsonCodec;
+import com.vaadin.ui.Grid;
import com.vaadin.ui.Grid.Column;
+import com.vaadin.ui.renderers.ClickableRenderer.RendererClickEvent;
import elemental.json.JsonValue;
/**
* An abstract base class for server-side
- * {@link com.vaadin.ui.renderers.Renderer Grid renderers}. This class currently
- * extends the AbstractExtension superclass, but this fact should be regarded as
- * an implementation detail and subject to change in a future major or minor
- * Vaadin version.
+ * {@link com.vaadin.ui.renderers.Renderer Grid renderers}.
+ *
+ * <p>
+ * This class currently extends the AbstractExtension superclass, but this fact
+ * should be regarded as an implementation detail and subject to change in a
+ * future major or minor Vaadin version.
*
* @param <T>
+ * the grid type this renderer can be attached to
+ * @param <V>
* the type this renderer knows how to present
*/
-public abstract class AbstractRenderer<T> extends AbstractExtension
- implements Renderer<T> {
- private final Class<T> presentationType;
+public abstract class AbstractRenderer<T, V> extends AbstractExtension
+ implements Renderer<V> {
+ private final Class<V> presentationType;
private final String nullRepresentation;
* value in case the actual cell value is <code>null</code>. May
* be <code>null</code>.
*/
- protected AbstractRenderer(Class<T> presentationType,
+ protected AbstractRenderer(Class<V> presentationType,
String nullRepresentation) {
Objects.requireNonNull(presentationType,
"Presentation type cannot be null");
* the data type that this renderer displays, not
* <code>null</code>
*/
- protected AbstractRenderer(Class<T> presentationType) {
+ protected AbstractRenderer(Class<V> presentationType) {
this(presentationType, null);
}
}
@Override
- public Class<T> getPresentationType() {
+ public Class<V> getPresentationType() {
return presentationType;
}
@Override
- public JsonValue encode(T value) {
+ public JsonValue encode(V value) {
if (value == null) {
return encode(getNullRepresentation(), String.class);
} else {
.encode(value, null, type, getUI().getConnectorTracker())
.getEncodedValue();
}
-}
\ No newline at end of file
+
+ /**
+ * Gets the {@link Grid} this renderer is attached to. Used internally for
+ * indicating the source grid of possible events emitted by this renderer,
+ * such as {@link RendererClickEvent}s.
+ *
+ * @return the grid this renderer is attached to or null if unattached
+ */
+ @SuppressWarnings("unchecked")
+ protected Grid<T> getParentGrid() {
+ if (super.getParent() == null) {
+ return null;
+ }
+ return (Grid<T>) super.getParent().getParent();
+ }
+}
--- /dev/null
+/*
+ * Copyright 2000-2016 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.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 7.4
+ * @author Vaadin Ltd
+ */
+public class ButtonRenderer<T> extends ClickableRenderer<T, String> {
+
+ /**
+ * Creates a new button renderer.
+ *
+ * @param nullRepresentation
+ * the textual representation of {@code null} value
+ */
+ public ButtonRenderer(String nullRepresentation) {
+ super(String.class, nullRepresentation);
+ }
+
+ /**
+ * Creates a new button renderer and adds the given click listener to it.
+ *
+ * @param listener
+ * the click listener to register
+ * @param nullRepresentation
+ * the textual representation of {@code null} value
+ */
+ public ButtonRenderer(RendererClickListener<T> listener,
+ String nullRepresentation) {
+ this(nullRepresentation);
+ addClickListener(listener);
+ }
+
+ /**
+ * Creates a new button renderer.
+ */
+ public ButtonRenderer() {
+ this("");
+ }
+
+ /**
+ * Creates a new button renderer and adds the given click listener to it.
+ *
+ * @param listener
+ * the click listener to register
+ */
+ public ButtonRenderer(RendererClickListener<T> listener) {
+ this(listener, "");
+ }
+
+ @Override
+ public String getNullRepresentation() {
+ return super.getNullRepresentation();
+ }
+
+}
--- /dev/null
+/*
+ * Copyright 2000-2016 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.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.Column;
+import com.vaadin.util.ReflectTools;
+
+/**
+ * An abstract superclass for {@link Renderer}s 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 of the parent {@link Grid}
+ * @param <V>
+ * the type presented by the renderer
+ *
+ * @since 7.4
+ * @author Vaadin Ltd
+ */
+public abstract class ClickableRenderer<T, V>
+ extends AbstractRenderer<T, V> {
+
+ /**
+ * An interface for listening to {@link RendererClickEvent renderer click
+ * events}.
+ *
+ * @see {@link ButtonRenderer#addClickListener(RendererClickListener)}
+ */
+ public interface RendererClickListener<T> 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<T> event);
+ }
+
+ /**
+ * An event fired when a clickable widget rendered by a ClickableRenderer is
+ * clicked.
+ *
+ * @param <T>
+ * the item type associated with this click event
+ */
+ public static class RendererClickEvent<T> extends ClickEvent {
+
+ private T item;
+ private Column column;
+
+ protected RendererClickEvent(Grid<T> source, T item, Column column,
+ MouseEventDetails mouseEventDetails) {
+ super(source, mouseEventDetails);
+ this.item = item;
+ this.column = column;
+ }
+
+ /**
+ * Returns the item of the row where the click event originated.
+ *
+ * @return the item of the clicked row
+ */
+ public T getItem() {
+ return item;
+ }
+
+ /**
+ * Returns the {@link Column} where the click event originated.
+ *
+ * @return the column of the click event
+ */
+ public Column getColumn() {
+ return column;
+ }
+ }
+
+ /**
+ * Creates a new clickable renderer with the given presentation type. No
+ * null representation will be used.
+ *
+ * @param presentationType
+ * the data type that this renderer displays, not
+ * <code>null</code>
+ */
+ protected ClickableRenderer(Class<V> presentationType) {
+ this(presentationType, null);
+ }
+
+ /**
+ * Creates a new clickable renderer with the given presentation type and
+ * null representation.
+ *
+ * @param presentationType
+ * the data type that this renderer displays, not
+ * <code>null</code>
+ * @param nullRepresentation
+ * a string that will be sent to the client instead of a regular
+ * value in case the actual cell value is <code>null</code>. May
+ * be <code>null</code>.
+ */
+ protected ClickableRenderer(Class<V> presentationType,
+ String nullRepresentation) {
+ super(presentationType, nullRepresentation);
+ registerRpc(new RendererClickRpc() {
+
+ @Override
+ public void click(String rowKey, String columnId,
+ MouseEventDetails mouseDetails) {
+
+ Grid<T> grid = getParentGrid();
+ T item = grid.getDataCommunicator().getKeyMapper().get(rowKey);
+ Column column = grid.getColumn(columnId);
+
+ fireEvent(new RendererClickEvent<T>(grid, item, column,
+ 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<T> 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<T> listener) {
+ removeListener(RendererClickEvent.class, listener);
+ }
+}
* @since 7.4
* @author Vaadin Ltd
*/
-public class DateRenderer extends AbstractRenderer<Date> {
+public class DateRenderer extends AbstractRenderer<Object, Date> {
private final Locale locale;
private final String formatString;
private final DateFormat dateFormat;
* @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>
+ * "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, "");
* @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>
+ * "http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html#syntax">
+ * Format String Syntax</a>
*/
public DateRenderer(String formatString, String nullRepresentation)
throws IllegalArgumentException {
* @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>
+ * "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 {
* @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>
+ * "http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html#syntax">
+ * Format String Syntax</a>
*/
public DateRenderer(String formatString, Locale locale,
String nullRepresentation) throws IllegalArgumentException {
* @author Vaadin Ltd
* @since 7.4
*/
-public class HtmlRenderer extends AbstractRenderer<String> {
+public class HtmlRenderer extends AbstractRenderer<Object, String> {
/**
* Creates a new HTML renderer.
*
--- /dev/null
+/*
+ * Copyright 2000-2016 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.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.
+ *
+ * @param <T>
+ * the type of the grid this renderer can be attached to
+ *
+ * @since 7.4
+ * @author Vaadin Ltd
+ */
+public class ImageRenderer<T> extends ClickableRenderer<T, Resource> {
+
+ /**
+ * Creates a new image renderer.
+ */
+ public ImageRenderer() {
+ super(Resource.class, null);
+ }
+
+ /**
+ * Creates a new image renderer and adds the given click listener to it.
+ *
+ * @param listener
+ * the click listener to register
+ */
+ public ImageRenderer(RendererClickListener<T> listener) {
+ this();
+ addClickListener(listener);
+ }
+
+ @Override
+ public JsonValue encode(Resource resource) {
+ if (!(resource == null || 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);
+ }
+}
* @since 7.4
* @author Vaadin Ltd
*/
-public class NumberRenderer extends AbstractRenderer<Number> {
+public class NumberRenderer extends AbstractRenderer<Object, Number> {
private final Locale locale;
private final NumberFormat numberFormat;
private final String formatString;
* @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>
+ * "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(), "");
* @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>
+ * "http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html#syntax">
+ * Format String Syntax</a>
*/
public NumberRenderer(String formatString, Locale locale,
String nullRepresentation) {
* @author Vaadin Ltd
* @since 7.4
*/
-public class ProgressBarRenderer extends AbstractRenderer<Double> {
+public class ProgressBarRenderer extends AbstractRenderer<Object, Double> {
/**
* Creates a new text renderer
* @since 7.4
* @author Vaadin Ltd
*/
-public class TextRenderer extends AbstractRenderer<String> {
+public class TextRenderer extends AbstractRenderer<Object, String> {
/**
* Creates a new text renderer
--- /dev/null
+/*
+ * Copyright 2000-2016 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.shared.ui.grid.renderers;
+
+import com.vaadin.shared.MouseEventDetails;
+import com.vaadin.shared.communication.ServerRpc;
+
+/**
+ * RPC interface implemented by server side {@link ClickableRenderer}s to
+ * receive click events from their client side counterparts.
+ */
+public interface RendererClickRpc extends ServerRpc {
+ /**
+ * Called when a click event has occurred and there are server side
+ * listeners for the event.
+ *
+ * @param mouseDetails
+ * Details about the mouse when the event took place
+ */
+ public void click(String rowKey, String columnId,
+ MouseEventDetails mouseDetails);
+}
--- /dev/null
+package com.vaadin.tests.components.grid;
+
+import com.vaadin.server.ExternalResource;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.renderers.ButtonRenderer;
+import com.vaadin.ui.renderers.ImageRenderer;
+
+public class GridClickableRenderers extends AbstractTestUI {
+
+ private static class TestPOJO {
+ String testText;
+ String imageUrl;
+ String buttonText;
+
+ TestPOJO(String intValue, String imageUrl, String buttonText) {
+ testText = intValue;
+ this.imageUrl = imageUrl;
+ this.buttonText = buttonText;
+ }
+ }
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ Label valueDisplayLabel = new Label();
+ Grid<TestPOJO> grid = new Grid<>();
+ grid.addColumn("images", pojo -> new ExternalResource(pojo.imageUrl),
+ new ImageRenderer<>());
+ grid.addColumn("buttons", pojo -> pojo.buttonText, new ButtonRenderer<>(
+ event -> valueDisplayLabel.setValue(event.getItem().testText)));
+ grid.setItems(new TestPOJO("first button clicked", "", "button 1 text"),
+ new TestPOJO("second button clicked", "", "button 2 text"));
+ addComponents(valueDisplayLabel, grid);
+ }
+}
--- /dev/null
+/*
+ * Copyright 2000-2016 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.components.grid;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.testbench.elements.LabelElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class GridClickableRenderersTest extends MultiBrowserTest {
+
+ @Test
+ public void buttonAndImageRenderersPresent() {
+ openTestURL();
+
+ Assert.assertTrue(isElementPresent(By.className("v-nativebutton")));
+
+ Assert.assertTrue(isElementPresent(By.className("gwt-Image")));
+ }
+
+ @Test
+ public void buttonRendererReturnsCorrectItem() {
+ openTestURL();
+ WebElement firstButton = findElements(By.className("v-nativebutton"))
+ .get(0);
+ WebElement secondButton = findElements(By.className("v-nativebutton"))
+ .get(1);
+ LabelElement label = $(LabelElement.class).get(1);
+
+ firstButton.click();
+ Assert.assertEquals("first button clicked", label.getText());
+
+ secondButton.click();
+ Assert.assertEquals("second button clicked", label.getText());
+ }
+}