Search in sources :

Example 6 with ListBox

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

the class ListBoxViewDemoPage method addComponentsBetween.

private void addComponentsBetween() {
    ListBox<String> listBox = new ListBox<>();
    listBox.setItems("Bread", "Butter", "Milk");
    // Adding components to the end:
    listBox.add(new H3("After all the items"));
    // Adding components after a specific item:
    listBox.addComponents("Butter", new H3("After butter"));
    // Adding components before a specific item:
    listBox.prependComponents("Bread", new H3("Before bread"));
    addCard("Adding components between items", listBox).setId("list-box-with-components-between");
}
Also used : H3(com.vaadin.flow.component.html.H3) ListBox(com.vaadin.flow.component.listbox.ListBox)

Example 7 with ListBox

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

the class ListBoxViewDemoPage method addItemRenderer.

private void addItemRenderer() {
    ListBox<Item> listBox = new ListBox<>();
    ListBoxListDataView<Item> listDataView = listBox.setItems(getItems());
    listBox.setRenderer(new ComponentRenderer<>(item -> {
        Label name = new Label("Item: " + item.getName());
        Label stock = new Label("In stock: " + item.getStock());
        NativeButton button = new NativeButton("Buy", event -> {
            item.setStock(item.getStock() - 1);
            listDataView.refreshItem(item);
        });
        Div labels = new Div(name, stock);
        Div layout = new Div(labels, button);
        labels.getStyle().set("display", "flex").set("flexDirection", "column").set("marginRight", "10px");
        layout.getStyle().set("display", "flex").set("alignItems", "center");
        return layout;
    }));
    listBox.setItemEnabledProvider(item -> item.getStock() > 0);
    addCard("Using item renderer and disabling items", listBox).setId("list-box-with-renderer");
}
Also used : ListBoxListDataView(com.vaadin.flow.component.listbox.dataview.ListBoxListDataView) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Component(com.vaadin.flow.component.Component) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) Div(com.vaadin.flow.component.html.Div) Label(com.vaadin.flow.component.html.Label) NativeButton(com.vaadin.flow.component.html.NativeButton) ListBox(com.vaadin.flow.component.listbox.ListBox) H3(com.vaadin.flow.component.html.H3) H2(com.vaadin.flow.component.html.H2) Collectors(java.util.stream.Collectors) Route(com.vaadin.flow.router.Route) List(java.util.List) Stream(java.util.stream.Stream) Div(com.vaadin.flow.component.html.Div) NativeButton(com.vaadin.flow.component.html.NativeButton) Label(com.vaadin.flow.component.html.Label) ListBox(com.vaadin.flow.component.listbox.ListBox)

Example 8 with ListBox

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

the class ListBoxDataViewPage method createSetSortComparatorDataView.

private void createSetSortComparatorDataView() {
    Item first = new Item(1L, FIRST);
    Item second = new Item(2L, SECOND);
    Item third = new Item(3L, THIRD);
    ListBox<Item> listBoxForSortDataView = new ListBox<>();
    listBoxForSortDataView.setId(LIST_BOX_FOR_SORT_DATA_VIEW);
    ListBox<Item> otherListBox = new ListBox<>();
    otherListBox.setId(OTHER_LIST_BOX_FOR_SORT_DATA_VIEW);
    final ListDataProvider<Item> dataProvider = DataProvider.ofItems(third, first, second);
    ListBoxListDataView<Item> dataView = listBoxForSortDataView.setItems(dataProvider);
    otherListBox.setItems(dataProvider);
    NativeButton dataViewSortButton = new NativeButton("Sort", click -> dataView.setSortComparator((item1, item2) -> item1.getValue().compareToIgnoreCase(item2.getValue())));
    dataViewSortButton.setId(LIST_DATA_VIEW_SORT_BUTTON);
    add(listBoxForSortDataView, otherListBox, dataViewSortButton);
}
Also used : ListBoxListDataView(com.vaadin.flow.component.listbox.dataview.ListBoxListDataView) ListDataProvider(com.vaadin.flow.data.provider.ListDataProvider) Arrays(java.util.Arrays) Query(com.vaadin.flow.data.provider.Query) MultiSelectListBox(com.vaadin.flow.component.listbox.MultiSelectListBox) AbstractDataProvider(com.vaadin.flow.data.provider.AbstractDataProvider) Set(java.util.Set) Div(com.vaadin.flow.component.html.Div) NativeButton(com.vaadin.flow.component.html.NativeButton) ListBox(com.vaadin.flow.component.listbox.ListBox) AtomicReference(java.util.concurrent.atomic.AtomicReference) ListBoxDataView(com.vaadin.flow.component.listbox.dataview.ListBoxDataView) ArrayList(java.util.ArrayList) Route(com.vaadin.flow.router.Route) HashSet(java.util.HashSet) Objects(java.util.Objects) List(java.util.List) Button(com.vaadin.flow.component.button.Button) Stream(java.util.stream.Stream) DataProvider(com.vaadin.flow.data.provider.DataProvider) Span(com.vaadin.flow.component.html.Span) NativeButton(com.vaadin.flow.component.html.NativeButton) MultiSelectListBox(com.vaadin.flow.component.listbox.MultiSelectListBox) ListBox(com.vaadin.flow.component.listbox.ListBox)

