Search in sources :

Example 1 with ListBox

use of com.vaadin.flow.component.listbox.ListBox in project flow-components by vaadin.

the class ListBoxDataViewPage method createGenericDataView.

private void createGenericDataView() {
    Item first = new Item(1L, FIRST);
    Item second = new Item(2L, SECOND);
    List<Item> items = new ArrayList<>(Arrays.asList(first, second));
    GenericDataProvider dataProvider = new GenericDataProvider(items);
    ListBox<Item> listBoxForDataView = new ListBox<>();
    listBoxForDataView.setId(LIST_BOX_FOR_DATA_VIEW);
    ListBoxDataView<Item> dataView = listBoxForDataView.setItems(dataProvider);
    dataView.setIdentifierProvider(Item::getId);
    NativeButton dataViewUpdateButton = new NativeButton("Update", click -> {
        first.setValue(CHANGED_1);
        second.setValue(CHANGED_2);
        dataView.refreshItem(new Item(1L));
    });
    dataViewUpdateButton.setId(DATA_VIEW_UPDATE_BUTTON);
    add(listBoxForDataView, dataViewUpdateButton);
}
Also used : NativeButton(com.vaadin.flow.component.html.NativeButton) ArrayList(java.util.ArrayList) MultiSelectListBox(com.vaadin.flow.component.listbox.MultiSelectListBox) ListBox(com.vaadin.flow.component.listbox.ListBox)

Example 2 with ListBox

use of com.vaadin.flow.component.listbox.ListBox in project flow-components by vaadin.

the class ListBoxDataViewPage method createListDataView.

private void createListDataView() {
    Item first = new Item(1L, FIRST);
    Item second = new Item(2L, SECOND);
    ListBox<Item> listBoxForListDataView = new ListBox<>();
    listBoxForListDataView.setId(LIST_BOX_FOR_LIST_DATA_VIEW);
    ListBoxListDataView<Item> dataView = listBoxForListDataView.setItems(first, second);
    dataView.setIdentifierProvider(Item::getId);
    NativeButton dataViewUpdateButton = new NativeButton("Update", click -> {
        first.setValue(CHANGED_1);
        second.setValue(CHANGED_2);
        dataView.refreshItem(new Item(1L));
    });
    dataViewUpdateButton.setId(LIST_DATA_VIEW_UPDATE_BUTTON);
    add(listBoxForListDataView, dataViewUpdateButton);
}
Also used : NativeButton(com.vaadin.flow.component.html.NativeButton) MultiSelectListBox(com.vaadin.flow.component.listbox.MultiSelectListBox) ListBox(com.vaadin.flow.component.listbox.ListBox)

Example 3 with ListBox

use of com.vaadin.flow.component.listbox.ListBox in project flow-components by vaadin.

the class ListBoxDataViewPage method createAddItemByDataView.

private void createAddItemByDataView() {
    Item first = new Item(1L, FIRST);
    ListBox<Item> listBoxForAddToDataView = new ListBox<>();
    listBoxForAddToDataView.setId(LIST_BOX_FOR_ADD_TO_DATA_VIEW);
    ListBox<Item> otherListBox = new ListBox<>();
    otherListBox.setId(OTHER_LIST_BOX_FOR_ADD_TO_DATA_VIEW);
    final ListDataProvider<Item> listDataProvider = DataProvider.ofItems(first);
    ListBoxListDataView<Item> dataView = listBoxForAddToDataView.setItems(listDataProvider);
    otherListBox.setItems(listDataProvider);
    NativeButton dataViewAddButton = new NativeButton("Add", click -> {
        Item second = new Item(2L, SECOND);
        dataView.addItem(second);
    });
    dataViewAddButton.setId(LIST_DATA_VIEW_ADD_BUTTON);
    add(listBoxForAddToDataView, otherListBox, dataViewAddButton);
}
Also used : NativeButton(com.vaadin.flow.component.html.NativeButton) MultiSelectListBox(com.vaadin.flow.component.listbox.MultiSelectListBox) ListBox(com.vaadin.flow.component.listbox.ListBox)

Example 4 with ListBox

use of com.vaadin.flow.component.listbox.ListBox in project flow-components by vaadin.

the class ListBoxDataViewPage method createNextPreviousItemDataView.

