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.

NativeSelects.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package com.vaadin.tests.components.select;
  2. import java.util.List;
  3. import com.vaadin.tests.components.ComponentTestCase;
  4. import com.vaadin.ui.Component;
  5. import com.vaadin.v7.ui.NativeSelect;
  6. public class NativeSelects extends ComponentTestCase<NativeSelect> {
  7. NativeSelect label[] = new NativeSelect[20];
  8. @Override
  9. protected Class<NativeSelect> getTestClass() {
  10. return NativeSelect.class;
  11. }
  12. @Override
  13. protected void initializeComponents() {
  14. NativeSelect s;
  15. s = createNativeSelect(null);
  16. s.setWidth(null);
  17. addTestComponent(s);
  18. s = createNativeSelect("Undefined wide, empty select");
  19. s.setWidth(null);
  20. addTestComponent(s);
  21. s = createNativeSelect("Undefined wide select with 5 items");
  22. s.setWidth(null);
  23. addItem(s, "The first item");
  24. addItem(s, "The second item");
  25. addItem(s, "The third item");
  26. addItem(s, "The fourth item");
  27. addItem(s, "The fifth item");
  28. addTestComponent(s);
  29. s = createNativeSelect("Undefined wide select with 50 items");
  30. s.setWidth(null);
  31. populate(s, 50);
  32. addTestComponent(s);
  33. s = createNativeSelect(null);
  34. s.setWidth("100px");
  35. addTestComponent(s);
  36. s = createNativeSelect("100px wide, empty select");
  37. s.setWidth("100px");
  38. addTestComponent(s);
  39. s = createNativeSelect("150px wide select with 5 items");
  40. s.setWidth("150px");
  41. addItem(s, "The first item");
  42. addItem(s, "The second item");
  43. addItem(s, "The third item");
  44. addItem(s, "The fourth item");
  45. addItem(s, "The fifth item");
  46. addTestComponent(s);
  47. s = createNativeSelect("200px wide select with 50 items");
  48. s.setWidth("200px");
  49. populate(s, 50);
  50. addTestComponent(s);
  51. }
  52. private void populate(NativeSelect s, int nr) {
  53. String text = " an item ";
  54. String caption = "";
  55. for (int i = 0; i < nr; i++) {
  56. if (i % 2 == 0) {
  57. caption += text;
  58. } else {
  59. caption += i;
  60. }
  61. addItem(s, caption);
  62. }
  63. }
  64. private void addItem(NativeSelect s, String string) {
  65. Object id = s.addItem();
  66. s.getItem(id).getItemProperty(CAPTION).setValue(string);
  67. }
  68. private NativeSelect createNativeSelect(String caption) {
  69. NativeSelect s = new NativeSelect();
  70. s.addContainerProperty(CAPTION, String.class, "");
  71. s.setItemCaptionPropertyId(CAPTION);
  72. s.setCaption(caption);
  73. s.setNullSelectionAllowed(false);
  74. return s;
  75. }
  76. @Override
  77. protected String getTestDescription() {
  78. return "A generic test for Labels in different configurations";
  79. }
  80. @Override
  81. protected void createCustomActions(List<Component> actions) {
  82. actions.add(createBooleanAction("Null selection allowed", false,
  83. new Command<NativeSelect, Boolean>() {
  84. @Override
  85. public void execute(NativeSelect c, Boolean value,
  86. Object data) {
  87. c.setNullSelectionAllowed(value);
  88. }
  89. }));
  90. }
  91. }