You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WindowScrollingComponentIntoView.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package com.vaadin.tests.components.window;
  2. import com.vaadin.tests.components.AbstractTestCase;
  3. import com.vaadin.ui.Button;
  4. import com.vaadin.ui.Component;
  5. import com.vaadin.ui.HorizontalLayout;
  6. import com.vaadin.ui.Label;
  7. import com.vaadin.ui.LegacyWindow;
  8. import com.vaadin.ui.Panel;
  9. import com.vaadin.ui.VerticalLayout;
  10. import com.vaadin.ui.Window;
  11. import com.vaadin.v7.ui.Table;
  12. public class WindowScrollingComponentIntoView extends AbstractTestCase {
  13. @Override
  14. protected String getDescription() {
  15. return "Scroll down, click 'up' and the view should scroll to the top";
  16. }
  17. @Override
  18. protected Integer getTicketNumber() {
  19. return 4206;
  20. }
  21. @Override
  22. public void init() {
  23. Table table = new Table();
  24. table.setPageLength(50);
  25. setMainWindow(new LegacyWindow(""));
  26. getMainWindow().getContent().setSizeUndefined();
  27. Component l2 = null;
  28. for (int i = 0; i < 10; i++) {
  29. l2 = l("X" + i);
  30. getMainWindow().addComponent(l2);
  31. }
  32. final Component x9 = l2;
  33. HorizontalLayout horizontalLayout = new HorizontalLayout();
  34. Component l = null;
  35. for (int i = 0; i < 10; i++) {
  36. l = l("Y" + i);
  37. horizontalLayout.addComponent(l);
  38. }
  39. getMainWindow().addComponent(horizontalLayout);
  40. final Component y9 = l;
  41. VerticalLayout layout = new VerticalLayout();
  42. layout.setMargin(true);
  43. final Window window = new Window();
  44. window.setHeight("500px");
  45. window.setWidth("500px");
  46. window.setPositionX(200);
  47. window.setPositionY(200);
  48. layout.addComponent(new Button("Scroll mainwin to X9",
  49. event -> getMainWindow().scrollIntoView(x9)));
  50. layout.addComponent(new Button("Scroll mainwin to Y9",
  51. event -> getMainWindow().scrollIntoView(y9)));
  52. VerticalLayout panelLayout = new VerticalLayout();
  53. panelLayout.setMargin(true);
  54. Panel panel = new Panel("scrollable panel", panelLayout);
  55. panel.setHeight(400, Panel.UNITS_PIXELS);
  56. panel.setScrollLeft(50);
  57. panel.setScrollTop(50);
  58. panelLayout.setSizeUndefined();
  59. layout.addComponent(l("Spacer", 500, 500));
  60. l2 = null;
  61. for (int i = 0; i < 10; i++) {
  62. l2 = l("X" + i);
  63. panelLayout.addComponent(l2);
  64. }
  65. final Component x29 = l2;
  66. horizontalLayout = new HorizontalLayout();
  67. l = null;
  68. for (int i = 0; i < 10; i++) {
  69. l = l("Y" + i);
  70. horizontalLayout.addComponent(l);
  71. }
  72. panelLayout.addComponent(horizontalLayout);
  73. final Component y29 = l;
  74. ((VerticalLayout) getMainWindow().getContent())
  75. .addComponent(new Button("Scroll win to X9", event -> {
  76. throw new RuntimeException("Currently not implemented");
  77. // window.scrollIntoView(x29);
  78. }), 0);
  79. ((VerticalLayout) getMainWindow().getContent())
  80. .addComponent(new Button("Scroll win to Y9", event -> {
  81. throw new RuntimeException("Currently not implemented");
  82. // window.scrollIntoView(y29);
  83. }), 0);
  84. layout.addComponent(panel);
  85. getMainWindow().addWindow(window);
  86. }
  87. private Component l(String string) {
  88. return l(string, 200, 350);
  89. }
  90. private Component l(String string, int h, int w) {
  91. Label label = new Label(string);
  92. label.setHeight(h, Label.UNITS_PIXELS);
  93. label.setWidth(w, Label.UNITS_PIXELS);
  94. return label;
  95. }
  96. }