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.

CheckBoxGroup.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.ui;
  17. import java.util.Collection;
  18. import com.vaadin.data.Listing;
  19. import com.vaadin.server.SerializablePredicate;
  20. import com.vaadin.server.data.DataSource;
  21. import com.vaadin.shared.ui.optiongroup.CheckBoxGroupState;
  22. /**
  23. * A group of Checkboxes. Individual checkboxes are made from items supplied by
  24. * a {@link DataSource}. Checkboxes may have captions and icons.
  25. *
  26. * @param <T>
  27. * item type
  28. * @author Vaadin Ltd
  29. * @since 8.0
  30. */
  31. public class CheckBoxGroup<T> extends AbstractMultiSelect<T> {
  32. /**
  33. * Constructs a new CheckBoxGroup with caption.
  34. *
  35. * @param caption
  36. * caption text
  37. * @see Listing#setDataSource(DataSource)
  38. */
  39. public CheckBoxGroup(String caption) {
  40. this();
  41. setCaption(caption);
  42. }
  43. /**
  44. * Constructs a new CheckBoxGroup with caption and DataSource.
  45. *
  46. * @param caption
  47. * the caption text
  48. * @param dataSource
  49. * the data source, not null
  50. * @see Listing#setDataSource(DataSource)
  51. */
  52. public CheckBoxGroup(String caption, DataSource<T> dataSource) {
  53. this(caption);
  54. setDataSource(dataSource);
  55. }
  56. /**
  57. * Constructs a new CheckBoxGroup with caption and DataSource containing
  58. * given items.
  59. *
  60. * @param caption
  61. * the caption text
  62. * @param items
  63. * the data items to use, not null
  64. * @see Listing#setDataSource(DataSource)
  65. */
  66. public CheckBoxGroup(String caption, Collection<T> items) {
  67. this(caption, DataSource.create(items));
  68. }
  69. /**
  70. * Constructs a new CheckBoxGroup.
  71. *
  72. * @see Listing#setDataSource(DataSource)
  73. */
  74. public CheckBoxGroup() {
  75. }
  76. /**
  77. * Sets whether html is allowed in the item captions. If set to true, the
  78. * captions are passed to the browser as html and the developer is
  79. * responsible for ensuring no harmful html is used. If set to false, the
  80. * content is passed to the browser as plain text.
  81. *
  82. * @param htmlContentAllowed
  83. * true if the captions are used as html, false if used as plain
  84. * text
  85. */
  86. public void setHtmlContentAllowed(boolean htmlContentAllowed) {
  87. getState().htmlContentAllowed = htmlContentAllowed;
  88. }
  89. /**
  90. * Checks whether captions are interpreted as html or plain text.
  91. *
  92. * @return true if the captions are used as html, false if used as plain
  93. * text
  94. * @see #setHtmlContentAllowed(boolean)
  95. */
  96. public boolean isHtmlContentAllowed() {
  97. return getState(false).htmlContentAllowed;
  98. }
  99. @Override
  100. protected CheckBoxGroupState getState() {
  101. return (CheckBoxGroupState) super.getState();
  102. }
  103. @Override
  104. protected CheckBoxGroupState getState(boolean markAsDirty) {
  105. return (CheckBoxGroupState) super.getState(markAsDirty);
  106. }
  107. @Override
  108. public IconGenerator<T> getItemIconGenerator() {
  109. return super.getItemIconGenerator();
  110. }
  111. @Override
  112. public void setItemIconGenerator(IconGenerator<T> itemIconGenerator) {
  113. super.setItemIconGenerator(itemIconGenerator);
  114. }
  115. @Override
  116. public SerializablePredicate<T> getItemEnabledProvider() {
  117. return super.getItemEnabledProvider();
  118. }
  119. @Override
  120. public void setItemEnabledProvider(
  121. SerializablePredicate<T> itemEnabledProvider) {
  122. super.setItemEnabledProvider(itemEnabledProvider);
  123. }
  124. }