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.

TextChangeListenerLosesFocus.java 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright 2012 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.textfield;
  17. import com.vaadin.event.FieldEvents.TextChangeEvent;
  18. import com.vaadin.event.FieldEvents.TextChangeListener;
  19. import com.vaadin.tests.components.TestBase;
  20. import com.vaadin.tests.util.TestUtils;
  21. import com.vaadin.ui.AbstractTextField;
  22. import com.vaadin.ui.Field;
  23. import com.vaadin.ui.TextArea;
  24. import com.vaadin.ui.TextField;
  25. public class TextChangeListenerLosesFocus extends TestBase {
  26. private final TextChangeListener listener = new TextChangeListener() {
  27. public void textChange(TextChangeEvent event) {
  28. final String value = event.getText();
  29. if (value.length() > 2) {
  30. ((Field) event.getComponent())
  31. .setValue("Updated by TextChangeListener");
  32. }
  33. }
  34. };
  35. @Override
  36. protected void setup() {
  37. TestUtils.injectCSS(getMainWindow(),
  38. ".v-textfield-focus, .v-textarea-focus { "
  39. + " background: #E8F0FF !important }");
  40. AbstractTextField field = new TextField();
  41. field.setDebugId("test-textfield");
  42. field.setInputPrompt("Enter at least 3 characters");
  43. field.addListener(listener);
  44. addComponent(field);
  45. field = new TextArea();
  46. field.setDebugId("test-textarea");
  47. field.setInputPrompt("Enter at least 3 characters");
  48. field.addListener(listener);
  49. addComponent(field);
  50. }
  51. @Override
  52. protected String getDescription() {
  53. return "Updating a focused TextField overwrites the focus stylename";
  54. }
  55. @Override
  56. protected Integer getTicketNumber() {
  57. return 11623;
  58. }
  59. }