]> source.dussan.org Git - vaadin-framework.git/commitdiff
fixes #1847
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Fri, 7 May 2010 16:59:33 +0000 (16:59 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Fri, 7 May 2010 16:59:33 +0000 (16:59 +0000)
svn changeset:13086/svn branch:6.3

src/com/vaadin/terminal/gwt/client/ui/VView.java
src/com/vaadin/terminal/gwt/client/ui/VWindow.java
src/com/vaadin/ui/Window.java
tests/src/com/vaadin/tests/components/window/WindowScrollingComponentIntoView.java [new file with mode: 0644]

index 033d35dab1e4b950b989192ff24ded2dee6f5ff8..d004d35b176d2d7ca5eb1744d03b9f69989fe90f 100644 (file)
@@ -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);
index 6005556fff601074de3919073903bda006ef4c33..ecb499fdf889fd12be442c898e64b3f78ba38b16 100644 (file)
@@ -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) {
index 46074fb0bafbc504bb9b83e5a9a793224a3a8f81..fd4edccb594ed6591181bdcf185a2a1c76021138 100644 (file)
@@ -128,6 +128,8 @@ public class Window extends Panel implements URIHandler, ParameterHandler {
 
     private ArrayList<String> 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 (file)
index 0000000..3d051c4
--- /dev/null
@@ -0,0 +1,137 @@
+package com.vaadin.tests.components.window;\r
+\r
+import com.vaadin.tests.components.AbstractTestCase;\r
+import com.vaadin.ui.Button;\r
+import com.vaadin.ui.Component;\r
+import com.vaadin.ui.HorizontalLayout;\r
+import com.vaadin.ui.Label;\r
+import com.vaadin.ui.Panel;\r
+import com.vaadin.ui.Table;\r
+import com.vaadin.ui.VerticalLayout;\r
+import com.vaadin.ui.Window;\r
+import com.vaadin.ui.Button.ClickEvent;\r
+import com.vaadin.ui.Button.ClickListener;\r
+\r
+public class WindowScrollingComponentIntoView extends AbstractTestCase {\r
+\r
+    @Override\r
+    protected String getDescription() {\r
+        return "Scroll down, click 'up' and the view should scroll to the top";\r
+    }\r
+\r
+    @Override\r
+    protected Integer getTicketNumber() {\r
+        return 4206;\r
+    }\r
+\r
+    @Override\r
+    public void init() {\r
+        Table table = new Table();\r
+        table.setPageLength(50);\r
+\r
+        final Button up = new Button("up");\r
+        up.addListener(new Button.ClickListener() {\r
+\r
+            public void buttonClick(ClickEvent event) {\r
+                up.getWindow().setScrollTop(0);\r
+            }\r
+        });\r
+\r
+        setMainWindow(new Window(""));\r
+        getMainWindow().getContent().setSizeUndefined();\r
+\r
+        Component l2 = null;\r
+        for (int i = 0; i < 10; i++) {\r
+            l2 = l("X" + i);\r
+            getMainWindow().addComponent(l2);\r
+        }\r
+\r
+        final Component x9 = l2;\r
+\r
+        HorizontalLayout horizontalLayout = new HorizontalLayout();\r
+\r
+        Component l = null;\r
+        for (int i = 0; i < 10; i++) {\r
+            l = l("Y" + i);\r
+            horizontalLayout.addComponent(l);\r
+        }\r
+\r
+        getMainWindow().addComponent(horizontalLayout);\r
+        final Component y9 = l;\r
+\r
+        final Window window = new Window();\r
+        window.setHeight("500px");\r
+        window.setWidth("500px");\r
+        window.setPositionX(200);\r
+        window.setPositionY(200);\r
+\r
+        window.addComponent(new Button("Scroll mainwin to X9",\r
+                new ClickListener() {\r
+                    public void buttonClick(ClickEvent event) {\r
+                        getMainWindow().scrollIntoView(x9);\r
+\r
+                    }\r
+                }));\r
+        window.addComponent(new Button("Scroll mainwin to Y9",\r
+                new ClickListener() {\r
+                    public void buttonClick(ClickEvent event) {\r
+                        getMainWindow().scrollIntoView(y9);\r
+\r
+                    }\r
+                }));\r
+\r
+        Panel panel = new Panel("scrollable panel");\r
+        panel.setHeight(400, Panel.UNITS_PIXELS);\r
+        panel.setScrollable(true);\r
+        panel.setScrollLeft(50);\r
+        panel.setScrollTop(50);\r
+        panel.getContent().setSizeUndefined();\r
+        window.addComponent(l("Spacer", 500, 500));\r
+\r
+        l2 = null;\r
+        for (int i = 0; i < 10; i++) {\r
+            l2 = l("X" + i);\r
+            panel.addComponent(l2);\r
+        }\r
+\r
+        final Component x29 = l2;\r
+\r
+        horizontalLayout = new HorizontalLayout();\r
+\r
+        l = null;\r
+        for (int i = 0; i < 10; i++) {\r
+            l = l("Y" + i);\r
+            horizontalLayout.addComponent(l);\r
+        }\r
+        panel.addComponent(horizontalLayout);\r
+        final Component y29 = l;\r
+\r
+        ((VerticalLayout) getMainWindow().getContent()).addComponent(\r
+                new Button("Scroll win to X9", new ClickListener() {\r
+                    public void buttonClick(ClickEvent event) {\r
+                        window.scrollIntoView(x29);\r
+                    }\r
+                }), 0);\r
+        ((VerticalLayout) getMainWindow().getContent()).addComponent(\r
+                new Button("Scroll win to Y9", new ClickListener() {\r
+                    public void buttonClick(ClickEvent event) {\r
+                        window.scrollIntoView(y29);\r
+                    }\r
+                }), 0);\r
+\r
+        window.addComponent(panel);\r
+        getMainWindow().addWindow(window);\r
+\r
+    }\r
+\r
+    private Component l(String string) {\r
+        return l(string, 200, 350);\r
+    }\r
+\r
+    private Component l(String string, int h, int w) {\r
+        Label label = new Label(string);\r
+        label.setHeight(h, Label.UNITS_PIXELS);\r
+        label.setWidth(w, Label.UNITS_PIXELS);\r
+        return label;\r
+    }\r
+}\r