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.

ComboBoxResetValue.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package com.vaadin.tests.components.combobox;
  2. import com.vaadin.server.VaadinRequest;
  3. import com.vaadin.tests.components.AbstractReindeerTestUI;
  4. import com.vaadin.ui.Button;
  5. import com.vaadin.ui.HorizontalLayout;
  6. import com.vaadin.ui.VerticalLayout;
  7. import com.vaadin.v7.ui.ComboBox;
  8. public class ComboBoxResetValue extends AbstractReindeerTestUI {
  9. protected static final String EMPTY_VALUE = "Empty value";
  10. protected static final String WITH_SET_NULL_SELECTION_ITEM_ID = "nullSelectionAllowedWithSetNullSelectionItemId";
  11. protected static final String WITHOUT_NULL_SELECTION_ITEM_ID = "nullSelectionAllowedWithoutNullSelectionItemId";
  12. protected static final String NULL_SELECTION_NOT_ALLOWED = "nullSelectionNotAllowed";
  13. @Override
  14. protected void setup(VaadinRequest request) {
  15. final ComboBox cbNullSelectionAllowedWithSetNullSelectionItemId = getComboBoxWithNullSelectionAllowedWithSetNullSelectionItemId();
  16. final ComboBox cbNullSelectionAllowedWithoutNullSelectionItemId = getComboBoxWithNullSelectionAllowedWithoutNullSelectionItemId();
  17. final ComboBox cbNullSelectionNotAllowed = getComboBoxWithNullSelectionNotAllowed();
  18. Button b = new Button("Reset");
  19. b.addClickListener(event -> {
  20. cbNullSelectionAllowedWithSetNullSelectionItemId.setValue(null);
  21. cbNullSelectionAllowedWithoutNullSelectionItemId.setValue(null);
  22. cbNullSelectionNotAllowed.setValue(null);
  23. });
  24. addComponents(new HorizontalLayout(new VerticalLayout(
  25. cbNullSelectionAllowedWithSetNullSelectionItemId,
  26. cbNullSelectionAllowedWithoutNullSelectionItemId,
  27. cbNullSelectionNotAllowed), b));
  28. }
  29. protected ComboBox getComboBoxWithNullSelectionAllowedWithSetNullSelectionItemId() {
  30. ComboBox cb = new ComboBox();
  31. cb.setId(WITH_SET_NULL_SELECTION_ITEM_ID);
  32. cb.setImmediate(true);
  33. cb.setNullSelectionAllowed(true);
  34. cb.addItem(EMPTY_VALUE);
  35. cb.setNullSelectionItemId(EMPTY_VALUE);
  36. cb.addItem(1);
  37. cb.select(1);
  38. return cb;
  39. }
  40. protected ComboBox getComboBoxWithNullSelectionAllowedWithoutNullSelectionItemId() {
  41. ComboBox cb = new ComboBox();
  42. cb.setId(WITHOUT_NULL_SELECTION_ITEM_ID);
  43. cb.setImmediate(true);
  44. cb.setNullSelectionAllowed(true);
  45. cb.addItem(1);
  46. cb.select(1);
  47. return cb;
  48. }
  49. protected ComboBox getComboBoxWithNullSelectionNotAllowed() {
  50. ComboBox cb = new ComboBox();
  51. cb.setId(NULL_SELECTION_NOT_ALLOWED);
  52. cb.setImmediate(true);
  53. cb.setNullSelectionAllowed(false);
  54. cb.addItem(1);
  55. cb.select(1);
  56. return cb;
  57. }
  58. @Override
  59. protected Integer getTicketNumber() {
  60. return 13217;
  61. }
  62. @Override
  63. protected String getTestDescription() {
  64. return "Tests that reseting (setValue(null), select(null)) of combobox works correctly (removes/updates old selection, also correctly works with filtering)";
  65. }
  66. }