diff options
author | Ansku <Ansku@users.noreply.github.com> | 2017-08-22 14:59:49 +0300 |
---|---|---|
committer | Aleksi Hietanen <aleksi@vaadin.com> | 2017-08-22 14:59:49 +0300 |
commit | 3b2bea5236718fb13c9885141c0a4dddb323a868 (patch) | |
tree | c701551cf723e5ca4424574f96db627fb3457b14 /client/src | |
parent | 5ef925daa91b1253f170f244e2a992f4f92979e1 (diff) | |
download | vaadin-framework-3b2bea5236718fb13c9885141c0a4dddb323a868.tar.gz vaadin-framework-3b2bea5236718fb13c9885141c0a4dddb323a868.zip |
Resize should work within Grid details row (#9808)
Fixes #7341
Diffstat (limited to 'client/src')
-rw-r--r-- | client/src/main/java/com/vaadin/client/connectors/grid/DetailsManagerConnector.java | 79 | ||||
-rwxr-xr-x | client/src/main/java/com/vaadin/client/widgets/Grid.java | 13 |
2 files changed, 87 insertions, 5 deletions
diff --git a/client/src/main/java/com/vaadin/client/connectors/grid/DetailsManagerConnector.java b/client/src/main/java/com/vaadin/client/connectors/grid/DetailsManagerConnector.java index a1f9336c40..b8889591da 100644 --- a/client/src/main/java/com/vaadin/client/connectors/grid/DetailsManagerConnector.java +++ b/client/src/main/java/com/vaadin/client/connectors/grid/DetailsManagerConnector.java @@ -19,14 +19,18 @@ import java.util.HashMap; import java.util.Map; import com.google.gwt.core.client.Scheduler; +import com.google.gwt.core.client.Scheduler.ScheduledCommand; +import com.google.gwt.dom.client.Element; import com.google.gwt.user.client.ui.Widget; - import com.vaadin.client.ComponentConnector; import com.vaadin.client.ConnectorMap; import com.vaadin.client.LayoutManager; import com.vaadin.client.ServerConnector; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.data.DataChangeHandler; import com.vaadin.client.extensions.AbstractExtensionConnector; +import com.vaadin.client.ui.layout.ElementResizeEvent; +import com.vaadin.client.ui.layout.ElementResizeListener; import com.vaadin.client.widget.grid.HeightAwareDetailsGenerator; import com.vaadin.client.widgets.Grid; import com.vaadin.shared.Registration; @@ -53,6 +57,21 @@ public class DetailsManagerConnector extends AbstractExtensionConnector { /* Registration for data change handler. */ private Registration dataChangeRegistration; + private final Map<Element, ScheduledCommand> elementToResizeCommand = new HashMap<Element, Scheduler.ScheduledCommand>(); + private final ElementResizeListener detailsRowResizeListener = new ElementResizeListener() { + + @Override + public void onElementResize(ElementResizeEvent e) { + if (elementToResizeCommand.containsKey(e.getElement())) { + Scheduler.get().scheduleFinally( + elementToResizeCommand.get(e.getElement())); + } + } + }; + + /* calculated when the first details row is opened */ + private Double spacerCellBorderHeights = null; + /** * DataChangeHandler for updating the visibility of detail widgets. */ @@ -107,7 +126,35 @@ public class DetailsManagerConnector extends AbstractExtensionConnector { return null; } - return getConnector(id).getWidget(); + Widget widget = getConnector(id).getWidget(); + getLayoutManager().addElementResizeListener(widget.getElement(), + detailsRowResizeListener); + elementToResizeCommand.put(widget.getElement(), + createResizeCommand(rowIndex, widget.getElement())); + + return widget; + } + + private ScheduledCommand createResizeCommand(final int rowIndex, + final Element element) { + return new ScheduledCommand() { + + @Override + public void execute() { + // It should not be possible to get here without calculating + // the spacerCellBorderHeights or without having the details + // row open, nor for this command to be triggered while + // layout is running, but it's safer to check anyway. + if (spacerCellBorderHeights != null + && !getLayoutManager().isLayoutRunning() + && getDetailsComponentConnectorId( + rowIndex) != null) { + double height = getLayoutManager().getOuterHeightDouble( + element) + spacerCellBorderHeights; + getWidget().setDetailsHeight(rowIndex, height); + } + } + }; } @Override @@ -120,8 +167,16 @@ public class DetailsManagerConnector extends AbstractExtensionConnector { getLayoutManager().setNeedsMeasureRecursively(componentConnector); getLayoutManager().layoutNow(); - return getLayoutManager().getOuterHeightDouble( - componentConnector.getWidget().getElement()); + Element element = componentConnector.getWidget().getElement(); + if (spacerCellBorderHeights == null) { + // If theme is changed, new details generator is created from + // scratch, so this value doesn't need to be updated elsewhere. + spacerCellBorderHeights = WidgetUtil + .getBorderTopAndBottomThickness( + element.getParentElement()); + } + + return getLayoutManager().getOuterHeightDouble(element); } private ComponentConnector getConnector(String id) { @@ -143,7 +198,21 @@ public class DetailsManagerConnector extends AbstractExtensionConnector { return; } - // New Details component, hide old one + if (id == null) { + // Details have been hidden, listeners attached to the old + // component need to be removed + id = indexToDetailConnectorId.get(rowIndex); + } + + // New or removed Details component, hide old one + ComponentConnector connector = (ComponentConnector) ConnectorMap + .get(getConnection()).getConnector(id); + if (connector != null) { + Element element = connector.getWidget().getElement(); + elementToResizeCommand.remove(element); + getLayoutManager().removeElementResizeListener(element, + detailsRowResizeListener); + } getWidget().setDetailsVisible(rowIndex, false); indexToDetailConnectorId.remove(rowIndex); } diff --git a/client/src/main/java/com/vaadin/client/widgets/Grid.java b/client/src/main/java/com/vaadin/client/widgets/Grid.java index 267dbccc87..0de0c9ab7e 100755 --- a/client/src/main/java/com/vaadin/client/widgets/Grid.java +++ b/client/src/main/java/com/vaadin/client/widgets/Grid.java @@ -9119,6 +9119,19 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, } /** + * Update details row height. + * + * @since + * @param rowIndex + * the index of the row for which to update details height + * @param height + * new height of the details row + */ + public void setDetailsHeight(int rowIndex, double height) { + escalator.getBody().setSpacer(rowIndex, height); + } + + /** * Requests that the column widths should be recalculated. * <p> * The actual recalculation is not necessarily done immediately so you |