選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

DateForm.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. package com.vaadin.tests.fieldgroup;
  2. import java.util.Date;
  3. import java.util.Locale;
  4. import com.vaadin.annotations.PropertyId;
  5. import com.vaadin.server.VaadinRequest;
  6. import com.vaadin.tests.components.AbstractTestUIWithLog;
  7. import com.vaadin.tests.data.bean.Person;
  8. import com.vaadin.ui.Button;
  9. import com.vaadin.ui.Button.ClickEvent;
  10. import com.vaadin.ui.Notification;
  11. import com.vaadin.v7.data.fieldgroup.BeanFieldGroup;
  12. import com.vaadin.v7.data.fieldgroup.FieldGroup;
  13. import com.vaadin.v7.data.fieldgroup.FieldGroup.CommitException;
  14. import com.vaadin.v7.data.util.BeanItem;
  15. import com.vaadin.v7.ui.DateField;
  16. import com.vaadin.v7.ui.InlineDateField;
  17. import com.vaadin.v7.ui.PopupDateField;
  18. import com.vaadin.v7.ui.TextField;
  19. public class DateForm extends AbstractTestUIWithLog {
  20. @PropertyId("date1")
  21. private DateField dateField;
  22. @PropertyId("date2")
  23. private PopupDateField popupDateField;
  24. @PropertyId("date3")
  25. private InlineDateField inlineDateField;
  26. @PropertyId("date4")
  27. private TextField textField;
  28. public static class DateObject {
  29. private Date date1, date2, date3, date4;
  30. public DateObject(Date date1, Date date2, Date date3, Date date4) {
  31. super();
  32. this.date1 = date1;
  33. this.date2 = date2;
  34. this.date3 = date3;
  35. this.date4 = date4;
  36. }
  37. public Date getDate1() {
  38. return date1;
  39. }
  40. public void setDate1(Date date1) {
  41. this.date1 = date1;
  42. }
  43. public Date getDate2() {
  44. return date2;
  45. }
  46. public void setDate2(Date date2) {
  47. this.date2 = date2;
  48. }
  49. public Date getDate3() {
  50. return date3;
  51. }
  52. public void setDate3(Date date3) {
  53. this.date3 = date3;
  54. }
  55. public Date getDate4() {
  56. return date4;
  57. }
  58. public void setDate4(Date date4) {
  59. this.date4 = date4;
  60. }
  61. }
  62. @Override
  63. protected void setup(VaadinRequest request) {
  64. setLocale(Locale.US);
  65. addComponent(log);
  66. final FieldGroup fieldGroup = new BeanFieldGroup<>(DateObject.class);
  67. fieldGroup.setBuffered(true);
  68. fieldGroup.buildAndBindMemberFields(this);
  69. textField.setWidth("20em");
  70. addComponent(dateField);
  71. addComponent(popupDateField);
  72. addComponent(inlineDateField);
  73. addComponent(textField);
  74. Button commitButton = new Button("Commit", new Button.ClickListener() {
  75. @Override
  76. public void buttonClick(ClickEvent event) {
  77. String msg = "Commit succesful";
  78. try {
  79. fieldGroup.commit();
  80. } catch (CommitException e) {
  81. msg = "Commit failed: " + e.getMessage();
  82. }
  83. Notification.show(msg);
  84. log(msg);
  85. }
  86. });
  87. Button discardButton = new Button("Discard",
  88. new Button.ClickListener() {
  89. @Override
  90. public void buttonClick(ClickEvent event) {
  91. fieldGroup.discard();
  92. log("Discarded changes");
  93. }
  94. });
  95. Button showBean = new Button("Show bean values",
  96. new Button.ClickListener() {
  97. @Override
  98. public void buttonClick(ClickEvent event) {
  99. log(getPerson(fieldGroup).toString());
  100. }
  101. });
  102. addComponent(commitButton);
  103. addComponent(discardButton);
  104. addComponent(showBean);
  105. DateObject d = new DateObject(new Date(443457289789L),
  106. new Date(443543689789L), new Date(443457289789L),
  107. new Date(443457289789L));
  108. fieldGroup.setItemDataSource(new BeanItem<>(d));
  109. }
  110. @SuppressWarnings("unchecked")
  111. public static Person getPerson(FieldGroup binder) {
  112. return ((BeanItem<Person>) binder.getItemDataSource()).getBean();
  113. }
  114. @Override
  115. protected String getTestDescription() {
  116. return "Ensure FieldGroupFieldFactory supports Dates";
  117. }
  118. @Override
  119. protected Integer getTicketNumber() {
  120. return 8539;
  121. }
  122. }