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.

DynamicallyChangeDateRange.java 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package com.vaadin.tests.components.datefield;
  2. import java.time.LocalDate;
  3. import java.util.Locale;
  4. import com.vaadin.server.VaadinRequest;
  5. import com.vaadin.tests.components.AbstractReindeerTestUI;
  6. import com.vaadin.ui.AbstractDateField;
  7. import com.vaadin.ui.Button;
  8. import com.vaadin.ui.Button.ClickEvent;
  9. import com.vaadin.ui.DateField;
  10. import com.vaadin.ui.InlineDateField;
  11. import com.vaadin.ui.VerticalLayout;
  12. /**
  13. * Main UI class
  14. */
  15. @SuppressWarnings("serial")
  16. public class DynamicallyChangeDateRange extends AbstractReindeerTestUI {
  17. @Override
  18. protected void setup(VaadinRequest request) {
  19. setLocale(Locale.ENGLISH);
  20. final VerticalLayout layout = new VerticalLayout();
  21. layout.setMargin(true);
  22. setContent(layout);
  23. final DateField df = new DateField();
  24. df.setValue(LocalDate.of(2012, 5, 12));
  25. setRange(df, 5);
  26. layout.addComponent(df);
  27. final InlineDateField df2 = new InlineDateField();
  28. df2.setValue(LocalDate.of(2012, 11, 16));
  29. setRange(df2, 5);
  30. // layout.addComponent(df2);
  31. Button button1 = new Button("Set Range Now+/-5d");
  32. button1.addClickListener(new Button.ClickListener() {
  33. @Override
  34. public void buttonClick(ClickEvent event) {
  35. setRange(df, 5);
  36. setRange(df2, 5);
  37. }
  38. });
  39. layout.addComponent(button1);
  40. Button button2 = new Button("Set Range Now+/-10d");
  41. button2.addClickListener(new Button.ClickListener() {
  42. @Override
  43. public void buttonClick(ClickEvent event) {
  44. setRange(df, 10);
  45. setRange(df2, 10);
  46. }
  47. });
  48. layout.addComponent(button2);
  49. }
  50. private void setRange(AbstractDateField df, int days) {
  51. df.setRangeStart(df.getValue().minusDays(days));
  52. df.setRangeEnd(df.getValue().plusDays(days));
  53. }
  54. /*
  55. * (non-Javadoc)
  56. *
  57. * @see com.vaadin.tests.components.AbstractTestUI#getTestDescription()
  58. */
  59. @Override
  60. protected String getTestDescription() {
  61. return "Verifies that the allowed date range can be updated dynamically";
  62. }
  63. /*
  64. * (non-Javadoc)
  65. *
  66. * @see com.vaadin.tests.components.AbstractTestUI#getTicketNumber()
  67. */
  68. @Override
  69. protected Integer getTicketNumber() {
  70. return 11940;
  71. }
  72. }