diff options
author | Teemu Suo-Anttila <teemusa@vaadin.com> | 2015-05-25 15:14:39 +0300 |
---|---|---|
committer | Teppo Kurki <teppo.kurki@vaadin.com> | 2015-05-27 05:44:51 +0000 |
commit | a95f757546892a855def121ec5ce5e5bda927a29 (patch) | |
tree | f789ec0c399c5edbf3965bf932d1ec502a10dc9a /client | |
parent | 0a7b430d50dc8d82e2ca23296381939a7f444846 (diff) | |
download | vaadin-framework-a95f757546892a855def121ec5ce5e5bda927a29.tar.gz vaadin-framework-a95f757546892a855def121ec5ce5e5bda927a29.zip |
Fix Grid client-side event support (#17986)
Added a public API to get an EventCellReference for the most recent
fired event. Also EventCellReference now contains information on Grid
section and some related helpers.
Change-Id: Ia8a166da6f322084d65f9b1cb242e22b0e66e53b
Diffstat (limited to 'client')
3 files changed, 90 insertions, 6 deletions
diff --git a/client/src/com/vaadin/client/renderers/ClickableRenderer.java b/client/src/com/vaadin/client/renderers/ClickableRenderer.java index f5368d31c9..83059f8f01 100644 --- a/client/src/com/vaadin/client/renderers/ClickableRenderer.java +++ b/client/src/com/vaadin/client/renderers/ClickableRenderer.java @@ -33,6 +33,7 @@ import com.vaadin.client.widget.grid.CellReference; import com.vaadin.client.widget.grid.EventCellReference; import com.vaadin.client.widgets.Escalator; import com.vaadin.client.widgets.Grid; +import com.vaadin.client.widgets.Grid.Section; /** * An abstract superclass for renderers that render clickable widgets. Click @@ -152,7 +153,9 @@ public abstract class ClickableRenderer<T, W extends Widget> extends Cell cell = container.getCell(e); EventCellReference<T> cellReference = new EventCellReference<T>( grid); - cellReference.set(cell); + // FIXME: Section is currently always body. Might be useful for the + // future to have an actual check. + cellReference.set(cell, Section.BODY); return cellReference; } diff --git a/client/src/com/vaadin/client/widget/grid/EventCellReference.java b/client/src/com/vaadin/client/widget/grid/EventCellReference.java index 7ca1d5de75..98878339d1 100644 --- a/client/src/com/vaadin/client/widget/grid/EventCellReference.java +++ b/client/src/com/vaadin/client/widget/grid/EventCellReference.java @@ -19,6 +19,7 @@ import com.google.gwt.dom.client.TableCellElement; import com.vaadin.client.widget.escalator.Cell; import com.vaadin.client.widgets.Grid; import com.vaadin.client.widgets.Grid.Column; +import com.vaadin.client.widgets.Grid.Section; /** * A data class which contains information which identifies a cell being the @@ -33,12 +34,11 @@ import com.vaadin.client.widgets.Grid.Column; */ public class EventCellReference<T> extends CellReference<T> { - private Grid<T> grid; + private Section section; private TableCellElement element; public EventCellReference(Grid<T> grid) { super(new RowReference<T>(grid)); - this.grid = grid; } /** @@ -47,22 +47,76 @@ public class EventCellReference<T> extends CellReference<T> { * @param targetCell * cell to point to */ - public void set(Cell targetCell) { + public void set(Cell targetCell, Section section) { + Grid<T> grid = getGrid(); int row = targetCell.getRow(); int columnIndexDOM = targetCell.getColumn(); Column<?, T> column = grid.getVisibleColumns().get(columnIndexDOM); + // Row objects only make sense for body section of Grid. + T rowObject; + if (section == Section.BODY) { + rowObject = grid.getDataSource().getRow(row); + } else { + rowObject = null; + } + // At least for now we don't need to have the actual TableRowElement // available. - getRowReference().set(row, grid.getDataSource().getRow(row), null); + getRowReference().set(row, rowObject, null); + int columnIndex = grid.getColumns().indexOf(column); set(columnIndexDOM, columnIndex, column); this.element = targetCell.getElement(); + this.section = section; } @Override public TableCellElement getElement() { return element; } + + /** + * Is the cell reference for a cell in the header of the Grid. + * + * @since + * @return <code>true</true> if referenced cell is in the header, + * <code>false</code> if not + */ + public boolean isHeader() { + return section == Section.HEADER; + } + + /** + * Is the cell reference for a cell in the body of the Grid. + * + * @since + * @return <code>true</true> if referenced cell is in the body, + * <code>false</code> if not + */ + public boolean isBody() { + return section == Section.BODY; + } + + /** + * Is the cell reference for a cell in the footer of the Grid. + * + * @since + * @return <code>true</true> if referenced cell is in the footer, + * <code>false</code> if not + */ + public boolean isFooter() { + return section == Section.FOOTER; + } + + /** + * Gets the Grid section where the referenced cell is. + * + * @since + * @return grid section + */ + public Section getSection() { + return section; + } } diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java index 50bc778736..f1edefc8ba 100644 --- a/client/src/com/vaadin/client/widgets/Grid.java +++ b/client/src/com/vaadin/client/widgets/Grid.java @@ -6202,7 +6202,7 @@ public class Grid<T> extends ResizeComposite implements assert cell != null : "received " + eventType + "-event with a null cell target"; - eventCell.set(cell); + eventCell.set(cell, getSectionFromContainer(container)); // Editor can steal focus from Grid and is still handled if (handleEditorEvent(event, container)) { @@ -6237,6 +6237,20 @@ public class Grid<T> extends ResizeComposite implements } } + private Section getSectionFromContainer(RowContainer container) { + assert container != null : "RowContainer should not be null"; + + if (container == escalator.getBody()) { + return Section.BODY; + } else if (container == escalator.getFooter()) { + return Section.FOOTER; + } else if (container == escalator.getHeader()) { + return Section.HEADER; + } + assert false : "RowContainer was not header, footer or body."; + return null; + } + private boolean isOrContainsInSpacer(Node node) { Node n = node; while (n != null && n != getElement()) { @@ -7780,4 +7794,17 @@ public class Grid<T> extends ResizeComposite implements sidebar.close(); } } + + /** + * Returns the {@link EventCellReference} for the latest event fired from + * this Grid. + * <p> + * Note: This cell reference will be updated when firing the next event. + * + * @since + * @return event cell reference + */ + public EventCellReference<T> getEventCell() { + return eventCell; + } } |