private ArrayList<String> jsExecQueue = null;
+ private Component scrollIntoView;
+
/* ********************************************************************* */
/**
centerRequested = false;
}
+ if (scrollIntoView != null) {
+ target.addAttribute("scrollTo", scrollIntoView);
+ scrollIntoView = null;
+ }
+
// Marks the main window
if (getApplication() != null
&& this == getApplication().getMainWindow()) {
/* ********************************************************************* */
+ /**
+ * 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.
*
@Override
public void handleAction(Object sender, Object target) {
- this.window.close();
+ window.close();
}
}
}
--- /dev/null
+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