Search in sources :

Example 1 with SingleSelect

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();
        }
    };
}
Also used : ComponentEventListener(com.vaadin.flow.component.ComponentEventListener) AbstractGridExtension(com.vaadin.flow.component.grid.Grid.AbstractGridExtension) ComponentUtil(com.vaadin.flow.component.ComponentUtil) Registration(com.vaadin.flow.shared.Registration) SingleSelect(com.vaadin.flow.data.selection.SingleSelect) SingleSelectionEvent(com.vaadin.flow.data.selection.SingleSelectionEvent) SelectionListener(com.vaadin.flow.data.selection.SelectionListener) Objects(java.util.Objects) Element(com.vaadin.flow.dom.Element) ComponentValueChangeEvent(com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent) Optional(java.util.Optional) SelectionEvent(com.vaadin.flow.data.selection.SelectionEvent) JsonObject(elemental.json.JsonObject) Collections(java.util.Collections) SingleSelectionListener(com.vaadin.flow.data.selection.SingleSelectionListener) SingleSelect(com.vaadin.flow.data.selection.SingleSelect) ComponentEventListener(com.vaadin.flow.component.ComponentEventListener) ComponentValueChangeEvent(com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent)

Aggregations

ComponentValueChangeEvent (com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent)1 ComponentEventListener (com.vaadin.flow.component.ComponentEventListener)1 ComponentUtil (com.vaadin.flow.component.ComponentUtil)1 AbstractGridExtension (com.vaadin.flow.component.grid.Grid.AbstractGridExtension)1 SelectionEvent (com.vaadin.flow.data.selection.SelectionEvent)1 SelectionListener (com.vaadin.flow.data.selection.SelectionListener)1 SingleSelect (com.vaadin.flow.data.selection.SingleSelect)1 SingleSelectionEvent (com.vaadin.flow.data.selection.SingleSelectionEvent)1 SingleSelectionListener (com.vaadin.flow.data.selection.SingleSelectionListener)1 Element (com.vaadin.flow.dom.Element)1 Registration (com.vaadin.flow.shared.Registration)1 JsonObject (elemental.json.JsonObject)1 Collections (java.util.Collections)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1