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.

DateFieldChangeResolution.java 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package com.vaadin.tests.components.datefield;
  2. import java.util.Locale;
  3. import com.vaadin.server.VaadinRequest;
  4. import com.vaadin.shared.ui.datefield.DateResolution;
  5. import com.vaadin.tests.components.AbstractReindeerTestUI;
  6. import com.vaadin.ui.AbstractLocalDateField;
  7. import com.vaadin.ui.Button;
  8. import com.vaadin.ui.DateField;
  9. import com.vaadin.ui.HorizontalLayout;
  10. import com.vaadin.ui.Label;
  11. public class DateFieldChangeResolution extends AbstractReindeerTestUI {
  12. public static final String DATEFIELD_ID = "datefield";
  13. // The ID of a button is BUTTON_BASE_ID + resolution, e.g. button-month
  14. public static final String BUTTON_BASE_ID = "button-";
  15. @Override
  16. protected void setup(VaadinRequest request) {
  17. final AbstractLocalDateField dateField = new DateField("Enter date");
  18. dateField.setResolution(DateResolution.YEAR);
  19. dateField.setId(DATEFIELD_ID);
  20. addComponent(dateField);
  21. Label l = new Label("Select resolution");
  22. addComponent(l);
  23. HorizontalLayout hlayout = new HorizontalLayout();
  24. addComponent(hlayout);
  25. for (final DateResolution value : DateResolution.values()) {
  26. String resolutionString = value.toString().toLowerCase(Locale.ROOT);
  27. Button button = new Button(resolutionString);
  28. button.addClickListener(event -> dateField.setResolution(value));
  29. button.setId(BUTTON_BASE_ID + resolutionString);
  30. hlayout.addComponent(button);
  31. }
  32. }
  33. @Override
  34. protected String getTestDescription() {
  35. return "The calendar should always have the correct resolution and the text field should be empty before selecting a date.";
  36. }
  37. @Override
  38. protected Integer getTicketNumber() {
  39. return 14174;
  40. }
  41. }