Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

NativeSelect.java 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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.v7.ui;
  17. import java.util.Collection;
  18. import com.vaadin.event.FieldEvents.BlurEvent;
  19. import com.vaadin.event.FieldEvents.BlurListener;
  20. import com.vaadin.event.FieldEvents.FocusAndBlurServerRpcDecorator;
  21. import com.vaadin.event.FieldEvents.FocusEvent;
  22. import com.vaadin.event.FieldEvents.FocusListener;
  23. import com.vaadin.server.PaintException;
  24. import com.vaadin.server.PaintTarget;
  25. import com.vaadin.v7.data.Container;
  26. import com.vaadin.v7.event.FieldEvents;
  27. /**
  28. * This is a simple drop-down select without, for instance, support for
  29. * multiselect, new items, lazyloading, and other advanced features. Sometimes
  30. * "native" select without all the bells-and-whistles of the ComboBox is a
  31. * better choice.
  32. *
  33. * @deprecated As of 8.0 replaced by {@link com.vaadin.ui.NativeSelect} based on
  34. * the new data binding API
  35. */
  36. @SuppressWarnings("serial")
  37. @Deprecated
  38. public class NativeSelect extends AbstractSelect
  39. implements FieldEvents.BlurNotifier, FieldEvents.FocusNotifier {
  40. // width in characters, mimics TextField
  41. private int columns = 0;
  42. public NativeSelect() {
  43. super();
  44. registerRpc(new FocusAndBlurServerRpcDecorator(this, this::fireEvent));
  45. }
  46. public NativeSelect(String caption, Collection<?> options) {
  47. super(caption, options);
  48. registerRpc(new FocusAndBlurServerRpcDecorator(this, this::fireEvent));
  49. }
  50. public NativeSelect(String caption, Container dataSource) {
  51. super(caption, dataSource);
  52. registerRpc(new FocusAndBlurServerRpcDecorator(this, this::fireEvent));
  53. }
  54. public NativeSelect(String caption) {
  55. super(caption);
  56. registerRpc(new FocusAndBlurServerRpcDecorator(this, this::fireEvent));
  57. }
  58. /**
  59. * Sets the width of the component so that it can display approximately the
  60. * given number of letters.
  61. * <p>
  62. * Calling {@code setColumns(10);} is equivalent to calling
  63. * {@code setWidth("10em");}
  64. * </p>
  65. *
  66. * @deprecated As of 7.0. "Columns" does not reflect the exact number of
  67. * characters that will be displayed. It is better to use
  68. * setWidth together with "em" to control the width of the
  69. * field.
  70. * @param columns
  71. * the number of columns to set.
  72. */
  73. @Deprecated
  74. public void setColumns(int columns) {
  75. if (columns < 0) {
  76. columns = 0;
  77. }
  78. if (this.columns != columns) {
  79. this.columns = columns;
  80. markAsDirty();
  81. }
  82. }
  83. /**
  84. * Gets the number of columns for the component.
  85. *
  86. * @see #setColumns(int)
  87. * @deprecated As of 7.0. "Columns" does not reflect the exact number of
  88. * characters that will be displayed. It is better to use
  89. * setWidth together with "em" to control the width of the
  90. * field.
  91. */
  92. @Deprecated
  93. public int getColumns() {
  94. return columns;
  95. }
  96. @Override
  97. public void paintContent(PaintTarget target) throws PaintException {
  98. target.addAttribute("type", "native");
  99. // Adds the number of columns
  100. if (columns != 0) {
  101. target.addAttribute("cols", columns);
  102. }
  103. super.paintContent(target);
  104. }
  105. @Override
  106. public void setMultiSelect(boolean multiSelect)
  107. throws UnsupportedOperationException {
  108. if (multiSelect) {
  109. throw new UnsupportedOperationException(
  110. "Multiselect not supported");
  111. }
  112. }
  113. @Override
  114. public void setNewItemsAllowed(boolean allowNewOptions)
  115. throws UnsupportedOperationException {
  116. if (allowNewOptions) {
  117. throw new UnsupportedOperationException(
  118. "newItemsAllowed not supported");
  119. }
  120. }
  121. @Override
  122. public void addFocusListener(FocusListener listener) {
  123. addListener(FocusEvent.EVENT_ID, FocusEvent.class, listener,
  124. FocusListener.focusMethod);
  125. }
  126. @Override
  127. public void removeFocusListener(FocusListener listener) {
  128. removeListener(FocusEvent.EVENT_ID, FocusEvent.class, listener);
  129. }
  130. @Override
  131. public void addBlurListener(BlurListener listener) {
  132. addListener(BlurEvent.EVENT_ID, BlurEvent.class, listener,
  133. BlurListener.blurMethod);
  134. }
  135. @Override
  136. public void removeBlurListener(BlurListener listener) {
  137. removeListener(BlurEvent.EVENT_ID, BlurEvent.class, listener);
  138. }
  139. }