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.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. ---
  2. title: TwinColSelect
  3. order: 20
  4. layout: page
  5. ---
  6. [[components.twincolselect]]
  7. = 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 selection
  22. is always a collection of the selected items in the right column.
  23. The selection columns can have their own captions, separate from the overall
  24. component caption, which is managed by the containing layout. You can set the
  25. column captions with [methodname]#setLeftColumnCaption()# and
  26. [methodname]#setRightColumnCaption()#.
  27. [source, java]
  28. ----
  29. TwinColSelect<String> select =
  30. new TwinColSelect<>("Select Targets");
  31. // Put some items in the select
  32. select.setItems("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
  37. select.select("Venus", "Earth", "Mars");
  38. // Handle value changes
  39. select.addSelectionListener(event ->
  40. layout.addComponent(
  41. new Label("Selected: " + event.getNewSelection())));
  42. ----
  43. The resulting component is shown in <<figure.components.twincolselect.basic>>.
  44. The [methodname]#setRows()# method sets the height of the component by the
  45. number of visible items in the selection boxes. Setting the height with
  46. [methodname]#setHeight()# to a defined value overrides the rows setting.
  47. Common selection component features are described in
  48. <<dummy/../../../framework/components/components-selection#components.selection,"Selection
  49. Components">>.
  50. == CSS Style Rules
  51. [source, css]
  52. ----
  53. .v-select-twincol {}
  54. .v-select-twincol-options-caption {}
  55. .v-select-twincol-selections-caption {}
  56. .v-select-twincol-options {}
  57. .v-select-twincol-buttons {}
  58. .v-button {}
  59. .v-button-wrap {}
  60. .v-button-caption {}
  61. .v-select-twincol-deco {}
  62. .v-select-twincol-selections {}
  63. ----
  64. The [classname]#TwinColSelect# component has an overall
  65. [literal]#++v-select-twincol++# style. If set, the left and right column
  66. captions have [literal]#++v-select-twincol-options-caption++# and
  67. [literal]#++v-select-twincol-options-caption++# style names, respectively. The
  68. left box, which displays the unselected items, has
  69. [literal]#++v-select-twincol-options-caption++# style and the right box, which
  70. displays the selected items, has
  71. [literal]#++v-select-twincol-options-selections++# style. Between them is the
  72. button area, which has overall [literal]#++v-select-twincol-buttons++# style;
  73. the actual buttons reuse the styles for the [classname]#Button# component.
  74. Between the buttons is a divider element with
  75. [literal]#++v-select-twincol-deco++# style.