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.

CheckBoxRevertValueChange.java 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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.checkbox;
  17. import com.vaadin.annotations.PreserveOnRefresh;
  18. import com.vaadin.data.Property;
  19. import com.vaadin.server.VaadinRequest;
  20. import com.vaadin.tests.components.AbstractTestUIWithLog;
  21. import com.vaadin.ui.CheckBox;
  22. @PreserveOnRefresh
  23. public class CheckBoxRevertValueChange extends AbstractTestUIWithLog {
  24. @Override
  25. protected void setup(VaadinRequest request) {
  26. final CheckBox alwaysUnchecked = new CheckBox("You may not check me");
  27. alwaysUnchecked
  28. .addValueChangeListener(new Property.ValueChangeListener() {
  29. @Override
  30. public void valueChange(Property.ValueChangeEvent event) {
  31. if (alwaysUnchecked.getValue()) {
  32. log("I said no checking!");
  33. alwaysUnchecked.setValue(false);
  34. }
  35. }
  36. });
  37. final CheckBox alwaysChecked = new CheckBox("You may not uncheck me");
  38. alwaysChecked.setValue(true);
  39. alwaysChecked
  40. .addValueChangeListener(new Property.ValueChangeListener() {
  41. @Override
  42. public void valueChange(Property.ValueChangeEvent event) {
  43. if (!alwaysChecked.getValue()) {
  44. log("I said no unchecking!");
  45. alwaysChecked.setValue(true);
  46. }
  47. }
  48. });
  49. addComponent(alwaysUnchecked);
  50. addComponent(alwaysChecked);
  51. }
  52. @Override
  53. protected String getTestDescription() {
  54. return "Ensure checking of a checkbox can be reverted on the server side without making the client go out of sync";
  55. }
  56. @Override
  57. protected Integer getTicketNumber() {
  58. return 11028;
  59. }
  60. }