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.

ComboBoxDataSourceChange.java 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package com.vaadin.tests.components.combobox;
  2. import com.vaadin.tests.components.TestBase;
  3. import com.vaadin.ui.Button;
  4. import com.vaadin.ui.HorizontalLayout;
  5. import com.vaadin.ui.Label;
  6. import com.vaadin.v7.data.util.IndexedContainer;
  7. import com.vaadin.v7.ui.ComboBox;
  8. import com.vaadin.v7.ui.Table;
  9. @SuppressWarnings("serial")
  10. public class ComboBoxDataSourceChange extends TestBase {
  11. private ComboBox cb2;
  12. @Override
  13. protected void setup() {
  14. final IndexedContainer ds1 = new IndexedContainer();
  15. // ds1.addContainerProperty("caption", String.class, "");
  16. for (int i = 0; i < 32; i++) {
  17. ds1.addItem("ds1-" + i);
  18. }
  19. final IndexedContainer ds2 = new IndexedContainer();
  20. // ds2.addContainerProperty("caption", String.class, "");
  21. for (int i = 0; i < 32; i++) {
  22. ds2.addItem("ds2-" + i);
  23. }
  24. HorizontalLayout hl = new HorizontalLayout();
  25. hl.setWidth("100%");
  26. cb2 = new ComboBox();
  27. cb2.setImmediate(true);
  28. hl.addComponent(cb2);
  29. HorizontalLayout state = new HorizontalLayout();
  30. state.setSpacing(true);
  31. hl.addComponent(state);
  32. final Label currentValue = new Label();
  33. currentValue.setCaption("Current Value:");
  34. currentValue.setSizeUndefined();
  35. final Label currentDS = new Label();
  36. currentDS.setCaption("Current DS:");
  37. currentDS.setSizeUndefined();
  38. state.addComponent(currentValue);
  39. state.addComponent(currentDS);
  40. Table t = new Table("ds1");
  41. t.setRowHeaderMode(Table.ROW_HEADER_MODE_ID);
  42. t.setContainerDataSource(ds1);
  43. state.addComponent(t);
  44. Button b = new Button("Use ds1");
  45. b.addClickListener(event -> {
  46. cb2.setContainerDataSource(ds1);
  47. currentDS.setValue("ds1");
  48. });
  49. state.addComponent(b);
  50. t = new Table("ds2");
  51. t.setContainerDataSource(ds2);
  52. t.setRowHeaderMode(Table.ROW_HEADER_MODE_ID);
  53. state.addComponent(t);
  54. b = new Button("Use ds2");
  55. b.addClickListener(event -> {
  56. cb2.setContainerDataSource(ds2);
  57. currentDS.setValue("ds2");
  58. });
  59. state.addComponent(b);
  60. addComponent(hl);
  61. cb2.addValueChangeListener(event -> currentValue
  62. .setValue(String.valueOf(event.getProperty().getValue())));
  63. }
  64. @Override
  65. protected String getDescription() {
  66. return "A test for combobox and its container changes.";
  67. }
  68. @Override
  69. protected Integer getTicketNumber() {
  70. // TODO should be list of integers applies for #5279
  71. return 4607;
  72. }
  73. }