Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

InlineDateFields.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package com.vaadin.tests.components.datefield;
  2. import java.time.LocalDate;
  3. import java.util.LinkedHashMap;
  4. import java.util.List;
  5. import java.util.Locale;
  6. import com.vaadin.shared.ui.datefield.DateResolution;
  7. import com.vaadin.tests.components.ComponentTestCase;
  8. import com.vaadin.ui.Component;
  9. import com.vaadin.ui.InlineDateField;
  10. @SuppressWarnings("serial")
  11. public class InlineDateFields extends ComponentTestCase<InlineDateField> {
  12. private static final Locale[] LOCALES = { Locale.US, Locale.TAIWAN,
  13. new Locale("fi", "FI") };
  14. @Override
  15. protected Class<InlineDateField> getTestClass() {
  16. return InlineDateField.class;
  17. }
  18. @Override
  19. protected void initializeComponents() {
  20. InlineDateField hidden = new InlineDateField();
  21. hidden.setVisible(false); // Used to break rest of layout #8693
  22. addComponent(hidden);
  23. Locale locale = LOCALES[0];
  24. InlineDateField pd = createInlineDateField("Undefined width", "-1",
  25. locale);
  26. pd.setId("Locale-" + locale + "-undefined-wide");
  27. addTestComponent(pd);
  28. pd = createInlineDateField("300px width", "300px", locale);
  29. pd.setId("Locale-" + locale + "-300px-wide");
  30. addTestComponent(pd);
  31. pd = createInlineDateField("Initially empty", "", locale);
  32. pd.setValue(null);
  33. pd.setId("Locale-" + locale + "-initially-empty");
  34. addTestComponent(pd);
  35. }
  36. private InlineDateField createInlineDateField(String caption, String width,
  37. Locale locale) {
  38. InlineDateField pd = new InlineDateField(caption + "(" + locale + ")");
  39. pd.setWidth(width);
  40. pd.setValue(LocalDate.of(1970, 05, 23));
  41. pd.setLocale(locale);
  42. pd.setResolution(DateResolution.YEAR);
  43. return pd;
  44. }
  45. @Override
  46. protected String getTestDescription() {
  47. return "A generic test for InlineDateFields in different configurations";
  48. }
  49. @Override
  50. protected List<Component> createActions() {
  51. List<Component> actions = super.createActions();
  52. actions.add(createResolutionSelectAction());
  53. actions.add(createLocaleSelectAction());
  54. return actions;
  55. }
  56. private Component createResolutionSelectAction() {
  57. LinkedHashMap<String, DateResolution> options = new LinkedHashMap<>();
  58. options.put("Year", DateResolution.YEAR);
  59. options.put("Month", DateResolution.MONTH);
  60. options.put("Day", DateResolution.DAY);
  61. return createSelectAction("Resolution", options, "Year",
  62. (field, value, data) -> field.setResolution(value));
  63. }
  64. private Component createLocaleSelectAction() {
  65. LinkedHashMap<String, Locale> options = new LinkedHashMap<>();
  66. for (Locale locale : LOCALES) {
  67. options.put(locale.toString(), locale);
  68. }
  69. return createSelectAction("Locale", options, LOCALES[0].toString(),
  70. new Command<InlineDateField, Locale>() {
  71. @Override
  72. public void execute(InlineDateField c, Locale value,
  73. Object data) {
  74. c.setCaption(c.getCaption().replaceAll(
  75. c.getLocale().toString(), value.toString()));
  76. c.setLocale(value);
  77. }
  78. });
  79. }
  80. }