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.

CompatibilityAbstractTextElementSetValue.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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.elements.abstracttextfield;
  17. import java.util.Date;
  18. import com.vaadin.server.VaadinRequest;
  19. import com.vaadin.tests.components.AbstractTestUI;
  20. import com.vaadin.v7.data.Property.ValueChangeEvent;
  21. import com.vaadin.v7.data.Property.ValueChangeListener;
  22. import com.vaadin.v7.ui.AbstractTextField;
  23. import com.vaadin.v7.ui.DateField;
  24. import com.vaadin.v7.ui.Label;
  25. import com.vaadin.v7.ui.PasswordField;
  26. import com.vaadin.v7.ui.TextArea;
  27. import com.vaadin.v7.ui.TextField;
  28. /**
  29. *
  30. * @since
  31. * @author Vaadin Ltd
  32. */
  33. public class CompatibilityAbstractTextElementSetValue extends AbstractTestUI {
  34. AbstractTextField[] comps = { new TextField(), new PasswordField(),
  35. new TextArea() };
  36. // one extra label for DateField, which we create in a separate method
  37. Label[] eventCountLabels = new Label[comps.length + 1];
  38. int[] eventCounters = new int[comps.length + 1];
  39. public static final String INITIAL_VALUE = "initial value";
  40. public static final Date INITIAL_DATE = new Date(2016, 5, 7);
  41. @Override
  42. protected void setup(VaadinRequest request) {
  43. for (int i = 0; i < comps.length; i++) {
  44. comps[i].setValue(INITIAL_VALUE);
  45. eventCountLabels[i] = new Label();
  46. eventCountLabels[i].setCaption("event count");
  47. // create an valueChangeListener, to count valueChangeListener
  48. // events
  49. comps[i].addValueChangeListener(new ValueChangeCounter(i));
  50. addComponent(comps[i]);
  51. addComponent(eventCountLabels[i]);
  52. }
  53. // add one extra label for DateField, which we create in a separate
  54. // method
  55. eventCountLabels[comps.length] = new Label();
  56. DateField df = createDateField();
  57. df.addValueChangeListener(new ValueChangeCounter(comps.length));
  58. addComponent(df);
  59. eventCountLabels[comps.length].setCaption("event count");
  60. addComponent(eventCountLabels[comps.length]);
  61. }
  62. @Override
  63. protected String getTestDescription() {
  64. return "Test type method of AbstractTextField components";
  65. }
  66. private DateField createDateField() {
  67. DateField df = new DateField();
  68. df.setValue(INITIAL_DATE);
  69. return df;
  70. }
  71. @Override
  72. protected Integer getTicketNumber() {
  73. return 13365;
  74. }
  75. // helper class, which increases valuechange event counter
  76. private class ValueChangeCounter implements ValueChangeListener {
  77. private int index;
  78. public ValueChangeCounter(int index) {
  79. this.index = index;
  80. }
  81. @Override
  82. public void valueChange(ValueChangeEvent event) {
  83. eventCounters[index]++;
  84. String value = "" + eventCounters[index];
  85. eventCountLabels[index].setValue(value);
  86. }
  87. }
  88. }