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.

AbstractListingConnector.java 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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.client.connectors;
  17. import com.vaadin.client.connectors.data.HasDataSource;
  18. import com.vaadin.client.data.DataSource;
  19. import com.vaadin.client.ui.AbstractFieldConnector;
  20. import com.vaadin.shared.data.DataCommunicatorConstants;
  21. import com.vaadin.shared.ui.abstractlisting.AbstractListingState;
  22. import com.vaadin.ui.AbstractListing;
  23. import elemental.json.JsonObject;
  24. import elemental.json.JsonValue;
  25. /**
  26. * A base connector class for {@link AbstractListing}.
  27. *
  28. * @author Vaadin Ltd.
  29. *
  30. * @since 8.0
  31. */
  32. public abstract class AbstractListingConnector extends AbstractFieldConnector
  33. implements HasDataSource {
  34. private DataSource<JsonObject> dataSource = null;
  35. @Override
  36. public void setDataSource(DataSource<JsonObject> dataSource) {
  37. this.dataSource = dataSource;
  38. }
  39. @Override
  40. public DataSource<JsonObject> getDataSource() {
  41. return dataSource;
  42. }
  43. /**
  44. * Returns the key of the given data row.
  45. *
  46. * @param row
  47. * the row
  48. * @return the row key
  49. */
  50. protected static String getRowKey(JsonObject row) {
  51. return row.getString(DataCommunicatorConstants.KEY);
  52. }
  53. /**
  54. * Returns the data of the given data row.
  55. *
  56. * @param row
  57. * the row
  58. * @return the row data
  59. */
  60. protected static JsonValue getRowData(JsonObject row) {
  61. return row.get(DataCommunicatorConstants.DATA);
  62. }
  63. /**
  64. * Returns whether the given row is selected.
  65. *
  66. * @param row
  67. * the row
  68. * @return {@code true} if the row is selected, {@code false} otherwise
  69. */
  70. protected boolean isRowSelected(JsonObject row) {
  71. return row.hasKey(DataCommunicatorConstants.SELECTED);
  72. }
  73. @Override
  74. public AbstractListingState getState() {
  75. return (AbstractListingState) super.getState();
  76. }
  77. }