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.

DateFieldValueChangeEvents.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright 2000-2016 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. /**
  17. *
  18. */
  19. package com.vaadin.tests.components.datefield;
  20. import java.util.Arrays;
  21. import java.util.Calendar;
  22. import com.vaadin.server.VaadinRequest;
  23. import com.vaadin.shared.ui.datefield.Resolution;
  24. import com.vaadin.tests.components.AbstractTestUIWithLog;
  25. import com.vaadin.tests.components.TestDateField;
  26. import com.vaadin.ui.AbstractDateField;
  27. import com.vaadin.ui.HorizontalLayout;
  28. import com.vaadin.v7.data.Property.ValueChangeEvent;
  29. import com.vaadin.v7.data.Property.ValueChangeListener;
  30. import com.vaadin.v7.ui.NativeSelect;
  31. /**
  32. *
  33. * @since
  34. * @author Vaadin Ltd
  35. */
  36. public class DateFieldValueChangeEvents extends AbstractTestUIWithLog {
  37. private int count = 0;
  38. /*
  39. * (non-Javadoc)
  40. *
  41. * @see com.vaadin.tests.components.AbstractTestUI#setup(com.vaadin.server.
  42. * VaadinRequest)
  43. */
  44. @Override
  45. protected void setup(VaadinRequest request) {
  46. HorizontalLayout hl = new HorizontalLayout();
  47. addComponent(hl);
  48. Calendar calendar = Calendar.getInstance();
  49. calendar.set(2010, 1, 1, 18, 19, 20);
  50. final AbstractDateField df = new TestDateField(null,
  51. calendar.getTime());
  52. df.setResolution(Resolution.SECOND);
  53. df.setImmediate(true);
  54. hl.addComponent(df);
  55. NativeSelect resolution = new NativeSelect(null,
  56. Arrays.asList(Resolution.values()));
  57. resolution.setImmediate(true);
  58. resolution.setValue(df.getResolution());
  59. hl.addComponent(resolution);
  60. resolution.addValueChangeListener(new ValueChangeListener() {
  61. @Override
  62. public void valueChange(ValueChangeEvent event) {
  63. df.setResolution((Resolution) event.getProperty().getValue());
  64. }
  65. });
  66. df.addValueChangeListener(event -> log("Value changes: " + (++count)));
  67. }
  68. /*
  69. * (non-Javadoc)
  70. *
  71. * @see com.vaadin.tests.components.AbstractTestUI#getTestDescription()
  72. */
  73. @Override
  74. protected String getTestDescription() {
  75. return "DateField Time resolution fields should only send events when focus is removed";
  76. }
  77. /*
  78. * (non-Javadoc)
  79. *
  80. * @see com.vaadin.tests.components.AbstractTestUI#getTicketNumber()
  81. */
  82. @Override
  83. protected Integer getTicketNumber() {
  84. return 6252;
  85. }
  86. }