use of com.vaadin.flow.data.selection.SingleSelect in project flow-components by vaadin.
the class AbstractGridSingleSelectionModel method asSingleSelect.
@Override
public SingleSelect<Grid<T>, T> asSingleSelect() {
return new SingleSelect<Grid<T>, T>() {
@Override
public void setValue(T value) {
setSelectedItem(value);
}
@Override
public T getValue() {
return getSelectedItem().orElse(getEmptyValue());
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Registration addValueChangeListener(ValueChangeListener<? super ComponentValueChangeEvent<Grid<T>, T>> listener) {
Objects.requireNonNull(listener, "listener cannot be null");
ComponentEventListener componentEventListener = event -> listener.valueChanged((ComponentValueChangeEvent<Grid<T>, T>) event);
return ComponentUtil.addListener(getGrid(), SingleSelectionEvent.class, componentEventListener);
}
@Override
public Element getElement() {
return getGrid().getElement();
}
};
}
Aggregations