All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.vaadin.v7.client.connectors.AbstractSelectionModelConnector Maven / Gradle / Ivy

There is a newer version: 8.27.3
Show newest version
/*
 * Copyright (C) 2000-2024 Vaadin Ltd
 *
 * This program is available under Vaadin Commercial License and Service Terms.
 *
 * See  for the full
 * license.
 */
package com.vaadin.v7.client.connectors;

import java.util.Collection;

import com.vaadin.client.data.DataSource.RowHandle;
import com.vaadin.client.extensions.AbstractExtensionConnector;
import com.vaadin.v7.client.widget.grid.selection.SelectionModel;
import com.vaadin.v7.client.widgets.Grid;
import com.vaadin.v7.shared.ui.grid.GridState;

import elemental.json.JsonObject;

/**
 * Base class for all selection model connectors.
 *
 * @since 7.6
 * @author Vaadin Ltd
 */
public abstract class AbstractSelectionModelConnector>
        extends AbstractExtensionConnector {

    @Override
    public GridConnector getParent() {
        return (GridConnector) super.getParent();
    }

    protected Grid getGrid() {
        return getParent().getWidget();
    }

    protected RowHandle getRowHandle(JsonObject row) {
        return getGrid().getDataSource().getHandle(row);
    }

    protected String getRowKey(JsonObject row) {
        return row != null ? getParent().getRowKey(row) : null;
    }

    protected abstract T createSelectionModel();

    public abstract static class AbstractSelectionModel
            implements SelectionModel {

        @Override
        public boolean isSelected(JsonObject row) {
            return row.hasKey(GridState.JSONKEY_SELECTED);
        }

        @Override
        public void setGrid(Grid grid) {
            // NO-OP
        }

        @Override
        public void reset() {
            // Should not need any actions.
        }

        @Override
        public Collection getSelectedRows() {
            throw new UnsupportedOperationException(
                    "This client-side selection model "
                            + getClass().getSimpleName()
                            + " does not know selected rows.");
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy