diff options
author | Artur Signell <artur@vaadin.com> | 2016-01-16 19:44:26 +0200 |
---|---|---|
committer | Teemu Suo-Anttila <teemusa@vaadin.com> | 2016-02-15 17:11:07 +0200 |
commit | 3b35d3f6c78f075e066eec1bda05fdf3fa52aef3 (patch) | |
tree | 385a4e0663ac294ee9d49bcea19ede2e68e52db4 /client/src | |
parent | 9dd31480b987ef89e7490d0e3775e4df64376167 (diff) | |
download | vaadin-framework-3b35d3f6c78f075e066eec1bda05fdf3fa52aef3.tar.gz vaadin-framework-3b35d3f6c78f075e066eec1bda05fdf3fa52aef3.zip |
Make hiding/showing components in grid header/footer work (#19297)
Change-Id: Icd98bf81f98c1d79b4c9b4ca4a17d36ed883e19f
Diffstat (limited to 'client/src')
-rw-r--r-- | client/src/com/vaadin/client/connectors/GridConnector.java | 16 | ||||
-rw-r--r-- | client/src/com/vaadin/client/widgets/Grid.java | 103 |
2 files changed, 82 insertions, 37 deletions
diff --git a/client/src/com/vaadin/client/connectors/GridConnector.java b/client/src/com/vaadin/client/connectors/GridConnector.java index 808b7ba2f3..7d8a2a8fbf 100644 --- a/client/src/com/vaadin/client/connectors/GridConnector.java +++ b/client/src/com/vaadin/client/connectors/GridConnector.java @@ -937,7 +937,13 @@ public class GridConnector extends AbstractHasComponentsConnector implements break; case WIDGET: ComponentConnector connector = (ComponentConnector) cellState.connector; - cell.setWidget(connector.getWidget()); + if (connector != null) { + cell.setWidget(connector.getWidget()); + } else { + // This happens if you do setVisible(false) on the component on + // the server side + cell.setWidget(null); + } break; default: throw new IllegalStateException("unexpected cell type: " @@ -991,7 +997,13 @@ public class GridConnector extends AbstractHasComponentsConnector implements break; case WIDGET: ComponentConnector connector = (ComponentConnector) cellState.connector; - cell.setWidget(connector.getWidget()); + if (connector != null) { + cell.setWidget(connector.getWidget()); + } else { + // This happens if you do setVisible(false) on the component on + // the server side + cell.setWidget(null); + } break; default: throw new IllegalStateException("unexpected cell type: " diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java index e3c51830fe..0de5e7a239 100644 --- a/client/src/com/vaadin/client/widgets/Grid.java +++ b/client/src/com/vaadin/client/widgets/Grid.java @@ -116,10 +116,10 @@ import com.vaadin.client.widget.grid.DetailsGenerator; import com.vaadin.client.widget.grid.EditorHandler; import com.vaadin.client.widget.grid.EditorHandler.EditorRequest; import com.vaadin.client.widget.grid.EventCellReference; +import com.vaadin.client.widget.grid.HeightAwareDetailsGenerator; import com.vaadin.client.widget.grid.RendererCellReference; import com.vaadin.client.widget.grid.RowReference; import com.vaadin.client.widget.grid.RowStyleGenerator; -import com.vaadin.client.widget.grid.HeightAwareDetailsGenerator; import com.vaadin.client.widget.grid.events.AbstractGridKeyEventHandler; import com.vaadin.client.widget.grid.events.AbstractGridMouseEventHandler; import com.vaadin.client.widget.grid.events.BodyClickHandler; @@ -371,6 +371,14 @@ public class Grid<T> extends ResizeComposite implements * null). */ public void setWidget(Widget widget) { + if (this.content == widget) { + return; + } + + if (this.content instanceof Widget) { + // Old widget in the cell, detach it first + section.getGrid().detachWidget((Widget) this.content); + } this.content = widget; this.type = GridStaticCellType.WIDGET; section.requestSectionRefresh(); @@ -407,6 +415,17 @@ public class Grid<T> extends ResizeComposite implements } + /** + * Called when the cell is detached from the row + * + * @since + */ + void detach() { + if (this.content instanceof Widget) { + // Widget in the cell, detach it + section.getGrid().detachWidget((Widget) this.content); + } + } } /** @@ -626,6 +645,22 @@ public class Grid<T> extends ResizeComposite implements this.styleName = styleName; section.requestSectionRefresh(); } + + /** + * Called when the row is detached from the grid + * + * @since + */ + void detach() { + // Avoid calling detach twice for a merged cell + HashSet<CELLTYPE> cells = new HashSet<CELLTYPE>(); + for (Column<?, ?> column : getSection().grid.getColumns()) { + cells.add(getCell(column)); + } + for (CELLTYPE cell : cells) { + cell.detach(); + } + } } private Grid<?> grid; @@ -738,7 +773,8 @@ public class Grid<T> extends ResizeComposite implements * @see #removeRow(StaticRow) */ public void removeRow(int index) { - rows.remove(index); + ROWTYPE row = rows.remove(index); + row.detach(); requestSectionRefresh(); } @@ -1820,7 +1856,7 @@ public class Grid<T> extends ResizeComposite implements if (editor != null) { columnToWidget.put(column, editor); - attachWidget(editor, cell); + grid.attachWidget(editor, cell); } if (i == focusedColumnIndex) { @@ -1866,7 +1902,7 @@ public class Grid<T> extends ResizeComposite implements } } }); - attachWidget(checkBox, cell); + grid.attachWidget(checkBox, cell); columnToWidget.put(column, checkBox); // Only enable CheckBox in non-buffered mode @@ -1891,8 +1927,8 @@ public class Grid<T> extends ResizeComposite implements } if (isBuffered()) { - attachWidget(saveButton, buttonsWrapper); - attachWidget(cancelButton, buttonsWrapper); + grid.attachWidget(saveButton, buttonsWrapper); + grid.attachWidget(cancelButton, buttonsWrapper); } setMessageAndButtonsWrapperVisible(isBuffered()); @@ -1981,8 +2017,8 @@ public class Grid<T> extends ResizeComposite implements } columnToWidget.clear(); - detachWidget(saveButton); - detachWidget(cancelButton); + grid.detachWidget(saveButton); + grid.detachWidget(cancelButton); editorOverlay.removeAllChildren(); cellWrapper.removeAllChildren(); @@ -2052,16 +2088,6 @@ public class Grid<T> extends ResizeComposite implements return cell; } - private void attachWidget(Widget w, Element parent) { - parent.appendChild(w.getElement()); - setParent(w, grid); - } - - private void detachWidget(Widget w) { - setParent(w, null); - w.getElement().removeFromParent(); - } - private static void setBounds(Element e, double left, double top, double width, double height) { Style style = e.getStyle(); @@ -5787,20 +5813,14 @@ public class Grid<T> extends ResizeComposite implements StaticSection.StaticCell metadata = gridRow.getCell(columns .get(cell.getColumn())); /* - * If the cell contains widgets that are not currently attach + * If the cell contains widgets that are not currently attached * then attach them now. */ if (GridStaticCellType.WIDGET.equals(metadata.getType())) { final Widget widget = metadata.getWidget(); - final Element cellElement = cell.getElement(); - - if (!widget.isAttached()) { - - // Physical attach - cellElement.appendChild(widget.getElement()); - - // Logical attach - setParent(widget, Grid.this); + if (widget != null && !widget.isAttached()) { + getGrid().attachWidget(metadata.getWidget(), + cell.getElement()); } } } @@ -5817,20 +5837,19 @@ public class Grid<T> extends ResizeComposite implements .get(cell.getColumn())); if (GridStaticCellType.WIDGET.equals(metadata.getType()) + && metadata.getWidget() != null && metadata.getWidget().isAttached()) { - Widget widget = metadata.getWidget(); - - // Logical detach - setParent(widget, null); - - // Physical detach - widget.getElement().removeFromParent(); + getGrid().detachWidget(metadata.getWidget()); } } } } + protected Grid getGrid() { + return section.grid; + } + @Override public void postDetach(Row row, Iterable<FlyweightCell> detachedCells) { } @@ -8585,6 +8604,20 @@ public class Grid<T> extends ResizeComposite implements } } + private void attachWidget(Widget w, Element parent) { + assert w.getParent() == null; + + parent.appendChild(w.getElement()); + setParent(w, this); + } + + private void detachWidget(Widget w) { + assert w.getParent() == this; + + setParent(w, null); + w.getElement().removeFromParent(); + } + /** * Resets all cached pixel sizes and reads new values from the DOM. This * methods should be used e.g. when styles affecting the dimensions of |