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.

AutomaticImmediate.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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.textfield;
  17. import com.vaadin.data.Property.ValueChangeEvent;
  18. import com.vaadin.data.Property.ValueChangeListener;
  19. import com.vaadin.server.VaadinRequest;
  20. import com.vaadin.tests.components.AbstractTestUIWithLog;
  21. import com.vaadin.ui.Button;
  22. import com.vaadin.ui.Button.ClickEvent;
  23. import com.vaadin.ui.Button.ClickListener;
  24. import com.vaadin.ui.CheckBox;
  25. import com.vaadin.ui.TextField;
  26. /**
  27. * Test to verify fields become implicitly "immediate" when adding value change
  28. * listener to them.
  29. *
  30. * @since 7.2
  31. * @author Vaadin Ltd
  32. */
  33. public class AutomaticImmediate extends AbstractTestUIWithLog {
  34. /**
  35. *
  36. */
  37. static final String BUTTON = "button";
  38. /**
  39. *
  40. */
  41. static final String EXPLICIT_FALSE = "explicit-false";
  42. /**
  43. *
  44. */
  45. static final String FIELD = "field";
  46. /**
  47. *
  48. */
  49. static final String LISTENER_TOGGLE = "listener-toggle";
  50. /*
  51. * (non-Javadoc)
  52. *
  53. * @see com.vaadin.tests.components.AbstractTestUI#setup(com.vaadin.server.
  54. * VaadinRequest)
  55. */
  56. @Override
  57. protected void setup(VaadinRequest request) {
  58. final TextField textField = new TextField() {
  59. /*
  60. * (non-Javadoc)
  61. *
  62. * @see com.vaadin.ui.AbstractField#fireValueChange(boolean)
  63. */
  64. @Override
  65. protected void fireValueChange(boolean repaintIsNotNeeded) {
  66. log("fireValueChange");
  67. super.fireValueChange(repaintIsNotNeeded);
  68. }
  69. };
  70. textField.setId(FIELD);
  71. final ValueChangeListener listener = new ValueChangeListener() {
  72. @Override
  73. public void valueChange(ValueChangeEvent event) {
  74. log("Value changed: " + event.getProperty().getValue());
  75. }
  76. };
  77. final CheckBox checkBox = new CheckBox("Toggle listener");
  78. checkBox.addValueChangeListener(new ValueChangeListener() {
  79. @Override
  80. public void valueChange(ValueChangeEvent event) {
  81. if (checkBox.getValue()) {
  82. textField.addValueChangeListener(listener);
  83. } else {
  84. textField.removeValueChangeListener(listener);
  85. }
  86. }
  87. });
  88. checkBox.setId(LISTENER_TOGGLE);
  89. Button b = new Button(
  90. "setImmediate(false), sets explicitly false and causes server roundtrip",
  91. new ClickListener() {
  92. @Override
  93. public void buttonClick(ClickEvent event) {
  94. textField.setImmediate(false);
  95. }
  96. });
  97. b.setId(EXPLICIT_FALSE);
  98. Button b2 = new Button("Hit server, causes server roundtrip",
  99. new ClickListener() {
  100. @Override
  101. public void buttonClick(ClickEvent event) {
  102. }
  103. });
  104. b2.setId(BUTTON);
  105. addComponent(textField);
  106. addComponent(checkBox);
  107. addComponent(b);
  108. addComponent(b2);
  109. }
  110. /*
  111. * (non-Javadoc)
  112. *
  113. * @see com.vaadin.tests.components.AbstractTestUI#getTestDescription()
  114. */
  115. @Override
  116. protected String getTestDescription() {
  117. return "Field should be immediate automatically if it has value change listener";
  118. }
  119. /*
  120. * (non-Javadoc)
  121. *
  122. * @see com.vaadin.tests.components.AbstractTestUI#getTicketNumber()
  123. */
  124. @Override
  125. protected Integer getTicketNumber() {
  126. return 8029;
  127. }
  128. }