From ea65f173ff5f4d7c980f1e2d1d03c42470d30a2e Mon Sep 17 00:00:00 2001 From: Johannes Dahlström Date: Wed, 28 Jan 2015 15:50:54 +0200 Subject: Maintain Grid scroll position on detach and reattach (#16220) Change-Id: I6ac5c3304bcd22e23f298c4dbdd65358aa1c64f7 --- .../client/widget/escalator/ScrollbarBundle.java | 11 ++++++++- .../src/com/vaadin/client/widgets/Escalator.java | 27 +++++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) (limited to 'client/src/com') diff --git a/client/src/com/vaadin/client/widget/escalator/ScrollbarBundle.java b/client/src/com/vaadin/client/widget/escalator/ScrollbarBundle.java index 21f56c6c4d..2345641408 100644 --- a/client/src/com/vaadin/client/widget/escalator/ScrollbarBundle.java +++ b/client/src/com/vaadin/client/widget/escalator/ScrollbarBundle.java @@ -335,7 +335,7 @@ public abstract class ScrollbarBundle implements DeferredWorker { private boolean isLocked = false; - /** @deprecarted access via {@link #getHandlerManager()} instead. */ + /** @deprecated access via {@link #getHandlerManager()} instead. */ @Deprecated private HandlerManager handlerManager; @@ -514,6 +514,15 @@ public abstract class ScrollbarBundle implements DeferredWorker { } } + /** + * Should be called whenever this bundle is attached to the DOM (typically, + * from the onLoad of the containing widget). Used to ensure the DOM scroll + * position is maintained when detaching and reattaching the bundle. + */ + public void onLoad() { + internalSetScrollPos(toInt32(scrollPos)); + } + /** * Truncates a double such that no decimal places are retained. *

diff --git a/client/src/com/vaadin/client/widgets/Escalator.java b/client/src/com/vaadin/client/widgets/Escalator.java index a81d0f3e18..129100e073 100644 --- a/client/src/com/vaadin/client/widgets/Escalator.java +++ b/client/src/com/vaadin/client/widgets/Escalator.java @@ -47,6 +47,7 @@ import com.google.gwt.dom.client.TableRowElement; import com.google.gwt.dom.client.TableSectionElement; import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.logging.client.LogConfiguration; +import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.RequiresResize; @@ -4479,7 +4480,28 @@ public class Escalator extends Widget implements RequiresResize, DeferredWorker header.paintInsertRows(0, header.getRowCount()); footer.paintInsertRows(0, footer.getRowCount()); - recalculateElementSizes(); + + // recalculateElementSizes(); + + Scheduler.get().scheduleDeferred(new Command() { + @Override + public void execute() { + /* + * Not a faintest idea why we have to defer this call, but + * unless it is deferred, the size of the escalator will be 0x0 + * after it is first detached and then reattached to the DOM. + * This only applies to a bare Escalator; inside a Grid + * everything works fine either way. + * + * The three autodetectRowHeightLater calls above seem obvious + * suspects at first. However, they don't seem to have anything + * to do with the issue, as they are no-ops in the + * detach-reattach case. + */ + recalculateElementSizes(); + } + }); + /* * Note: There's no need to explicitly insert rows into the body. * @@ -4506,6 +4528,9 @@ public class Escalator extends Widget implements RequiresResize, DeferredWorker footer.reapplyColumnWidths(); } + verticalScrollbar.onLoad(); + horizontalScrollbar.onLoad(); + scroller.attachScrollListener(verticalScrollbar.getElement()); scroller.attachScrollListener(horizontalScrollbar.getElement()); scroller.attachMousewheelListener(getElement()); -- cgit v1.2.3