com.vaadin.client.widget.grid.selection.SelectionEvent Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vaadin-client Show documentation
Show all versions of vaadin-client Show documentation
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.
/*
* 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 java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import com.google.gwt.event.shared.GwtEvent;
import com.vaadin.client.widgets.Grid;
/**
* Event object describing a change in Grid row selection state.
*
* @since 7.4
* @author Vaadin Ltd
*/
@SuppressWarnings("rawtypes")
public class SelectionEvent extends GwtEvent {
private static final Type eventType = new Type<>();
private final Grid grid;
private final List added;
private final List removed;
private final boolean batched;
/**
* Creates an event with a single added or removed row.
*
* @param grid
* grid reference, used for getSource
* @param added
* the added row, or null
if a row was not added
* @param removed
* the removed row, or null
if a row was not removed
* @param batched
* whether or not this selection change event is triggered during
* a batched selection/deselection action
* @see SelectionModel.Multi.Batched
*/
public SelectionEvent(Grid grid, T added, T removed, boolean batched) {
this.grid = grid;
this.batched = batched;
if (added != null) {
this.added = Collections.singletonList(added);
} else {
this.added = Collections.emptyList();
}
if (removed != null) {
this.removed = Collections.singletonList(removed);
} else {
this.removed = Collections.emptyList();
}
}
/**
* Creates an event where several rows have been added or removed.
*
* @param grid
* Grid reference, used for getSource
* @param added
* a collection of added rows, or null
if no rows
* were added
* @param removed
* a collection of removed rows, or null
if no rows
* were removed
* @param batched
* whether or not this selection change event is triggered during
* a batched selection/deselection action
* @see SelectionModel.Multi.Batched
*/
public SelectionEvent(Grid grid, Collection added,
Collection removed, boolean batched) {
this.grid = grid;
this.batched = batched;
if (added != null) {
this.added = new ArrayList<>(added);
} else {
this.added = Collections.emptyList();
}
if (removed != null) {
this.removed = new ArrayList<>(removed);
} else {
this.removed = Collections.emptyList();
}
}
/**
* Gets a reference to the Grid object that fired this event.
*
* @return a grid reference
*/
@Override
public Grid getSource() {
return grid;
}
/**
* Gets all rows added to the selection since the last
* {@link SelectionEvent} .
*
* @return a collection of added rows. Empty collection if no rows were
* added.
*/
public Collection getAdded() {
return Collections.unmodifiableCollection(added);
}
/**
* Gets all rows removed from the selection since the last
* {@link SelectionEvent}.
*
* @return a collection of removed rows. Empty collection if no rows were
* removed.
*/
public Collection getRemoved() {
return Collections.unmodifiableCollection(removed);
}
/**
* Gets a type identifier for this event.
*
* @return a {@link Type} identifier.
*/
public static Type getType() {
return eventType;
}
@Override
public Type getAssociatedType() {
return eventType;
}
@Override
@SuppressWarnings("unchecked")
protected void dispatch(SelectionHandler handler) {
handler.onSelect(this);
}
/**
* Checks if this selection change event is fired during a batched
* selection/deselection operation.
*
* @return true
iff this event is fired during a batched
* selection/deselection operation
*/
public boolean isBatchedSelection() {
return batched;
}
}