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.

CompatibilityDateFieldShortcut.java 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package com.vaadin.tests.components.datefield;
  2. import java.text.SimpleDateFormat;
  3. import java.util.Date;
  4. import com.vaadin.event.ShortcutAction.KeyCode;
  5. import com.vaadin.event.ShortcutListener;
  6. import com.vaadin.server.VaadinRequest;
  7. import com.vaadin.tests.components.AbstractTestUI;
  8. import com.vaadin.ui.Notification;
  9. import com.vaadin.v7.ui.DateField;
  10. @SuppressWarnings("deprecation")
  11. public class CompatibilityDateFieldShortcut extends AbstractTestUI {
  12. @Override
  13. protected void setup(VaadinRequest request) {
  14. String dateFormat = "dd/MM/yyyy";
  15. DateField dateField = new DateField();
  16. dateField.setValue(new Date(2018 - 1900, 0, 11));
  17. dateField.setDateFormat(dateFormat);
  18. dateField.addShortcutListener(
  19. new ShortcutListener("Enter", KeyCode.ENTER, null) {
  20. @Override
  21. public void handleAction(Object sender, Object target) {
  22. SimpleDateFormat df = new SimpleDateFormat(dateFormat);
  23. Notification.show(df.format(dateField.getValue()));
  24. }
  25. });
  26. addComponent(dateField);
  27. }
  28. @Override
  29. protected String getTestDescription() {
  30. return "Modify the date manually (without using the popup element) and"
  31. + " then press Enter. The notification should show the modified"
  32. + " value instead of the old value.";
  33. }
  34. @Override
  35. protected Integer getTicketNumber() {
  36. return 10854;
  37. }
  38. }