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);
}
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);
}
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);
}
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);
}
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");
}
Aggregations