Example 9 with ListBox

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

the class ListBoxDataViewPage method createFilterItemsByDataView.

private void createFilterItemsByDataView() {
    ListBox<Integer> numbers = new ListBox<>();
    numbers.setId(LIST_BOX_FOR_FILTER_DATA_VIEW);
    ListBox<Integer> otherNumbers = new ListBox<>();
    otherNumbers.setId(OTHER_LIST_BOX_FOR_FILTER_DATA_VIEW);
    final ListDataProvider<Integer> dataProvider = DataProvider.ofItems(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
    ListBoxListDataView<Integer> numbersDataView = numbers.setItems(dataProvider);
    otherNumbers.setItems(dataProvider);
    NativeButton filterOdds = new NativeButton("Filter Odds", click -> numbersDataView.setFilter(num -> num % 2 == 0));
    filterOdds.setId(LIST_DATA_VIEW_SET_FILTER_BUTTON);
    NativeButton filterMultiplesOfThree = new NativeButton("Filter Multiples of 3", click -> numbersDataView.addFilter(num -> num % 3 != 0));
    filterMultiplesOfThree.setId(LIST_DATA_VIEW_ADD_FILTER_BUTTON);
    NativeButton noFilter = new NativeButton("No Filter", click -> numbersDataView.removeFilters());
    noFilter.setId(LIST_DATA_VIEW_REMOVE_FILTER_BUTTON);
    add(numbers, otherNumbers, filterOdds, filterMultiplesOfThree, noFilter);
}
Also used : ListBoxListDataView(com.vaadin.flow.component.listbox.dataview.ListBoxListDataView) ListDataProvider(com.vaadin.flow.data.provider.ListDataProvider) Arrays(java.util.Arrays) Query(com.vaadin.flow.data.provider.Query) MultiSelectListBox(com.vaadin.flow.component.listbox.MultiSelectListBox) AbstractDataProvider(com.vaadin.flow.data.provider.AbstractDataProvider) Set(java.util.Set) Div(com.vaadin.flow.component.html.Div) NativeButton(com.vaadin.flow.component.html.NativeButton) ListBox(com.vaadin.flow.component.listbox.ListBox) AtomicReference(java.util.concurrent.atomic.AtomicReference) ListBoxDataView(com.vaadin.flow.component.listbox.dataview.ListBoxDataView) ArrayList(java.util.ArrayList) Route(com.vaadin.flow.router.Route) HashSet(java.util.HashSet) Objects(java.util.Objects) List(java.util.List) Button(com.vaadin.flow.component.button.Button) Stream(java.util.stream.Stream) DataProvider(com.vaadin.flow.data.provider.DataProvider) Span(com.vaadin.flow.component.html.Span) NativeButton(com.vaadin.flow.component.html.NativeButton) MultiSelectListBox(com.vaadin.flow.component.listbox.MultiSelectListBox) ListBox(com.vaadin.flow.component.listbox.ListBox)

Example 10 with ListBox

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

the class ListBoxDataViewPage method createRemoveItemByDataView.

private void createRemoveItemByDataView() {
    Item first = new Item(1L, FIRST);
    Item second = new Item(2L, SECOND);
    ListBox<Item> listBoxForRemoveFromDataView = new ListBox<>();
    listBoxForRemoveFromDataView.setId(LIST_BOX_FOR_REMOVE_FROM_DATA_VIEW);
    ListBox<Item> otherListBox = new ListBox<>();
    otherListBox.setId(OTHER_LIST_BOX_FOR_REMOVE_FROM_DATA_VIEW);
    final ListDataProvider<Item> listDataProvider = DataProvider.ofItems(first, second);
    ListBoxListDataView<Item> dataView = listBoxForRemoveFromDataView.setItems(listDataProvider);
    otherListBox.setItems(listDataProvider);
    NativeButton dataViewRemoveButton = new NativeButton("Remove", click -> dataView.removeItem(second));
    dataViewRemoveButton.setId(LIST_DATA_VIEW_REMOVE_BUTTON);
    add(listBoxForRemoveFromDataView, otherListBox, dataViewRemoveButton);
}
Also used : NativeButton(com.vaadin.flow.component.html.NativeButton) MultiSelectListBox(com.vaadin.flow.component.listbox.MultiSelectListBox) 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