use of com.vaadin.flow.data.renderer.ComponentRenderer in project flow-components by vaadin.
the class TestView method createOptions.
private void createOptions() {
Div options = new Div();
options.add(new NativeButton(SELECT_FIRST_ITEM, event -> select.setValue(items.get(0))));
options.add(new NativeButton(SELECT_THIRD_ITEM, event -> select.setValue(items.get(2))));
options.add(new NativeButton(SELECT_LAST_ITEM, event -> select.setValue(items.get(items.size() - 1))));
options.add(new Div());
options.add(new NativeButton("Reset 0 items", event -> setItems(0)));
options.add(new NativeButton("Reset 1 items", event -> setItems(1)));
options.add(new NativeButton("Reset 2 items", event -> setItems(2)));
options.add(new NativeButton("Reset 5 items", event -> setItems(5)));
options.add(new NativeButton("Reset 10 items", event -> setItems(10)));
options.add(new NativeButton("Reset 20 items", event -> setItems(20)));
options.add(new NativeButton("Reset 50 items", event -> setItems(50)));
options.add(new Div());
options.add(new NativeButton("Refresh item 0", event -> refreshItem(0)));
options.add(new NativeButton("Refresh item 2", event -> refreshItem(2)));
options.add(new NativeButton("Refresh item 10", event -> refreshItem(10)));
options.add(new NativeButton("Refresh All", event -> refreshAll()));
options.add(new Div());
options.add(new Checkbox("ItemLabelGenerator", event -> setItemLabelGenerator(event.getValue())));
options.add(new Checkbox("ItemEnabledProvider", event -> setItemEnabledProvider(event.getValue())));
options.add(new Div());
Checkbox emptySelectionEnabled = new Checkbox("emptySelectionEnabled", event -> setEmptySelectionAllowed(event.getValue()));
emptySelectionEnabled.setValue(select.isEmptySelectionAllowed());
emptySelectionEnabled.setId("emptySelectionEnabled");
options.add(emptySelectionEnabled);
Input emptySelectionCaption = new Input();
emptySelectionCaption.setId("emptySelectionCaption");
emptySelectionCaption.setValue(select.getEmptySelectionCaption());
emptySelectionCaption.addValueChangeListener(event -> setEmptySelectionCaption(event.getValue()));
options.add(new Span("EmptySelectionCaption:"), emptySelectionCaption);
options.add(new Div());
options.add(new NativeButton("focus()", event -> select.focus()));
Checkbox requiredIndicatorVisible = new Checkbox("RequiredIndicator", event -> select.setRequiredIndicatorVisible(event.getValue()));
requiredIndicatorVisible.setValue(select.isRequiredIndicatorVisible());
requiredIndicatorVisible.setId("requiredIndicatorVisible");
options.add(requiredIndicatorVisible);
Input errorMessage = new Input();
errorMessage.setId("errorMessage");
errorMessage.addValueChangeListener(event -> select.setErrorMessage(event.getValue()));
options.add(new Span("errorMessage"), errorMessage);
Input placeholder = new Input();
placeholder.setId("placeholder");
placeholder.addValueChangeListener(event -> select.setPlaceholder(event.getValue()));
options.add(new Span("placeholder"), placeholder);
options.add(new Div());
options.add(new NativeButton("Set renderer", event -> {
if (select.getItemRenderer() == null) {
select.setRenderer(componentRenderer);
} else {
select.setRenderer(null);
}
}), new NativeButton("Add HR 0", event -> addHrInBeginning()), new NativeButton("Remove HR 0", event -> removeHrInBeginning()), new NativeButton("Add HR 2", event -> addHrAfterIndexTwo()), new NativeButton("Remove HR 2", event -> removeHrAfterIndexTwo()), new NativeButton("Add HR LAST", event -> addHrLast()), new NativeButton("Remove HR LAST", event -> removeHrLast()));
options.add(new Div());
enabled = new Checkbox("Enabled");
enabled.setValue(select.isEnabled());
enabled.addValueChangeListener(event -> select.setEnabled(event.getValue()));
readOnly = new Checkbox("ReadOnly");
readOnly.setValue(select.isReadOnly());
readOnly.addValueChangeListener(event -> select.setReadOnly(event.getValue()));
visible = new Checkbox("Visible");
visible.setValue(select.isVisible());
visible.addValueChangeListener(event -> select.setVisible(event.getValue()));
helperText = new Checkbox("HelperText");
helperText.setValue(false);
helperText.addValueChangeListener(event -> {
if (event.getValue())
select.setHelperText("Helper text");
else
select.setHelperText(null);
});
options.add(enabled, readOnly, visible, helperText);
add(options);
}
use of com.vaadin.flow.data.renderer.ComponentRenderer in project flow-components by vaadin.
the class GridItemRefreshPage method createComponentGrid.
private void createComponentGrid() {
Grid<Bean> grid = new Grid<>();
grid.setHeight("500px");
grid.addColumn(new ComponentRenderer<Label, Bean>(item -> new Label(item.getFirstField()))).setHeader("First Field");
grid.addColumn(new ComponentRenderer<Label, Bean>(item -> new Label(String.valueOf(item.getSecondField())))).setHeader("Second Field");
List<Bean> items = createItems(1000);
grid.setItems(items);
grid.setId("component-grid");
Div div = new Div();
div.setText("Component Grid");
add(div, grid);
addButtons(grid, items, "component-");
}
use of com.vaadin.flow.data.renderer.ComponentRenderer 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");
}
use of com.vaadin.flow.data.renderer.ComponentRenderer in project flow-components by vaadin.
the class IronListTestPage method createListWithComponentRenderer.
private void createListWithComponentRenderer() {
IronList<String> list = new IronList<>();
list.setHeight("100px");
List<String> items = IntStream.range(1, 101).mapToObj(i -> "Item " + i).collect(Collectors.toList());
list.setRenderer(new ComponentRenderer<>(item -> {
Label label = new Label(item);
label.addClassName("component-rendered");
return label;
}));
list.setItems(items);
list.setId("component-renderer");
add(list);
}
use of com.vaadin.flow.data.renderer.ComponentRenderer in project flow-components by vaadin.
the class VirtualListPage method createListWithComponentRenderer.
private void createListWithComponentRenderer() {
VirtualList<String> list = new VirtualList<>();
list.setHeight("100px");
List<String> items = IntStream.range(1, 101).mapToObj(i -> "Item " + i).collect(Collectors.toList());
list.setRenderer(new ComponentRenderer<>(item -> {
Div text = new Div(new Text(item));
text.addClassName("component-rendered");
text.setHeight("18px");
return text;
}));
list.setItems(items);
list.setId("component-renderer");
add(list);
}
Aggregations