From: Matti Tahvonen Date: Fri, 7 May 2010 16:59:33 +0000 (+0000) Subject: fixes #1847 X-Git-Tag: 6.7.0.beta1~1670^2~10 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=21e4e36a13dfd50963ba11732a6ae2e0c4296dd7;p=vaadin-framework.git fixes #1847 svn changeset:13086/svn branch:6.3 --- diff --git a/src/com/vaadin/terminal/gwt/client/ui/VView.java b/src/com/vaadin/terminal/gwt/client/ui/VView.java index 033d35dab1..d004d35b17 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VView.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VView.java @@ -389,9 +389,29 @@ public class VView extends SimplePanel implements Container, ResizeHandler, Util.runWebkitOverflowAutoFix(getElement()); } + scrollIntoView(uidl); + rendering = false; } + /** + * Tries to scroll paintable referenced from given UIDL snippet to be + * visible. + * + * @param uidl + */ + void scrollIntoView(final UIDL uidl) { + if (uidl.hasAttribute("scrollTo")) { + DeferredCommand.addCommand(new Command() { + public void execute() { + final Paintable paintable = uidl.getPaintableAttribute( + "scrollTo", connection); + ((Widget) paintable).getElement().scrollIntoView(); + } + }); + } + } + @Override public void onBrowserEvent(Event event) { super.onBrowserEvent(event); diff --git a/src/com/vaadin/terminal/gwt/client/ui/VWindow.java b/src/com/vaadin/terminal/gwt/client/ui/VWindow.java index 6005556fff..ecb499fdf8 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VWindow.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VWindow.java @@ -473,6 +473,8 @@ public class VWindow extends VOverlay implements Container, ScrollListener { Util.runWebkitOverflowAutoFix(contentPanel.getElement()); + client.getView().scrollIntoView(uidl); + } private void setDraggable(boolean draggable) { diff --git a/src/com/vaadin/ui/Window.java b/src/com/vaadin/ui/Window.java index 46074fb0ba..fd4edccb59 100644 --- a/src/com/vaadin/ui/Window.java +++ b/src/com/vaadin/ui/Window.java @@ -128,6 +128,8 @@ public class Window extends Panel implements URIHandler, ParameterHandler { private ArrayList jsExecQueue = null; + private Component scrollIntoView; + /* ********************************************************************* */ /** @@ -515,6 +517,11 @@ public class Window extends Panel implements URIHandler, ParameterHandler { centerRequested = false; } + if (scrollIntoView != null) { + target.addAttribute("scrollTo", scrollIntoView); + scrollIntoView = null; + } + // Marks the main window if (getApplication() != null && this == getApplication().getMainWindow()) { @@ -613,6 +620,23 @@ public class Window extends Panel implements URIHandler, ParameterHandler { /* ********************************************************************* */ + /** + * Method tries to scroll all scrollable elements up from given component so + * that the component becomes visible for end user. The given component is + * expected to be inside this window. + * + * @param component + * the component where to scroll + */ + public void scrollIntoView(Component component) { + if (component.getWindow() != this) { + throw new IllegalArgumentException( + "The component where to scroll must be inside this window."); + } + scrollIntoView = component; + requestRepaint(); + } + /** * Opens the given resource in this window. * @@ -1902,7 +1926,7 @@ public class Window extends Panel implements URIHandler, ParameterHandler { @Override public void handleAction(Object sender, Object target) { - this.window.close(); + window.close(); } } } diff --git a/tests/src/com/vaadin/tests/components/window/WindowScrollingComponentIntoView.java b/tests/src/com/vaadin/tests/components/window/WindowScrollingComponentIntoView.java new file mode 100644 index 0000000000..3d051c4a10 --- /dev/null +++ b/tests/src/com/vaadin/tests/components/window/WindowScrollingComponentIntoView.java @@ -0,0 +1,137 @@ +package com.vaadin.tests.components.window; + +import com.vaadin.tests.components.AbstractTestCase; +import com.vaadin.ui.Button; +import com.vaadin.ui.Component; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Label; +import com.vaadin.ui.Panel; +import com.vaadin.ui.Table; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.Window; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; + +public class WindowScrollingComponentIntoView extends AbstractTestCase { + + @Override + protected String getDescription() { + return "Scroll down, click 'up' and the view should scroll to the top"; + } + + @Override + protected Integer getTicketNumber() { + return 4206; + } + + @Override + public void init() { + Table table = new Table(); + table.setPageLength(50); + + final Button up = new Button("up"); + up.addListener(new Button.ClickListener() { + + public void buttonClick(ClickEvent event) { + up.getWindow().setScrollTop(0); + } + }); + + setMainWindow(new Window("")); + getMainWindow().getContent().setSizeUndefined(); + + Component l2 = null; + for (int i = 0; i < 10; i++) { + l2 = l("X" + i); + getMainWindow().addComponent(l2); + } + + final Component x9 = l2; + + HorizontalLayout horizontalLayout = new HorizontalLayout(); + + Component l = null; + for (int i = 0; i < 10; i++) { + l = l("Y" + i); + horizontalLayout.addComponent(l); + } + + getMainWindow().addComponent(horizontalLayout); + final Component y9 = l; + + final Window window = new Window(); + window.setHeight("500px"); + window.setWidth("500px"); + window.setPositionX(200); + window.setPositionY(200); + + window.addComponent(new Button("Scroll mainwin to X9", + new ClickListener() { + public void buttonClick(ClickEvent event) { + getMainWindow().scrollIntoView(x9); + + } + })); + window.addComponent(new Button("Scroll mainwin to Y9", + new ClickListener() { + public void buttonClick(ClickEvent event) { + getMainWindow().scrollIntoView(y9); + + } + })); + + Panel panel = new Panel("scrollable panel"); + panel.setHeight(400, Panel.UNITS_PIXELS); + panel.setScrollable(true); + panel.setScrollLeft(50); + panel.setScrollTop(50); + panel.getContent().setSizeUndefined(); + window.addComponent(l("Spacer", 500, 500)); + + l2 = null; + for (int i = 0; i < 10; i++) { + l2 = l("X" + i); + panel.addComponent(l2); + } + + final Component x29 = l2; + + horizontalLayout = new HorizontalLayout(); + + l = null; + for (int i = 0; i < 10; i++) { + l = l("Y" + i); + horizontalLayout.addComponent(l); + } + panel.addComponent(horizontalLayout); + final Component y29 = l; + + ((VerticalLayout) getMainWindow().getContent()).addComponent( + new Button("Scroll win to X9", new ClickListener() { + public void buttonClick(ClickEvent event) { + window.scrollIntoView(x29); + } + }), 0); + ((VerticalLayout) getMainWindow().getContent()).addComponent( + new Button("Scroll win to Y9", new ClickListener() { + public void buttonClick(ClickEvent event) { + window.scrollIntoView(y29); + } + }), 0); + + window.addComponent(panel); + getMainWindow().addWindow(window); + + } + + private Component l(String string) { + return l(string, 200, 350); + } + + private Component l(String string, int h, int w) { + Label label = new Label(string); + label.setHeight(h, Label.UNITS_PIXELS); + label.setWidth(w, Label.UNITS_PIXELS); + return label; + } +}