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.

TabSelectionRevertedByServer.java 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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.Component;
  5. import com.vaadin.ui.Label;
  6. import com.vaadin.ui.Notification;
  7. import com.vaadin.ui.TabSheet;
  8. /**
  9. * TabSheet test in case user selects a tab and on the selection listener the
  10. * selected tab is changed to another one.
  11. *
  12. * This test used to cause nonfunctional TabSheet if the current tab was 1, user
  13. * selects 5, then the selection listener will revert the selected tab to 1.
  14. *
  15. * @author Vaadin Ltd
  16. */
  17. public class TabSelectionRevertedByServer extends AbstractReindeerTestUI {
  18. @Override
  19. protected void setup(VaadinRequest request) {
  20. final TabSheet tabsheet = new TabSheet();
  21. tabsheet.setWidth("400px");
  22. Component lastLabel = null;
  23. for (int i = 1; i <= 5; i++) {
  24. String caption = "Tab " + i;
  25. Label label = new Label(caption);
  26. tabsheet.addTab(label, caption);
  27. lastLabel = label;
  28. }
  29. tabsheet.setSelectedTab(0);
  30. final Component lastTab = lastLabel;
  31. tabsheet.addSelectedTabChangeListener(event -> {
  32. if (tabsheet.getSelectedTab().equals(lastTab)) {
  33. // Set focus back to first tab in tabsheet
  34. tabsheet.setSelectedTab(0);
  35. Notification.show("Focus set back to tab at position 0");
  36. }
  37. });
  38. addComponent(tabsheet);
  39. addButton("Select Last Tab", event -> tabsheet.setSelectedTab(lastTab));
  40. }
  41. @Override
  42. protected String getTestDescription() {
  43. return "Clicking on Tab 5 will revert to Tab 1. The action is handled on the server side and will set the selected tab to 1 if Tab 5 is selected.";
  44. }
  45. @Override
  46. protected Integer getTicketNumber() {
  47. return 14710;
  48. }
  49. }