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

com.vaadin.client.widget.grid.selection.SelectionModel Maven / Gradle / Ivy

Go to download

Vaadin is a web application framework for Rich Internet Applications (RIA). Vaadin enables easy development and maintenance of fast and secure rich web applications with a stunning look and feel and a wide browser support. It features a server-side architecture with the majority of the logic running on the server. Ajax technology is used at the browser-side to ensure a rich and interactive user experience.

There is a newer version: 8.27.1
Show newest version
/*
 * Copyright 2000-2016 Vaadin Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.vaadin.client.widget.grid.selection;

import com.vaadin.shared.data.DataCommunicatorConstants;

import elemental.json.JsonObject;

/**
 * Models the selection logic of a {@code Grid} component. Determines how items
 * can be selected and deselected.
 *
 * @author Vaadin Ltd.
 *
 * @param 
 *            the type of the items to select
 * @since 8.0
 */
public interface SelectionModel {

    public static class NoSelectionModel implements SelectionModel {

        @Override
        public void select(T item) {
        }

        @Override
        public void deselect(T item) {
        }

        @Override
        public boolean isSelected(T item) {
            return false;
        }

        @Override
        public void deselectAll() {
        }

        @Override
        public void setSelectionAllowed(boolean selectionAllowed) {
        }

        @Override
        public boolean isSelectionAllowed() {
            return false;
        }
    }

    /**
     * Selects the given item. If another item was already selected, that item
     * is deselected.
     *
     * @param item
     *            the item to select, not null
     */
    void select(T item);

    /**
     * Deselects the given item. If the item is not currently selected, does
     * nothing.
     *
     * @param item
     *            the item to deselect, not null
     */
    void deselect(T item);

    /**
     * Returns whether the given item is currently selected.
     *
     * @param item
     *            the item to check, not null
     * @return {@code true} if the item is selected, {@code false} otherwise
     */
    boolean isSelected(T item);

    /**
     * Deselects all currently selected items.
     */
    void deselectAll();

    /**
     * Sets whether the user is allowed to change the selection.
     * 

* The check is done only for the client side actions. It doesn't affect * selection requests sent from the server side. * * @param selectionAllowed * true if the user is allowed to change the * selection, false otherwise */ void setSelectionAllowed(boolean selectionAllowed); /** * Checks if the user is allowed to change the selection. *

* The check is done only for the client side actions. It doesn't affect * selection requests sent from the server side. * * @return true if the user is allowed to change the selection, * false otherwise */ boolean isSelectionAllowed(); /** * Gets the selected state from a given grid row json object. This is a * helper method for grid selection models. * * @param item * a json object * @return {@code true} if the json object is marked as selected; * {@code false} if not */ public static boolean isItemSelected(JsonObject item) { return item.hasKey(DataCommunicatorConstants.SELECTED) && item.getBoolean(DataCommunicatorConstants.SELECTED); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy