use of com.vaadin.flow.data.provider.DataProvider in project flow-components by vaadin.
the class VirtualListViewPage method createDisabledStringsList.
private void createDisabledStringsList() {
VirtualList<String> list = new VirtualList<>();
list.setHeight("400px");
list.getStyle().set("border", "1px solid lightgray");
Div removalResult = new Div();
removalResult.setId("disabled-removal-result");
DataProvider<String, ?> dataProvider = DataProvider.fromCallbacks(query -> queryStringsFromDatabase(query), query -> countStringsFromDatabase(query));
list.setDataProvider(dataProvider);
// Disable the list so that scrolling still works but events are not
// handled
list.setEnabled(false);
/*
* The name of the event handlers defined at 'on-click' are used inside
* the 'withEventHandler' calls.
*/
list.setRenderer(TemplateRenderer.<String>of("<div style='display:flex; justify-content:space-between; padding:10px;'>" + "<div style='flex-grow:1'>[[item.name]]</div>" + "<div><button on-click='removeItem' style='color:red'>X</button></div>" + "<div>").withProperty("name", ValueProvider.identity()).withEventHandler("removeItem", item -> {
removalResult.setText(item);
}));
NativeButton switchEnabled = new NativeButton("Switch enabled state", event -> list.setEnabled(!list.isEnabled()));
list.setId("disabled-list-with-templates");
switchEnabled.setId("switch-enabled-state-string-list");
add(new Div(new Text("Rank up/down your favorite Lord of the Rings characters")), list, removalResult, switchEnabled);
}
use of com.vaadin.flow.data.provider.DataProvider in project flow-components by vaadin.
the class VirtualListPage method createTemplateFromRendererWithPeople.
private void createTemplateFromRendererWithPeople() {
VirtualList<Person> list = new VirtualList<>();
list.setHeight("100px");
List<Person> people = createPeople(3);
DataProvider<Person, ?> dataProvider = DataProvider.ofCollection(people);
list.setDataProvider(dataProvider);
list.setRenderer(TemplateRenderer.<Person>of("[[item.name]] - [[item.age]] - [[item.user]]").withProperty("name", Person::getName).withProperty("age", Person::getAge).withProperty("user", person -> person.getName().toLowerCase().replace(" ", "_")));
NativeButton update = new NativeButton("Update item 1", evt -> {
Person item = people.get(0);
item.setName(item.getName() + " Updated");
list.getDataProvider().refreshItem(item);
});
list.setId("template-renderer-with-people");
update.setId("template-renderer-with-people-update-item");
add(list, update);
}
use of com.vaadin.flow.data.provider.DataProvider 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);
}
use of com.vaadin.flow.data.provider.DataProvider 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);
}
use of com.vaadin.flow.data.provider.DataProvider in project flow-components by vaadin.
the class IronListTestPage method createTemplateFromRendererWithPeople.
private void createTemplateFromRendererWithPeople() {
IronList<Person> list = new IronList<>();
list.setHeight("100px");
List<Person> people = createPeople(3);
DataProvider<Person, ?> dataProvider = DataProvider.ofCollection(people);
list.setDataProvider(dataProvider);
list.setRenderer(TemplateRenderer.<Person>of("[[item.name]] - [[item.age]] - [[item.user]]").withProperty("name", Person::getName).withProperty("age", Person::getAge).withProperty("user", person -> person.getName().toLowerCase().replace(" ", "_")));
NativeButton update = new NativeButton("Update item 1", evt -> {
Person item = people.get(0);
item.setName(item.getName() + " Updated");
list.getDataProvider().refreshItem(item);
});
list.setId("template-renderer-with-people");
update.setId("template-renderer-with-people-update-item");
add(list, update);
}
Aggregations