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.

ListSelect.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright 2000-2018 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.v7.ui;
  17. import java.util.Collection;
  18. import com.vaadin.server.PaintException;
  19. import com.vaadin.server.PaintTarget;
  20. import com.vaadin.v7.data.Container;
  21. /**
  22. * This is a simple list select without, for instance, support for new items,
  23. * lazyloading, and other advanced features.
  24. *
  25. * @deprecated As of 8.0 replaced by {@link com.vaadin.ui.ListSelect} based on
  26. * the new data binding API
  27. */
  28. @SuppressWarnings("serial")
  29. @Deprecated
  30. public class ListSelect extends AbstractSelect {
  31. private int columns = 0;
  32. private int rows = 0;
  33. public ListSelect() {
  34. super();
  35. }
  36. public ListSelect(String caption, Collection<?> options) {
  37. super(caption, options);
  38. }
  39. public ListSelect(String caption, Container dataSource) {
  40. super(caption, dataSource);
  41. }
  42. public ListSelect(String caption) {
  43. super(caption);
  44. }
  45. /**
  46. * Sets the width of the component so that it can display approximately the
  47. * given number of letters.
  48. * <p>
  49. * Calling {@code setColumns(10);} is equivalent to calling
  50. * {@code setWidth("10em");}
  51. * </p>
  52. *
  53. * @deprecated As of 7.0. "Columns" does not reflect the exact number of
  54. * characters that will be displayed. It is better to use
  55. * setWidth together with "em" to control the width of the
  56. * field.
  57. * @param columns
  58. * the number of columns to set.
  59. */
  60. @Deprecated
  61. public void setColumns(int columns) {
  62. if (columns < 0) {
  63. columns = 0;
  64. }
  65. if (this.columns != columns) {
  66. this.columns = columns;
  67. markAsDirty();
  68. }
  69. }
  70. /**
  71. * Gets the number of columns for the component.
  72. *
  73. * @see #setColumns(int)
  74. * @deprecated As of 7.0. "Columns" does not reflect the exact number of
  75. * characters that will be displayed. It is better to use
  76. * setWidth together with "em" to control the width of the
  77. * field.
  78. */
  79. @Deprecated
  80. public int getColumns() {
  81. return columns;
  82. }
  83. public int getRows() {
  84. return rows;
  85. }
  86. /**
  87. * Sets the number of rows in the editor. If the number of rows is set 0,
  88. * the actual number of displayed rows is determined implicitly by the
  89. * adapter.
  90. *
  91. * @param rows
  92. * the number of rows to set.
  93. */
  94. public void setRows(int rows) {
  95. if (rows < 0) {
  96. rows = 0;
  97. }
  98. if (this.rows != rows) {
  99. this.rows = rows;
  100. markAsDirty();
  101. }
  102. }
  103. @Override
  104. public void paintContent(PaintTarget target) throws PaintException {
  105. target.addAttribute("type", "list");
  106. // Adds the number of columns
  107. if (columns != 0) {
  108. target.addAttribute("cols", columns);
  109. }
  110. // Adds the number of rows
  111. if (rows != 0) {
  112. target.addAttribute("rows", rows);
  113. }
  114. super.paintContent(target);
  115. }
  116. }