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.

TabKeyboardNavigation.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package com.vaadin.tests.components.tabsheet;
  2. import java.util.ArrayList;
  3. import com.vaadin.event.FieldEvents.BlurEvent;
  4. import com.vaadin.event.FieldEvents.BlurListener;
  5. import com.vaadin.event.FieldEvents.FocusEvent;
  6. import com.vaadin.event.FieldEvents.FocusListener;
  7. import com.vaadin.server.VaadinRequest;
  8. import com.vaadin.tests.components.AbstractTestUI;
  9. import com.vaadin.tests.util.Log;
  10. import com.vaadin.ui.Button;
  11. import com.vaadin.ui.Button.ClickEvent;
  12. import com.vaadin.ui.Button.ClickListener;
  13. import com.vaadin.ui.Component;
  14. import com.vaadin.ui.Label;
  15. import com.vaadin.ui.Layout;
  16. import com.vaadin.ui.TabSheet;
  17. import com.vaadin.ui.TabSheet.Tab;
  18. import com.vaadin.ui.TextField;
  19. import com.vaadin.ui.VerticalLayout;
  20. /**
  21. * Test if the click and key tab selection in a tabsheet generate the correct
  22. * focus/blur events.
  23. *
  24. * The solution was broken in ticket (#14304)
  25. *
  26. * @since
  27. * @author Vaadin Ltd
  28. */
  29. public class TabKeyboardNavigation extends AbstractTestUI {
  30. int index = 1;
  31. ArrayList<Component> tabs = new ArrayList<Component>();
  32. TabSheet ts = new TabSheet();
  33. Log focusblur = new Log(10);
  34. @Override
  35. protected void setup(VaadinRequest request) {
  36. ts.setWidth("500px");
  37. ts.setHeight("500px");
  38. ts.addFocusListener(new FocusListener() {
  39. @Override
  40. public void focus(FocusEvent event) {
  41. focusblur.log("Tabsheet focused!");
  42. }
  43. });
  44. ts.addBlurListener(new BlurListener() {
  45. @Override
  46. public void blur(BlurEvent event) {
  47. focusblur.log("Tabsheet blurred!");
  48. }
  49. });
  50. for (int i = 0; i < 5; ++i) {
  51. addTab();
  52. }
  53. Button addTab = new Button("Add a tab", new ClickListener() {
  54. @Override
  55. public void buttonClick(ClickEvent event) {
  56. addTab();
  57. }
  58. });
  59. Button focus = new Button("Focus tabsheet", new ClickListener() {
  60. @Override
  61. public void buttonClick(ClickEvent event) {
  62. ts.focus();
  63. }
  64. });
  65. addComponent(addTab);
  66. addComponent(focus);
  67. TextField tf = new TextField();
  68. addComponent(tf);
  69. addComponent(focusblur);
  70. addComponent(ts);
  71. tf = new TextField();
  72. addComponent(tf);
  73. }
  74. @Override
  75. protected String getTestDescription() {
  76. return "The tab bar should be focusable and arrow keys should switch tabs. The del key should close a tab if closable.";
  77. }
  78. @Override
  79. protected Integer getTicketNumber() {
  80. return 5100;
  81. }
  82. public final static String LABEL_ID = "sheetLabel";
  83. public final static String labelID(int index) {
  84. return LABEL_ID + index;
  85. }
  86. private Tab addTab() {
  87. Layout content = new VerticalLayout();
  88. tabs.add(content);
  89. Label label = new Label("Tab " + index);
  90. label.setId(labelID(index));
  91. content.addComponent(label);
  92. content.addComponent(new TextField());
  93. Tab tab = ts.addTab(content, "Tab " + index, null);
  94. if (index == 2) {
  95. tab.setClosable(true);
  96. }
  97. if (index == 4) {
  98. tab.setEnabled(false);
  99. }
  100. index++;
  101. return tab;
  102. }
  103. }