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.

AbstractGridRendererConnector.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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.client.connectors.grid;
  17. import com.vaadin.client.ServerConnector;
  18. import com.vaadin.client.connectors.AbstractRendererConnector;
  19. import com.vaadin.client.widgets.Grid.Column;
  20. import com.vaadin.shared.data.DataCommunicatorConstants;
  21. import elemental.json.JsonObject;
  22. /**
  23. * An abstract base class for renderer connectors. A renderer connector is used
  24. * to link a client-side {@link Renderer} to a server-side
  25. * {@link com.vaadin.client.renderers.Renderer Renderer}. As a connector, it can
  26. * use the regular Vaadin RPC and shared state mechanism to pass additional
  27. * state and information between the client and the server. This base class
  28. * itself only uses the basic {@link com.vaadin.shared.communication.SharedState
  29. * SharedState} and no RPC interfaces.
  30. *
  31. * @param <T>
  32. * the presentation type of the renderer
  33. *
  34. * @since 7.4
  35. * @author Vaadin Ltd
  36. */
  37. public abstract class AbstractGridRendererConnector<T>
  38. extends AbstractRendererConnector<T> {
  39. /**
  40. * Gets the row key for a row object.
  41. * <p>
  42. * In case this renderer wants be able to identify a row in such a way that
  43. * the server also understands it, the row key is used for that. Rows are
  44. * identified by unified keys between the client and the server.
  45. *
  46. * @param row
  47. * the row object
  48. * @return the row key for the given row
  49. */
  50. protected String getRowKey(JsonObject row) {
  51. return row.getString(DataCommunicatorConstants.KEY);
  52. }
  53. /**
  54. * Gets the column id for a column.
  55. * <p>
  56. * In case this renderer wants be able to identify a column in such a way
  57. * that the server also understands it, the column id is used for that.
  58. * Columns are identified by unified ids between the client and the server.
  59. *
  60. * @param column
  61. * the column object
  62. * @return the column id for the given column
  63. */
  64. protected String getColumnId(Column<?, JsonObject> column) {
  65. return getGridConnector().getColumnId(column);
  66. }
  67. /**
  68. * Gets the grid connector for this renderer connector.
  69. *
  70. * @return the parent grid connector.
  71. */
  72. protected GridConnector getGridConnector() {
  73. final ServerConnector parent = getParent();
  74. if (parent instanceof ColumnConnector) {
  75. final ServerConnector parentGrid = parent.getParent();
  76. if (parentGrid instanceof GridConnector) {
  77. return (GridConnector) parentGrid;
  78. }
  79. }
  80. throw new IllegalStateException(
  81. "Renderers can only be used with a Grid.");
  82. }
  83. }