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.

components-twincolselect.asciidoc 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. ---
  2. title: TwinColSelect
  3. order: 20
  4. layout: page
  5. ---
  6. [[components.twincolselect]]
  7. = [classname]#TwinColSelect#
  8. ifdef::web[]
  9. [.sampler]
  10. image:{live-demo-image}[alt="Live Demo", link="http://demo.vaadin.com/sampler/#ui/data-input/multiple-value/list-builder"]
  11. endif::web[]
  12. The [classname]#TwinColSelect# field provides a multiple selection component
  13. that shows two lists side by side, with the left column containing unselected
  14. items and the right column the selected items. The user can select items from
  15. the list on the left and click on the ">>" button to move them to the list on
  16. the right. Items can be deselected by selecting them in the right list and
  17. clicking on the "<<" button.
  18. [[figure.components.twincolselect.basic]]
  19. .Twin Column Selection
  20. image::img/twincolselect-basic.png[width=50%, scaledwidth=80%]
  21. [classname]#TwinColSelect# is always in multi-select mode, so its property value
  22. is always a collection of the item IDs of the selected items, that is, the items
  23. in the right column.
  24. The selection columns can have their own captions, separate from the overall
  25. component caption, which is managed by the containing layout. You can set the
  26. column captions with [methodname]#setLeftColumnCaption()# and
  27. [methodname]#setRightColumnCaption()#.
  28. [source, java]
  29. ----
  30. TwinColSelect select = new TwinColSelect("Select Targets");
  31. // Put some items in the select
  32. select.addItems("Mercury", "Venus", "Earth", "Mars",
  33. "Jupiter", "Saturn", "Uranus", "Neptune");
  34. // Few items, so we can set rows to match item count
  35. select.setRows(select.size());
  36. // Preselect a few items by creating a set
  37. select.setValue(new HashSet<String>(
  38. Arrays.asList("Venus", "Earth", "Mars")));
  39. // Handle value changes
  40. select.addValueChangeListener(event -> // Java 8
  41. layout.addComponent(new Label("Selected: " +
  42. event.getProperty().getValue())));
  43. ----
  44. See the http://demo.vaadin.com/book-examples-vaadin7/book#component.select.twincolselect.captions[on-line example, window="_blank"].
  45. The resulting component is shown in <<figure.components.twincolselect.basic>>.
  46. The [methodname]#setRows()# method sets the height of the component by the
  47. number of visible items in the selection boxes. Setting the height with
  48. [methodname]#setHeight()# to a defined value overrides the rows setting.
  49. Common selection component features are described in
  50. <<dummy/../../../framework/components/components-selection#components.selection,"Selection
  51. Components">>.
  52. == CSS Style Rules
  53. [source, css]
  54. ----
  55. .v-select-twincol {}
  56. .v-select-twincol-options-caption {}
  57. .v-select-twincol-selections-caption {}
  58. .v-select-twincol-options {}
  59. .v-select-twincol-buttons {}
  60. .v-button {}
  61. .v-button-wrap {}
  62. .v-button-caption {}
  63. .v-select-twincol-deco {}
  64. .v-select-twincol-selections {}
  65. ----
  66. The [classname]#TwinColSelect# component has an overall
  67. [literal]#++v-select-twincol++# style. If set, the left and right column
  68. captions have [literal]#++v-select-twincol-options-caption++# and
  69. [literal]#++v-select-twincol-options-caption++# style names, respectively. The
  70. left box, which displays the unselected items, has
  71. [literal]#++v-select-twincol-options-caption++# style and the right box, which
  72. displays the selected items, has
  73. [literal]#++v-select-twincol-options-selections++# style. Between them is the
  74. button area, which has overall [literal]#++v-select-twincol-buttons++# style;
  75. the actual buttons reuse the styles for the [classname]#Button# component.
  76. Between the buttons is a divider element with
  77. [literal]#++v-select-twincol-deco++# style.