private void createNextPreviousItemDataView() {
    Item first = new Item(1L, FIRST);
    Item second = new Item(2L, SECOND);
    Item third = new Item(3L, THIRD);
    List<Item> items = new ArrayList<>(Arrays.asList(first, second, third));
    ListBox<Item> listBoxForNextPrevDataView = new ListBox<>();
    listBoxForNextPrevDataView.setId(LIST_BOX_FOR_NEXT_PREV_DATA_VIEW);
    ListBoxListDataView<Item> dataView = listBoxForNextPrevDataView.setItems(items);
    AtomicReference<Item> current = new AtomicReference<>(second);
    Span currentItem = new Span(current.get().getValue());
    currentItem.setId(CURRENT_ITEM_SPAN);
    Span hasNextItem = new Span(String.valueOf(dataView.getNextItem(current.get()).isPresent()));
    hasNextItem.setId(HAS_NEXT_ITEM_SPAN);
    Span hasPrevItem = new Span(String.valueOf(dataView.getPreviousItem(current.get()).isPresent()));
    hasPrevItem.setId(HAS_PREV_ITEM_SPAN);
    NativeButton dataViewNextButton = new NativeButton("Next", click -> {
        current.set(dataView.getNextItem(current.get()).get());
        currentItem.setText(current.get().getValue());
        hasNextItem.setText(String.valueOf(dataView.getNextItem(current.get()).isPresent()));
        hasPrevItem.setText(String.valueOf(dataView.getPreviousItem(current.get()).isPresent()));
    });
    dataViewNextButton.setId(LIST_DATA_VIEW_NEXT_BUTTON);
    NativeButton dataViewPrevButton = new NativeButton("Previous", click -> {
        current.set(dataView.getPreviousItem(current.get()).get());
        currentItem.setText(current.get().getValue());
        hasNextItem.setText(String.valueOf(dataView.getNextItem(current.get()).isPresent()));
        hasPrevItem.setText(String.valueOf(dataView.getPreviousItem(current.get()).isPresent()));
    });
    dataViewPrevButton.setId(LIST_DATA_VIEW_PREV_BUTTON);
    add(listBoxForNextPrevDataView, dataViewNextButton, dataViewPrevButton, currentItem, hasNextItem, hasPrevItem);
}
Also used : NativeButton(com.vaadin.flow.component.html.NativeButton) ArrayList(java.util.ArrayList) AtomicReference(java.util.concurrent.atomic.AtomicReference) MultiSelectListBox(com.vaadin.flow.component.listbox.MultiSelectListBox) ListBox(com.vaadin.flow.component.listbox.ListBox) Span(com.vaadin.flow.component.html.Span)

Example 5 with ListBox

use of com.vaadin.flow.component.listbox.ListBox in project flow-components by vaadin.

the class ListBoxViewDemoPage method addListboxWithSelection.

private void addListboxWithSelection() {
    Label message = new Label("-");
    ListBox<String> listBox = new ListBox<>();
    listBox.setItems("Bread", "Butter", "Milk");
    listBox.addValueChangeListener(event -> message.setText(String.format("Selection changed from %s to %s, selection is from client: %s", event.getOldValue(), event.getValue(), event.isFromClient())));
    NativeButton button = new NativeButton("Select Milk", event -> listBox.setValue("Milk"));
    addCard("ListBox and selection", listBox, button, message).setId("list-box-with-selection");
}
Also used : NativeButton(com.vaadin.flow.component.html.NativeButton) Label(com.vaadin.flow.component.html.Label) ListBox(com.vaadin.flow.component.listbox.ListBox)

Aggregations

ListBox (com.vaadin.flow.component.listbox.ListBox)12 NativeButton (com.vaadin.flow.component.html.NativeButton)11 MultiSelectListBox (com.vaadin.flow.component.listbox.MultiSelectListBox)8 ArrayList (java.util.ArrayList)5 Span (com.vaadin.flow.component.html.Span)4 Button (com.vaadin.flow.component.button.Button)3 Div (com.vaadin.flow.component.html.Div)3 Label (com.vaadin.flow.component.html.Label)3 ListBoxListDataView (com.vaadin.flow.component.listbox.dataview.ListBoxListDataView)3 Route (com.vaadin.flow.router.Route)3 List (java.util.List)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 Stream (java.util.stream.Stream)3 H3 (com.vaadin.flow.component.html.H3)2 ListBoxDataView (com.vaadin.flow.component.listbox.dataview.ListBoxDataView)2 AbstractDataProvider (com.vaadin.flow.data.provider.AbstractDataProvider)2 DataProvider (com.vaadin.flow.data.provider.DataProvider)2 ListDataProvider (com.vaadin.flow.data.provider.ListDataProvider)2 Query (com.vaadin.flow.data.provider.Query)2 Arrays (java.util.Arrays)2