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.

FilterSelect.java 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.itmill.toolkit.demo;
  5. import com.itmill.toolkit.ui.OrderedLayout;
  6. import com.itmill.toolkit.ui.Panel;
  7. import com.itmill.toolkit.ui.Select;
  8. import com.itmill.toolkit.ui.Window;
  9. import com.itmill.toolkit.ui.AbstractSelect.Filtering;
  10. /**
  11. * The classic "hello, world!" example for IT Mill Toolkit. The class simply
  12. * implements the abstract {@link com.itmill.toolkit.Application#init() init()}
  13. * method in which it creates a Window and adds a Label to it.
  14. *
  15. * @author IT Mill Ltd.
  16. * @see com.itmill.toolkit.Application
  17. * @see com.itmill.toolkit.ui.Window
  18. * @see com.itmill.toolkit.ui.Label
  19. */
  20. public class FilterSelect extends com.itmill.toolkit.Application {
  21. private static final String[] firstnames = new String[] { "John", "Mary",
  22. "Joe", "Sarah", "Jeff", "Jane", "Peter", "Marc", "Robert", "Paula",
  23. "Lenny", "Kenny", "Nathan", "Nicole", "Laura", "Jos", "Josie",
  24. "Linus" };
  25. private static final String[] lastnames = new String[] { "Torvalds",
  26. "Smith", "Adams", "Black", "Wilson", "Richards", "Thompson",
  27. "McGoff", "Halas", "Jones", "Beck", "Sheridan", "Picard", "Hill",
  28. "Fielding", "Einstein" };
  29. /**
  30. * The initialization method that is the only requirement for inheriting the
  31. * com.itmill.toolkit.service.Application class. It will be automatically
  32. * called by the framework when a user accesses the application.
  33. */
  34. public void init() {
  35. /*
  36. * - Create new window for the application - Give the window a visible
  37. * title - Set the window to be the main window of the application
  38. */
  39. final Window main = new Window("Filter select demo");
  40. setMainWindow(main);
  41. // default filterin (Starts with)
  42. final Select s1 = new Select();
  43. for (int i = 0; i < 105; i++) {
  44. s1
  45. .addItem(firstnames[(int) (Math.random() * (firstnames.length - 1))]
  46. + " "
  47. + lastnames[(int) (Math.random() * (lastnames.length - 1))]);
  48. }
  49. s1.setImmediate(true);
  50. // contains filter
  51. final Select s2 = new Select();
  52. for (int i = 0; i < 500; i++) {
  53. s2
  54. .addItem(firstnames[(int) (Math.random() * (firstnames.length - 1))]
  55. + " "
  56. + lastnames[(int) (Math.random() * (lastnames.length - 1))]);
  57. }
  58. s2.setFilteringMode(Filtering.FILTERINGMODE_CONTAINS);
  59. // Add selects to UI using ordered layout and panels
  60. final OrderedLayout orderedLayout = new OrderedLayout(
  61. OrderedLayout.ORIENTATION_HORIZONTAL);
  62. final Panel panel1 = new Panel("Select with default filter");
  63. final Panel panel2 = new Panel("Select with contains filter");
  64. panel1.addComponent(s1);
  65. panel2.addComponent(s2);
  66. orderedLayout.addComponent(panel1);
  67. orderedLayout.addComponent(panel2);
  68. main.addComponent(orderedLayout);
  69. }
  70. }