summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2014-12-18 16:20:46 +0200
committerArtur Signell <artur@vaadin.com>2014-12-18 16:20:46 +0200
commit7849971947f2bce16d5bbb34af8e3a662ef0fdc3 (patch)
tree9a58df2a21f71c96b45a5940c447fb09529d9e69 /server
parent4e27233dbc454981b7a2f8e33697589c371e3238 (diff)
parentb178104c75d99a34869eb10dedd73b67383c7374 (diff)
downloadvaadin-framework-7849971947f2bce16d5bbb34af8e3a662ef0fdc3.tar.gz
vaadin-framework-7849971947f2bce16d5bbb34af8e3a662ef0fdc3.zip
Merge remote-tracking branch 'origin/grid' into 7.4
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/ui/Grid.java28
-rw-r--r--server/src/com/vaadin/ui/renderer/ClickableRenderer.java24
2 files changed, 43 insertions, 9 deletions
diff --git a/server/src/com/vaadin/ui/Grid.java b/server/src/com/vaadin/ui/Grid.java
index 60df269f10..8aee5ac19e 100644
--- a/server/src/com/vaadin/ui/Grid.java
+++ b/server/src/com/vaadin/ui/Grid.java
@@ -2382,9 +2382,35 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
* @return the item id corresponding to {@code key}
*/
protected Object getItemId(String rowKey) {
+ return getParentGrid().getKeyMapper().getItemId(rowKey);
+ }
+
+ /**
+ * Gets the column for a column id.
+ * <p>
+ * An id is used to identify a particular column on both a server and a
+ * client. This method can be used to get the column for the column id
+ * that the client has sent.
+ *
+ * @param columnId
+ * the column id for which to retrieve a column
+ * @return the column corresponding to {@code columnId}
+ */
+ protected Column getColumn(String columnId) {
+ return getParentGrid().getColumnByColumnId(columnId);
+ }
+
+ /**
+ * Gets the parent Grid of the renderer.
+ *
+ * @return parent grid
+ * @throws IllegalStateException
+ * if parent is not Grid
+ */
+ protected Grid getParentGrid() {
if (getParent() instanceof Grid) {
Grid grid = (Grid) getParent();
- return grid.getKeyMapper().getItemId(rowKey);
+ return grid;
} else {
throw new IllegalStateException(
"Renderers can be used only with Grid");
diff --git a/server/src/com/vaadin/ui/renderer/ClickableRenderer.java b/server/src/com/vaadin/ui/renderer/ClickableRenderer.java
index 0d745ab29e..ef293c7e3c 100644
--- a/server/src/com/vaadin/ui/renderer/ClickableRenderer.java
+++ b/server/src/com/vaadin/ui/renderer/ClickableRenderer.java
@@ -23,6 +23,7 @@ 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.ui.Grid.Column;
import com.vaadin.util.ReflectTools;
/**
@@ -64,11 +65,13 @@ public class ClickableRenderer<T> extends AbstractRenderer<T> {
public static class RendererClickEvent extends ClickEvent {
private Object itemId;
+ private Column column;
- protected RendererClickEvent(Grid source, Object itemId,
+ protected RendererClickEvent(Grid source, Object itemId, Column column,
MouseEventDetails mouseEventDetails) {
super(source, mouseEventDetails);
this.itemId = itemId;
+ this.column = column;
}
/**
@@ -79,20 +82,25 @@ public class ClickableRenderer<T> extends AbstractRenderer<T> {
public Object getItemId() {
return itemId;
}
+
+ /**
+ * Returns the {@link Column} where the click event originated.
+ *
+ * @return the column of the click event
+ */
+ public Column getColumn() {
+ return column;
+ }
}
protected ClickableRenderer(Class<T> presentationType) {
super(presentationType);
registerRpc(new RendererClickRpc() {
@Override
- public void click(int row, int column,
+ public void click(String rowKey, String columnId,
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));
+ fireEvent(new RendererClickEvent(getParentGrid(),
+ getItemId(rowKey), getColumn(columnId), mouseDetails));
}
});
}