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.

ComboBoxExample.java 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.automatedtests.featurebrowser;
  5. import java.util.Random;
  6. import com.vaadin.ui.ComboBox;
  7. import com.vaadin.ui.CustomComponent;
  8. import com.vaadin.ui.OrderedLayout;
  9. import com.vaadin.ui.AbstractSelect.Filtering;
  10. /**
  11. *
  12. */
  13. @SuppressWarnings("serial")
  14. public class ComboBoxExample extends CustomComponent {
  15. private static final String[] firstnames = new String[] { "John", "Mary",
  16. "Joe", "Sarah", "Jeff", "Jane", "Peter", "Marc", "Robert", "Paula",
  17. "Lenny", "Kenny", "Nathan", "Nicole", "Laura", "Jos", "Josie",
  18. "Linus" };
  19. private static final String[] lastnames = new String[] { "Torvalds",
  20. "Smith", "Adams", "Black", "Wilson", "Richards", "Thompson",
  21. "McGoff", "Halas", "Jones", "Beck", "Sheridan", "Picard", "Hill",
  22. "Fielding", "Einstein" };
  23. public ComboBoxExample() {
  24. final OrderedLayout main = new OrderedLayout();
  25. main.setMargin(true);
  26. setCompositionRoot(main);
  27. // starts-with filter
  28. final ComboBox s1 = new ComboBox("Select with starts-with filter");
  29. s1.setDebugId("ComboBoxStartFilter");
  30. s1.setFilteringMode(Filtering.FILTERINGMODE_STARTSWITH);
  31. s1.setColumns(20);
  32. Random r = new Random(5);
  33. for (int i = 0; i < 105; i++) {
  34. s1
  35. .addItem(firstnames[(int) (r.nextDouble() * (firstnames.length - 1))]
  36. + " "
  37. + lastnames[(int) (r.nextDouble() * (lastnames.length - 1))]);
  38. }
  39. s1.setImmediate(true);
  40. main.addComponent(s1);
  41. // contains filter
  42. final ComboBox s2 = new ComboBox("Select with contains filter");
  43. s2.setDebugId("ComboBoxContainsFilter");
  44. s2.setFilteringMode(Filtering.FILTERINGMODE_CONTAINS);
  45. s2.setColumns(20);
  46. for (int i = 0; i < 500; i++) {
  47. s2
  48. .addItem(firstnames[(int) (r.nextDouble() * (firstnames.length - 1))]
  49. + " "
  50. + lastnames[(int) (r.nextDouble() * (lastnames.length - 1))]);
  51. }
  52. s2.setImmediate(true);
  53. main.addComponent(s2);
  54. // initially empty
  55. final ComboBox s3 = new ComboBox("Initially empty; enter your own");
  56. s3.setDebugId("EmptyComboBox");
  57. s3.setColumns(20);
  58. s3.setImmediate(true);
  59. s3.setNewItemsAllowed(true);
  60. main.addComponent(s3);
  61. }
  62. }