From 9dd665b56eb4166d2af92a4825c37d20d15ed413 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Thu, 29 Nov 2012 16:36:27 +0200 Subject: UI scroll position can be given programmatically (#9952) Change-Id: Icef0858ee495abcacab7823f7f8fc6044abd64dc --- server/src/com/vaadin/ui/UI.java | 55 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) (limited to 'server/src/com/vaadin/ui/UI.java') diff --git a/server/src/com/vaadin/ui/UI.java b/server/src/com/vaadin/ui/UI.java index 55f756010e..b45aedb8e1 100644 --- a/server/src/com/vaadin/ui/UI.java +++ b/server/src/com/vaadin/ui/UI.java @@ -39,6 +39,7 @@ import com.vaadin.server.VaadinServlet; import com.vaadin.server.VaadinSession; import com.vaadin.shared.EventId; import com.vaadin.shared.MouseEventDetails; +import com.vaadin.shared.ui.ui.ScrollClientRpc; import com.vaadin.shared.ui.ui.UIConstants; import com.vaadin.shared.ui.ui.UIServerRpc; import com.vaadin.shared.ui.ui.UIState; @@ -114,6 +115,16 @@ public abstract class UI extends AbstractSingleComponentContainer implements private Page page = new Page(this); + /** + * Scroll Y position. + */ + private int scrollTop = 0; + + /** + * Scroll X position + */ + private int scrollLeft = 0; + private UIServerRpc rpc = new UIServerRpc() { @Override public void click(MouseEventDetails mouseDetails) { @@ -126,6 +137,12 @@ public abstract class UI extends AbstractSingleComponentContainer implements // TODO We're not doing anything with the view dimensions getPage().updateBrowserWindowSize(windowWidth, windowHeight); } + + @Override + public void scroll(int scrollTop, int scrollLeft) { + UI.this.scrollTop = scrollTop; + UI.this.scrollLeft = scrollLeft; + } }; /** @@ -560,8 +577,44 @@ public abstract class UI extends AbstractSingleComponentContainer implements return CurrentInstance.get(UI.class); } + /** + * Set top offset to which the UI should scroll to. + * + * @param scrollTop + */ public void setScrollTop(int scrollTop) { - throw new RuntimeException("Not yet implemented"); + if (scrollTop < 0) { + throw new IllegalArgumentException( + "Scroll offset must be at least 0"); + } + if (this.scrollTop != scrollTop) { + this.scrollTop = scrollTop; + getRpcProxy(ScrollClientRpc.class).setScrollTop(scrollTop); + } + } + + public int getScrollTop() { + return scrollTop; + } + + /** + * Set left offset to which the UI should scroll to. + * + * @param scrollLeft + */ + public void setScrollLeft(int scrollLeft) { + if (scrollLeft < 0) { + throw new IllegalArgumentException( + "Scroll offset must be at least 0"); + } + if (this.scrollLeft != scrollLeft) { + this.scrollLeft = scrollLeft; + getRpcProxy(ScrollClientRpc.class).setScrollLeft(scrollLeft); + } + } + + public int getScrollLeft() { + return scrollLeft; } @Override -- cgit v1.2.3