2 * Copyright 2000-2018 Vaadin Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
16 package com.vaadin.v7.client.connectors;
18 import java.util.Collection;
20 import com.vaadin.client.data.DataSource.RowHandle;
21 import com.vaadin.client.extensions.AbstractExtensionConnector;
22 import com.vaadin.v7.client.widget.grid.selection.SelectionModel;
23 import com.vaadin.v7.client.widgets.Grid;
24 import com.vaadin.v7.shared.ui.grid.GridState;
26 import elemental.json.JsonObject;
29 * Base class for all selection model connectors.
34 public abstract class AbstractSelectionModelConnector<T extends SelectionModel<JsonObject>>
35 extends AbstractExtensionConnector {
38 public GridConnector getParent() {
39 return (GridConnector) super.getParent();
42 protected Grid<JsonObject> getGrid() {
43 return getParent().getWidget();
46 protected RowHandle<JsonObject> getRowHandle(JsonObject row) {
47 return getGrid().getDataSource().getHandle(row);
50 protected String getRowKey(JsonObject row) {
51 return row != null ? getParent().getRowKey(row) : null;
54 protected abstract T createSelectionModel();
56 public abstract static class AbstractSelectionModel
57 implements SelectionModel<JsonObject> {
60 public boolean isSelected(JsonObject row) {
61 return row.hasKey(GridState.JSONKEY_SELECTED);
65 public void setGrid(Grid<JsonObject> grid) {
71 // Should not need any actions.
75 public Collection<JsonObject> getSelectedRows() {
76 throw new UnsupportedOperationException(
77 "This client-side selection model "
78 + getClass().getSimpleName()
79 + " does not know selected rows.");