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.

AbstractSelectionModelConnector.java 2.4KB

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.client.connectors;
  17. import java.util.Collection;
  18. import com.vaadin.client.data.DataSource.RowHandle;
  19. import com.vaadin.client.extensions.AbstractExtensionConnector;
  20. import com.vaadin.client.widget.grid.selection.SelectionModel;
  21. import com.vaadin.client.widgets.Grid;
  22. import com.vaadin.shared.ui.grid.GridState;
  23. import elemental.json.JsonObject;
  24. /**
  25. * Base class for all selection model connectors.
  26. *
  27. * @since 7.6
  28. * @author Vaadin Ltd
  29. */
  30. public abstract class AbstractSelectionModelConnector<T extends SelectionModel<JsonObject>>
  31. extends AbstractExtensionConnector {
  32. @Override
  33. public GridConnector getParent() {
  34. return (GridConnector) super.getParent();
  35. }
  36. protected Grid<JsonObject> getGrid() {
  37. return getParent().getWidget();
  38. }
  39. protected RowHandle<JsonObject> getRowHandle(JsonObject row) {
  40. return getGrid().getDataSource().getHandle(row);
  41. }
  42. protected String getRowKey(JsonObject row) {
  43. return row != null ? getParent().getRowKey(row) : null;
  44. }
  45. protected abstract T createSelectionModel();
  46. public abstract static class AbstractSelectionModel implements
  47. SelectionModel<JsonObject> {
  48. @Override
  49. public boolean isSelected(JsonObject row) {
  50. return row.hasKey(GridState.JSONKEY_SELECTED);
  51. }
  52. @Override
  53. public void setGrid(Grid<JsonObject> grid) {
  54. // NO-OP
  55. }
  56. @Override
  57. public void reset() {
  58. // Should not need any actions.
  59. }
  60. @Override
  61. public Collection<JsonObject> getSelectedRows() {
  62. throw new UnsupportedOperationException(
  63. "This client-side selection model "
  64. + getClass().getSimpleName()
  65. + " does not know selected rows.");
  66. }
  67. }
  68. }