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.

DateFieldShortcut.java 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package com.vaadin.tests.components.datefield;
  2. import java.time.LocalDate;
  3. import java.time.format.DateTimeFormatter;
  4. import com.vaadin.annotations.Widgetset;
  5. import com.vaadin.event.ShortcutAction.KeyCode;
  6. import com.vaadin.event.ShortcutListener;
  7. import com.vaadin.server.VaadinRequest;
  8. import com.vaadin.tests.components.AbstractTestUI;
  9. import com.vaadin.ui.DateField;
  10. import com.vaadin.ui.Notification;
  11. @Widgetset("com.vaadin.DefaultWidgetSet")
  12. public class DateFieldShortcut extends AbstractTestUI {
  13. @Override
  14. protected void setup(VaadinRequest request) {
  15. String dateFormat = "dd/MM/yyyy";
  16. DateField dateField = new DateField();
  17. dateField.setValue(LocalDate.of(2018, 1, 11));
  18. dateField.setDateFormat(dateFormat);
  19. dateField.addShortcutListener(
  20. new ShortcutListener("Enter", KeyCode.ENTER, null) {
  21. @Override
  22. public void handleAction(Object sender, Object target) {
  23. Notification.show(dateField.getValue().format(
  24. DateTimeFormatter.ofPattern(dateFormat)));
  25. }
  26. });
  27. addComponent(dateField);
  28. }
  29. @Override
  30. protected String getTestDescription() {
  31. return "Modify the date maually (without using the popup element) and"
  32. + " then press Enter. The notification should show the modified"
  33. + " value instead of the old value.";
  34. }
  35. }