選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

SingleSelectionConnector.java 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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.client.tokka.connectors.selection;
  17. import java.util.logging.Logger;
  18. import com.vaadin.client.ServerConnector;
  19. import com.vaadin.client.tokka.connectors.components.AbstractListingConnector;
  20. import com.vaadin.client.tokka.data.selection.SelectionModel;
  21. import com.vaadin.client.tokka.data.selection.SelectionModel.Single;
  22. import com.vaadin.shared.data.selection.SelectionServerRpc;
  23. import com.vaadin.shared.ui.Connect;
  24. import elemental.json.JsonObject;
  25. @Connect(com.vaadin.tokka.server.communication.data.SingleSelection.class)
  26. public class SingleSelectionConnector extends AbstractSelectionConnector {
  27. public static class SingleSelection implements SelectionModel, Single {
  28. private JsonObject value;
  29. private SelectionServerRpc rpc;
  30. public SingleSelection(SelectionServerRpc rpc) {
  31. this.rpc = rpc;
  32. }
  33. @Override
  34. public void select(JsonObject item) {
  35. if (item != null && !jsonEquals(value, item)) {
  36. rpc.select(getKey(item));
  37. value = item;
  38. }
  39. }
  40. @Override
  41. public void deselect(JsonObject item) {
  42. if (item != null && jsonEquals(value, item)) {
  43. rpc.deselect(getKey(item));
  44. value = null;
  45. }
  46. }
  47. @Override
  48. public boolean isSelected(JsonObject item) {
  49. if (hasSelectedKey(item)) {
  50. value = item;
  51. return true;
  52. }
  53. return false;
  54. }
  55. }
  56. private AbstractListingConnector parent;
  57. @Override
  58. protected void extend(ServerConnector target) {
  59. super.extend(target);
  60. parent = getParent();
  61. }
  62. @Override
  63. protected SelectionModel createSelectionModel() {
  64. return new SingleSelection(getRpcProxy(SelectionServerRpc.class));
  65. }
  66. @Override
  67. public void onUnregister() {
  68. super.onUnregister();
  69. if (parent.getSelectionModel() == getSelectionModel()) {
  70. // Remove from parent.
  71. parent.setSelectionModel(null);
  72. }
  73. }
  74. }