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 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.components.table;
  17. import java.util.Map;
  18. import com.vaadin.event.FieldEvents.BlurEvent;
  19. import com.vaadin.event.FieldEvents.BlurListener;
  20. import com.vaadin.event.FieldEvents.FocusEvent;
  21. import com.vaadin.event.FieldEvents.FocusListener;
  22. import com.vaadin.server.VaadinRequest;
  23. import com.vaadin.tests.components.AbstractTestUIWithLog;
  24. import com.vaadin.ui.Button;
  25. import com.vaadin.ui.Button.ClickEvent;
  26. import com.vaadin.ui.Button.ClickListener;
  27. import com.vaadin.ui.Label;
  28. import com.vaadin.ui.Notification;
  29. import com.vaadin.ui.Table;
  30. /**
  31. * Tests that previously focused component's blur event happens before any
  32. * variable changes in the focused Table.
  33. *
  34. * @author Vaadin Ltd
  35. */
  36. public class TableBlurFocus extends AbstractTestUIWithLog {
  37. enum Columns {
  38. COLUMN1, COLUMN2, COLUMN3, COLUMN4, COLUMN5
  39. }
  40. private int count = 0;
  41. private Button focusButton;
  42. @Override
  43. protected void setup(VaadinRequest request) {
  44. System.out
  45. .println("TableBlurFocus/TableInIframeRowClickScrollJumpTest");
  46. Button button = new Button("click to focus");
  47. button.addFocusListener(new FocusListener() {
  48. @Override
  49. public void focus(FocusEvent event) {
  50. log("focus");
  51. }
  52. });
  53. button.addBlurListener(new BlurListener() {
  54. @Override
  55. public void blur(BlurEvent event) {
  56. log("blur");
  57. }
  58. });
  59. final Button scrollButton = new Button(
  60. "focus lowest button to scroll down");
  61. scrollButton.setId("scroll-button");
  62. scrollButton.addClickListener(new ClickListener() {
  63. @Override
  64. public void buttonClick(ClickEvent event) {
  65. focusButton.focus();
  66. }
  67. });
  68. Label spacerLabel = new Label("spacer");
  69. spacerLabel.setHeight("300px");
  70. addComponent(button);
  71. addComponent(scrollButton);
  72. addComponent(createTable());
  73. addComponent(spacerLabel);
  74. addComponent(focusButton = new Button("for focus"));
  75. focusButton.setId("focus-button");
  76. focusButton.addFocusListener(new FocusListener() {
  77. @Override
  78. public void focus(FocusEvent event) {
  79. focusButton.setCaption("focused");
  80. }
  81. });
  82. }
  83. private Table createTable() {
  84. Table table = new Table() {
  85. @Override
  86. public void changeVariables(Object source,
  87. Map<String, Object> variables) {
  88. log("variable change");
  89. super.changeVariables(source, variables);
  90. }
  91. };
  92. table.setSelectable(true);
  93. table.setImmediate(true);
  94. table.addContainerProperty(Columns.COLUMN1, String.class, " ");
  95. table.addContainerProperty(Columns.COLUMN2, Label.class, null);
  96. table.addContainerProperty(Columns.COLUMN3, Button.class, null);
  97. table.addContainerProperty(Columns.COLUMN4, String.class, " ");
  98. table.setColumnCollapsingAllowed(true);
  99. table.setColumnCollapsible(Columns.COLUMN4, true);
  100. table.setColumnCollapsed(Columns.COLUMN4, true);
  101. table.setSortEnabled(true);
  102. table.setFooterVisible(true);
  103. table.setPageLength(14);
  104. table.addGeneratedColumn(Columns.COLUMN5, new Table.ColumnGenerator() {
  105. @Override
  106. public Object generateCell(Table source, Object itemId,
  107. Object columnId) {
  108. return "Generated";
  109. }
  110. });
  111. table.setColumnHeader(Columns.COLUMN1, "Column");
  112. for (int x = 0; x < 120; x++) {
  113. final Label buttonLabel = new Label("Not clicked");
  114. Button button = new Button("Click me?", new Button.ClickListener() {
  115. @Override
  116. public void buttonClick(Button.ClickEvent event) {
  117. ++count;
  118. buttonLabel.setValue("Clicked " + count + " times");
  119. Notification.show("Clicked!");
  120. }
  121. });
  122. table.addItem(new Object[] { "entryString" + x, buttonLabel,
  123. button, " " }, "entryID" + x);
  124. }
  125. return table;
  126. }
  127. @Override
  128. protected String getTestDescription() {
  129. return "Click button to focus, then click Table header. Blur event should arrive before the next variable change.";
  130. }
  131. @Override
  132. protected Integer getTicketNumber() {
  133. return 15294;
  134. }
  135. }