Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

SingleSelection.java 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright 2000-2014 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.server.communication.data.typed;
  17. import java.util.Collection;
  18. import java.util.Collections;
  19. import com.vaadin.event.handler.Handler;
  20. import com.vaadin.event.handler.Registration;
  21. import com.vaadin.server.communication.data.typed.SelectionModel.Single;
  22. import com.vaadin.shared.data.selection.SelectionServerRpc;
  23. /**
  24. * {@link SelectionModel} for selecting a single value.
  25. *
  26. * @param <T>
  27. * type of selected data
  28. */
  29. public class SingleSelection<T> extends AbstractSelectionModel<T> implements
  30. Single<T> {
  31. public SingleSelection() {
  32. registerRpc(new SelectionServerRpc() {
  33. @Override
  34. public void select(String key) {
  35. setValue(getData(key));
  36. }
  37. @Override
  38. public void deselect(String key) {
  39. if (getData(key).equals(value)) {
  40. setValue(null);
  41. }
  42. }
  43. });
  44. }
  45. private T value = null;
  46. @Override
  47. public Collection<T> getSelected() {
  48. if (value != null) {
  49. return Collections.singleton(value);
  50. } else {
  51. return Collections.emptySet();
  52. }
  53. }
  54. @Override
  55. public void setValue(T value) {
  56. if (this.value != value) {
  57. this.value = value;
  58. // TODO: fire event
  59. }
  60. }
  61. @Override
  62. public T getValue() {
  63. return value;
  64. }
  65. @Override
  66. public Registration onChange(Handler<T> handler) {
  67. return () -> {
  68. // TODO: Event registration
  69. };
  70. }
  71. }