diff options
author | Teemu Suo-Anttila <teemusa@vaadin.com> | 2014-12-18 12:52:15 +0200 |
---|---|---|
committer | Teemu Suo-Anttila <teemusa@vaadin.com> | 2014-12-18 12:53:21 +0200 |
commit | ca62a4a1f76d2555a38dc91320949ecf09e92c35 (patch) | |
tree | e80864835a14d2c641db29bce03ea7d7b6d66910 /client | |
parent | 1326e5cf76093ffed3b832afe7dcf3f909aec846 (diff) | |
download | vaadin-framework-ca62a4a1f76d2555a38dc91320949ecf09e92c35.tar.gz vaadin-framework-ca62a4a1f76d2555a38dc91320949ecf09e92c35.zip |
Use CellReferences everywhere in Renderer APIs (#13334)
This patch adds getElement() to RowReference and CellReference
Change-Id: I3df6e50256f628e5cdb5d64d741ff1eb59e8e1c3
Diffstat (limited to 'client')
6 files changed, 63 insertions, 30 deletions
diff --git a/client/src/com/vaadin/client/renderers/ComplexRenderer.java b/client/src/com/vaadin/client/renderers/ComplexRenderer.java index a4980b8108..4e41b5f80d 100644 --- a/client/src/com/vaadin/client/renderers/ComplexRenderer.java +++ b/client/src/com/vaadin/client/renderers/ComplexRenderer.java @@ -24,6 +24,7 @@ import com.google.gwt.dom.client.Node; import com.google.gwt.dom.client.Style.Visibility; import com.vaadin.client.widget.escalator.Cell; import com.vaadin.client.widget.escalator.FlyweightCell; +import com.vaadin.client.widget.grid.CellReference; import com.vaadin.client.widget.grid.RendererCellReference; /** @@ -99,7 +100,7 @@ public abstract class ComplexRenderer<T> implements Renderer<T> { * The original DOM event * @return true if event should not be handled by grid */ - public boolean onBrowserEvent(Cell cell, NativeEvent event) { + public boolean onBrowserEvent(CellReference<?> cell, NativeEvent event) { return false; } @@ -142,7 +143,7 @@ public abstract class ComplexRenderer<T> implements Renderer<T> { * @return <code>true</code> if event was handled and should not be * interpreted as a generic gesture by Grid. */ - public boolean onActivate(Cell cell) { + public boolean onActivate(CellReference<?> cell) { return false; } diff --git a/client/src/com/vaadin/client/widget/grid/CellReference.java b/client/src/com/vaadin/client/widget/grid/CellReference.java index 9a4601c6e2..bddb24d8fc 100644 --- a/client/src/com/vaadin/client/widget/grid/CellReference.java +++ b/client/src/com/vaadin/client/widget/grid/CellReference.java @@ -15,6 +15,7 @@ */ package com.vaadin.client.widget.grid; +import com.google.gwt.dom.client.TableCellElement; import com.vaadin.client.widgets.Grid; /** @@ -40,8 +41,6 @@ public class CellReference<T> { /** * Sets the identifying information for this cell. * - * @param rowReference - * a reference to the row that contains this cell * @param columnIndex * the index of the column * @param column @@ -107,6 +106,15 @@ public class CellReference<T> { } /** + * Get the element of the cell. + * + * @return the element of the cell + */ + public TableCellElement getElement() { + return rowReference.getElement().getCells().getItem(columnIndex); + } + + /** * Gets the RowReference for this CellReference. * * @return the row reference @@ -114,4 +122,5 @@ public class CellReference<T> { protected RowReference<T> getRowReference() { return rowReference; } + }
\ No newline at end of file diff --git a/client/src/com/vaadin/client/widget/grid/EventCellReference.java b/client/src/com/vaadin/client/widget/grid/EventCellReference.java index 300bbd90d9..86c3bcb5b6 100644 --- a/client/src/com/vaadin/client/widget/grid/EventCellReference.java +++ b/client/src/com/vaadin/client/widget/grid/EventCellReference.java @@ -15,6 +15,7 @@ */ package com.vaadin.client.widget.grid; +import com.google.gwt.dom.client.TableCellElement; import com.vaadin.client.widget.escalator.Cell; import com.vaadin.client.widgets.Grid; @@ -32,6 +33,7 @@ import com.vaadin.client.widgets.Grid; public class EventCellReference<T> extends CellReference<T> { private Grid<T> grid; + private TableCellElement element; public EventCellReference(Grid<T> grid) { super(new RowReference<T>(grid)); @@ -47,8 +49,16 @@ public class EventCellReference<T> extends CellReference<T> { public void set(Cell targetCell) { int row = targetCell.getRow(); int column = targetCell.getColumn(); - getRowReference().set(row, grid.getDataSource().getRow(row)); + // At least for now we don't need to have the actual TableRowElement + // available. + getRowReference().set(row, grid.getDataSource().getRow(row), null); set(column, grid.getColumn(column)); + + this.element = targetCell.getElement(); } + @Override + public TableCellElement getElement() { + return element; + } } diff --git a/client/src/com/vaadin/client/widget/grid/RowReference.java b/client/src/com/vaadin/client/widget/grid/RowReference.java index 9135c4aa26..4298d05756 100644 --- a/client/src/com/vaadin/client/widget/grid/RowReference.java +++ b/client/src/com/vaadin/client/widget/grid/RowReference.java @@ -15,6 +15,7 @@ */ package com.vaadin.client.widget.grid; +import com.google.gwt.dom.client.TableRowElement; import com.vaadin.client.widgets.Grid; /** @@ -34,6 +35,8 @@ public class RowReference<T> { private int rowIndex; private T row; + private TableRowElement element; + /** * Creates a new row reference for the given grid. * @@ -51,10 +54,13 @@ public class RowReference<T> { * the index of the row * @param row * the row object + * @param elemenet + * the element of the row */ - public void set(int rowIndex, T row) { + public void set(int rowIndex, T row, TableRowElement element) { this.rowIndex = rowIndex; this.row = row; + this.element = element; } /** @@ -84,4 +90,13 @@ public class RowReference<T> { return row; } + /** + * Gets the table row element of the row. + * + * @return the element of the row + */ + public TableRowElement getElement() { + return element; + } + }
\ No newline at end of file diff --git a/client/src/com/vaadin/client/widget/grid/selection/MultiSelectionRenderer.java b/client/src/com/vaadin/client/widget/grid/selection/MultiSelectionRenderer.java index 525603a15b..b8e7c1f252 100644 --- a/client/src/com/vaadin/client/widget/grid/selection/MultiSelectionRenderer.java +++ b/client/src/com/vaadin/client/widget/grid/selection/MultiSelectionRenderer.java @@ -34,7 +34,7 @@ import com.google.gwt.user.client.Event.NativePreviewEvent; import com.google.gwt.user.client.Event.NativePreviewHandler; import com.vaadin.client.Util; import com.vaadin.client.renderers.ComplexRenderer; -import com.vaadin.client.widget.escalator.Cell; +import com.vaadin.client.widget.grid.CellReference; import com.vaadin.client.widget.grid.RendererCellReference; import com.vaadin.client.widget.grid.selection.SelectionModel.Multi.Batched; import com.vaadin.client.widgets.Grid; @@ -581,7 +581,8 @@ public class MultiSelectionRenderer<T> extends ComplexRenderer<Boolean> { } @Override - public boolean onBrowserEvent(final Cell cell, final NativeEvent event) { + public boolean onBrowserEvent(final CellReference<?> cell, + final NativeEvent event) { if (BrowserEvents.TOUCHSTART.equals(event.getType()) || (BrowserEvents.MOUSEDOWN.equals(event.getType()) && event .getButton() == NativeEvent.BUTTON_LEFT)) { diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java index 80493388e0..bc8b0fbf3c 100644 --- a/client/src/com/vaadin/client/widgets/Grid.java +++ b/client/src/com/vaadin/client/widgets/Grid.java @@ -1612,8 +1612,8 @@ public class Grid<T> extends ResizeComposite implements * @param cell * a cell object */ - public void setCellFocus(Cell cell) { - setCellFocus(cell.getRow(), cell.getColumn(), + public void setCellFocus(CellReference<T> cell) { + setCellFocus(cell.getRowIndex(), cell.getColumnIndex(), escalator.findRowContainer(cell.getElement())); } @@ -1629,7 +1629,7 @@ public class Grid<T> extends ResizeComposite implements /** * Handle events that can move the cell focus. */ - public void handleNavigationEvent(Event event, Cell cell) { + public void handleNavigationEvent(Event event, CellReference<T> cell) { if (event.getType().equals(BrowserEvents.CLICK)) { setCellFocus(cell); // Grid should have focus when clicked. @@ -2984,7 +2984,8 @@ public class Grid<T> extends ResizeComposite implements @Override public void preAttach(Row row, Iterable<FlyweightCell> cellsToAttach) { int rowIndex = row.getRow(); - rowReference.set(rowIndex, getDataSource().getRow(rowIndex)); + rowReference.set(rowIndex, getDataSource().getRow(rowIndex), + row.getElement()); for (FlyweightCell cell : cellsToAttach) { Renderer<?> renderer = findRenderer(cell); if (renderer instanceof ComplexRenderer) { @@ -3056,7 +3057,7 @@ public class Grid<T> extends ResizeComposite implements boolean isEvenIndex = (row.getRow() % 2 == 0); setStyleName(rowElement, rowStripeStyleName, !isEvenIndex); - rowReference.set(rowIndex, rowData); + rowReference.set(rowIndex, rowData, rowElement); if (hasData) { setStyleName(rowElement, rowSelectedStyleName, @@ -3182,7 +3183,7 @@ public class Grid<T> extends ResizeComposite implements int rowIndex = row.getRow(); // Passing null row data since it might not exist in the data source // any more - rowReference.set(rowIndex, null); + rowReference.set(rowIndex, null, row.getElement()); for (FlyweightCell cell : detachedCells) { Renderer renderer = findRenderer(cell); if (renderer instanceof ComplexRenderer) { @@ -4458,7 +4459,7 @@ public class Grid<T> extends ResizeComposite implements eventCell.set(cell); // Editor can steal focus from Grid and is still handled - if (handleEditorEvent(event, container, cell)) { + if (handleEditorEvent(event, container)) { return; } @@ -4472,7 +4473,7 @@ public class Grid<T> extends ResizeComposite implements return; } - if (handleRendererEvent(event, container, cell)) { + if (handleRendererEvent(event, container)) { return; } @@ -4480,7 +4481,7 @@ public class Grid<T> extends ResizeComposite implements return; } - if (handleCellFocusEvent(event, container, cell)) { + if (handleCellFocusEvent(event, container)) { return; } } @@ -4506,8 +4507,7 @@ public class Grid<T> extends ResizeComposite implements return w != null; } - private boolean handleEditorEvent(Event event, RowContainer container, - Cell cell) { + private boolean handleEditorEvent(Event event, RowContainer container) { if (editor.getState() != Editor.State.INACTIVE) { if (event.getTypeInt() == Event.ONKEYDOWN @@ -4519,10 +4519,8 @@ public class Grid<T> extends ResizeComposite implements if (container == escalator.getBody() && editor.isEnabled()) { if (event.getTypeInt() == Event.ONDBLCLICK) { - if (cell != null) { - editor.editRow(cell.getRow()); - return true; - } + editor.editRow(eventCell.getRowIndex()); + return true; } else if (event.getTypeInt() == Event.ONKEYDOWN && event.getKeyCode() == Editor.KEYCODE_SHOW) { editor.editRow(cellFocusHandler.rowWithFocus); @@ -4532,8 +4530,7 @@ public class Grid<T> extends ResizeComposite implements return false; } - private boolean handleRendererEvent(Event event, RowContainer container, - Cell cell) { + private boolean handleRendererEvent(Event event, RowContainer container) { if (container == escalator.getBody()) { Column<?, T> gridColumn = eventCell.getColumn(); @@ -4546,13 +4543,14 @@ public class Grid<T> extends ResizeComposite implements ComplexRenderer<?> cplxRenderer = (ComplexRenderer<?>) gridColumn .getRenderer(); if (cplxRenderer.getConsumedEvents().contains(event.getType())) { - if (cplxRenderer.onBrowserEvent(cell, event)) { + if (cplxRenderer.onBrowserEvent(eventCell, event)) { return true; } } // Calls onActivate if KeyDown and Enter or double click - if ((enterKey || doubleClick) && cplxRenderer.onActivate(cell)) { + if ((enterKey || doubleClick) + && cplxRenderer.onActivate(eventCell)) { return true; } } @@ -4560,11 +4558,10 @@ public class Grid<T> extends ResizeComposite implements return false; } - private boolean handleCellFocusEvent(Event event, RowContainer container, - Cell cell) { + private boolean handleCellFocusEvent(Event event, RowContainer container) { Collection<String> navigation = cellFocusHandler.getNavigationEvents(); if (navigation.contains(event.getType())) { - cellFocusHandler.handleNavigationEvent(event, cell); + cellFocusHandler.handleNavigationEvent(event, eventCell); } return false; } |