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.

ComboBoxes2.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package com.vaadin.tests.components.combobox;
  2. import java.util.LinkedHashMap;
  3. import com.vaadin.server.Resource;
  4. import com.vaadin.tests.components.select.AbstractSelectTestCase;
  5. import com.vaadin.v7.shared.ui.combobox.FilteringMode;
  6. import com.vaadin.v7.ui.ComboBox;
  7. import com.vaadin.v7.ui.ComboBox.ItemStyleGenerator;
  8. public class ComboBoxes2<T extends ComboBox> extends AbstractSelectTestCase<T> {
  9. private Command<T, String> inputPromptCommand = new Command<T, String>() {
  10. @Override
  11. public void execute(T c, String value, Object data) {
  12. c.setInputPrompt(value);
  13. }
  14. };
  15. private Command<T, FilteringMode> filteringModeCommand = new Command<T, FilteringMode>() {
  16. @Override
  17. public void execute(T c, FilteringMode value, Object data) {
  18. c.setFilteringMode(value);
  19. }
  20. };
  21. private Command<T, ItemStyleGenerator> itemStyleGeneratorCommand = new Command<T, ItemStyleGenerator>() {
  22. @Override
  23. public void execute(T c, ItemStyleGenerator value, Object data) {
  24. c.setItemStyleGenerator(value);
  25. }
  26. };
  27. @Override
  28. protected Class<T> getTestClass() {
  29. return (Class<T>) ComboBox.class;
  30. }
  31. @Override
  32. protected void createActions() {
  33. super.createActions();
  34. createItemIconSelect(CATEGORY_DATA_SOURCE);
  35. createInputPromptAction(CATEGORY_FEATURES);
  36. createFilteringModeAction(CATEGORY_FEATURES);
  37. createItemStyleGeneratorAction(CATEGORY_FEATURES);
  38. createNewItemsAllowedAction(CATEGORY_STATE);
  39. createTextInputAlowedAction(CATEGORY_STATE);
  40. }
  41. private void createTextInputAlowedAction(String category) {
  42. createBooleanAction("Text input allowed", category, true,
  43. new Command<T, Boolean>() {
  44. @Override
  45. public void execute(T c, Boolean value, Object data) {
  46. c.setTextInputAllowed(value.booleanValue());
  47. }
  48. });
  49. }
  50. private void createNewItemsAllowedAction(String category) {
  51. createBooleanAction("New items allowed", category, false,
  52. new Command<T, Boolean>() {
  53. @Override
  54. public void execute(T c, Boolean value, Object data) {
  55. c.setNewItemsAllowed(value.booleanValue());
  56. }
  57. });
  58. }
  59. private void createFilteringModeAction(String category) {
  60. LinkedHashMap<String, FilteringMode> options = new LinkedHashMap<>();
  61. options.put("Off", FilteringMode.OFF);
  62. options.put("Contains", FilteringMode.CONTAINS);
  63. options.put("Starts with", FilteringMode.STARTSWITH);
  64. createSelectAction("Filtering mode", category, options, "Contains",
  65. filteringModeCommand);
  66. }
  67. private void createItemStyleGeneratorAction(String category) {
  68. LinkedHashMap<String, ItemStyleGenerator> options = new LinkedHashMap<>();
  69. options.put("-", null);
  70. options.put("Bold fives", (source, itemId) -> {
  71. if (String.valueOf(itemId).indexOf('5') != -1) {
  72. return "bold";
  73. }
  74. return null;
  75. });
  76. createSelectAction("Item style generator", category, options, "-",
  77. itemStyleGeneratorCommand);
  78. }
  79. private void createInputPromptAction(String category) {
  80. LinkedHashMap<String, String> options = new LinkedHashMap<>();
  81. options.put("-", null);
  82. options.put("Enter a value", "Enter a value");
  83. options.put("- Click here -", "- Click here -");
  84. createSelectAction("Input prompt", category, options, "-",
  85. inputPromptCommand);
  86. }
  87. private void createItemIconSelect(String category) {
  88. createSelectAction("Icon", category, createIconOptions(false), "-",
  89. new Command<T, Resource>() {
  90. @Override
  91. public void execute(T c, Resource value, Object data) {
  92. for (Object id : c.getItemIds()) {
  93. if (value == null) {
  94. c.setItemIcon(id, null);
  95. } else {
  96. c.setItemIcon(id, value);
  97. }
  98. }
  99. }
  100. });
  101. }
  102. }