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.

TableBlurFocus.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package com.vaadin.tests.components.table;
  2. import java.util.Map;
  3. import com.vaadin.server.VaadinRequest;
  4. import com.vaadin.tests.components.AbstractReindeerTestUIWithLog;
  5. import com.vaadin.ui.Button;
  6. import com.vaadin.ui.Label;
  7. import com.vaadin.ui.Notification;
  8. import com.vaadin.v7.ui.Table;
  9. /**
  10. * Tests that previously focused component's blur event happens before any
  11. * variable changes in the focused Table.
  12. *
  13. * @author Vaadin Ltd
  14. */
  15. public class TableBlurFocus extends AbstractReindeerTestUIWithLog {
  16. enum Columns {
  17. COLUMN1, COLUMN2, COLUMN3, COLUMN4, COLUMN5
  18. }
  19. private int count = 0;
  20. private Button focusButton;
  21. @Override
  22. protected void setup(VaadinRequest request) {
  23. System.out
  24. .println("TableBlurFocus/TableInIframeRowClickScrollJumpTest");
  25. Button button = new Button("click to focus");
  26. button.addFocusListener(event -> log("focus"));
  27. button.addBlurListener(event -> log("blur"));
  28. final Button scrollButton = new Button(
  29. "focus lowest button to scroll down");
  30. scrollButton.setId("scroll-button");
  31. scrollButton.addClickListener(event -> focusButton.focus());
  32. Label spacerLabel = new Label("spacer");
  33. spacerLabel.setHeight("300px");
  34. addComponent(button);
  35. addComponent(scrollButton);
  36. addComponent(createTable());
  37. addComponent(spacerLabel);
  38. addComponent(focusButton = new Button("for focus"));
  39. focusButton.setId("focus-button");
  40. focusButton
  41. .addFocusListener(event -> focusButton.setCaption("focused"));
  42. }
  43. private Table createTable() {
  44. Table table = new Table() {
  45. @Override
  46. public void changeVariables(Object source,
  47. Map<String, Object> variables) {
  48. log("variable change");
  49. super.changeVariables(source, variables);
  50. }
  51. };
  52. table.setSelectable(true);
  53. table.setImmediate(true);
  54. table.addContainerProperty(Columns.COLUMN1, String.class, " ");
  55. table.addContainerProperty(Columns.COLUMN2, Label.class, null);
  56. table.addContainerProperty(Columns.COLUMN3, Button.class, null);
  57. table.addContainerProperty(Columns.COLUMN4, String.class, " ");
  58. table.setColumnCollapsingAllowed(true);
  59. table.setColumnCollapsible(Columns.COLUMN4, true);
  60. table.setColumnCollapsed(Columns.COLUMN4, true);
  61. table.setSortEnabled(true);
  62. table.setFooterVisible(true);
  63. table.setPageLength(14);
  64. table.addGeneratedColumn(Columns.COLUMN5, new Table.ColumnGenerator() {
  65. @Override
  66. public Object generateCell(Table source, Object itemId,
  67. Object columnId) {
  68. return "Generated";
  69. }
  70. });
  71. table.setColumnHeader(Columns.COLUMN1, "Column");
  72. for (int x = 0; x < 120; x++) {
  73. final Label buttonLabel = new Label("Not clicked");
  74. Button button = new Button("Click me?", event -> {
  75. ++count;
  76. buttonLabel.setValue("Clicked " + count + " times");
  77. Notification.show("Clicked!");
  78. });
  79. table.addItem(new Object[] { "entryString" + x, buttonLabel, button,
  80. " " }, "entryID" + x);
  81. }
  82. return table;
  83. }
  84. @Override
  85. protected String getTestDescription() {
  86. return "Click button to focus, then click Table header. Blur event should arrive before the next variable change.";
  87. }
  88. @Override
  89. protected Integer getTicketNumber() {
  90. return 15294;
  91. }
  92. }