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.

TabSheetScrollOnTabClose.java 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package com.vaadin.tests.components.tabsheet;
  2. import com.vaadin.server.VaadinRequest;
  3. import com.vaadin.tests.components.AbstractReindeerTestUI;
  4. import com.vaadin.ui.Button;
  5. import com.vaadin.ui.CssLayout;
  6. import com.vaadin.ui.Label;
  7. import com.vaadin.ui.TabSheet;
  8. import com.vaadin.ui.TabSheet.Tab;
  9. /**
  10. * This testUI is used for testing that the scroll position of a tab sheet does
  11. * not change when tabs are removed. The exception is removing the leftmost
  12. * visible tab.
  13. *
  14. * @author Vaadin Ltd
  15. */
  16. public class TabSheetScrollOnTabClose extends AbstractReindeerTestUI {
  17. /*
  18. * (non-Javadoc)
  19. *
  20. * @see com.vaadin.tests.components.AbstractTestUI#setup(com.vaadin.server.
  21. * VaadinRequest)
  22. */
  23. @Override
  24. protected void setup(VaadinRequest request) {
  25. final TabSheet tabSheet = new TabSheet();
  26. for (int i = 0; i < 10; i++) {
  27. Tab tab = tabSheet.addTab(new CssLayout(), "tab " + i);
  28. tab.setClosable(true);
  29. tab.setId("tab" + i);
  30. }
  31. tabSheet.setWidth(250, Unit.PIXELS);
  32. addComponent(tabSheet);
  33. addComponent(new Label("Close tab number"));
  34. for (int i = 0; i < 10; i++) {
  35. final String tabCaption = "tab " + i;
  36. final Button b = new Button("" + i);
  37. b.addClickListener(event -> {
  38. b.setEnabled(false);
  39. tabSheet.removeTab(getTab(tabSheet, tabCaption));
  40. });
  41. addComponent(b);
  42. }
  43. }
  44. private Tab getTab(TabSheet ts, String tabCaption) {
  45. for (int i = 0; i < ts.getComponentCount(); i++) {
  46. String caption = ts.getTab(i).getCaption();
  47. if (tabCaption.equals(caption)) {
  48. return ts.getTab(i);
  49. }
  50. }
  51. return null;
  52. }
  53. /*
  54. * (non-Javadoc)
  55. *
  56. * @see com.vaadin.tests.components.AbstractTestUI#getTestDescription()
  57. */
  58. @Override
  59. protected String getTestDescription() {
  60. return "Scroll position should not change when closing tabs.";
  61. }
  62. /*
  63. * (non-Javadoc)
  64. *
  65. * @see com.vaadin.tests.components.AbstractTestUI#getTicketNumber()
  66. */
  67. @Override
  68. protected Integer getTicketNumber() {
  69. return 14348;
  70. }
  71. }