use of com.vaadin.flow.data.renderer.ComponentRenderer in project flow-components by vaadin.
the class MainView method createEditorColumns.
protected void createEditorColumns() {
Div itemDisplayPanel = new Div();
Div subPropertyDisplayPanel = new Div();
subPropertyDisplayPanel.setId("prop-panel");
Div eventsPanel = new Div();
eventsPanel.setId("events-panel");
GridPro<Person> grid = new GridPro<>();
Button disableGrid = new Button("Disable Grid");
disableGrid.setId("disable-grid-id");
List<City> cityList = createCityItems();
List<Person> personList = createItems();
mapLists(personList, cityList);
grid.setItems(personList);
grid.addCellEditStartedListener(e -> eventsPanel.add(e.getItem().toString()));
grid.addColumn(Person::getAge).setHeader("Age");
grid.addEditColumn(Person::getName, "name").text((item, newValue) -> {
item.setName(newValue);
itemDisplayPanel.setText(item.toString());
subPropertyDisplayPanel.setText(newValue);
}).setHeader("Name").setWidth("300px");
ComboBox<Department> cb = new ComboBox<>();
cb.setItems(Department.values());
grid.addEditColumn(Person::getDepartment).custom(cb, (item, newValue) -> {
item.setDepartment(newValue);
itemDisplayPanel.setText(item.toString());
subPropertyDisplayPanel.setText(String.valueOf(newValue));
}).setHeader("Department").setWidth("300px");
ComponentRenderer<Span, Person> booleanRenderer = new ComponentRenderer<>(person -> new Span(person.isSubscriber() ? "Yes" : "No"));
grid.addEditColumn(Person::isSubscriber, booleanRenderer).checkbox((item, newValue) -> {
item.setSubscriber(newValue);
itemDisplayPanel.setText(item.toString());
subPropertyDisplayPanel.setText(newValue.toString());
}).setHeader("Subscriber").setWidth("300px");
ComboBox<City> cityCb = new ComboBox<>();
cityCb.setItems(cityList);
cityCb.setItemLabelGenerator(City::getName);
ComponentRenderer<Span, Person> cityRenderer = new ComponentRenderer<>(person -> {
if (person.getCity() != null) {
return new Span(person.getCity().getName());
} else {
return new Span("");
}
});
grid.addEditColumn(Person::getCity, cityRenderer).custom(cityCb, (item, newValue) -> {
item.setCity(newValue);
newValue.setPerson(item);
itemDisplayPanel.setText(item.toString());
subPropertyDisplayPanel.setText(newValue.toString());
}).setHeader("City").setWidth("300px");
Input customField = new Input();
grid.addEditColumn(Person::getEmail).custom(customField, (item, newValue) -> item.setEmail(newValue)).setHeader("Email").setWidth("300px");
disableGrid.addClickListener(click -> grid.setEnabled(false));
add(grid, itemDisplayPanel, subPropertyDisplayPanel, eventsPanel, disableGrid);
}
use of com.vaadin.flow.data.renderer.ComponentRenderer in project flow-components by vaadin.
the class RadioButtonGroupDemoPage method addItemRenderer.
private void addItemRenderer() {
Div message = new Div();
RadioButtonGroup<Person> group = new RadioButtonGroup<>();
group.setItems(new Person(1, "Joe"), new Person(2, "John"), new Person(3, "Bill"));
group.setRenderer(new ComponentRenderer<>(person -> new Anchor("http://example.com/" + person.getId(), person.getName())));
group.addValueChangeListener(event -> message.setText(String.format("Radio button group value changed from '%s' to '%s'", getName(event.getOldValue()), getName(event.getValue()))));
group.setId("button-group-renderer");
message.setId("button-group-renderer-value");
addCard("Radio button group with renderer", group, message);
}
use of com.vaadin.flow.data.renderer.ComponentRenderer in project flow-components by vaadin.
the class VirtualListPage method createListWithComponentRendererWithBeansAndPlaceholder.
private void createListWithComponentRendererWithBeansAndPlaceholder() {
VirtualList<Person> list = new VirtualList<>();
list.setHeight("100px");
List<Person> people = createPeople(100);
list.setRenderer(new ComponentRenderer<Div, Person>(person -> {
Div text = new Div(new Text(person.getName()));
text.addClassName("component-rendered");
return text;
}));
list.setItems(people);
list.setId("component-renderer-with-beans");
Person placeholder = new Person();
placeholder.setName("the-placeholder");
list.setPlaceholderItem(placeholder);
add(list);
}
use of com.vaadin.flow.data.renderer.ComponentRenderer in project flow-components by vaadin.
the class GridBenchmark method setParameter.
@Override
public void setParameter(BeforeEvent event, @OptionalParameter String parameter) {
Location location = event.getLocation();
QueryParameters queryParameters = location.getQueryParameters();
Map<String, List<String>> parametersMap = queryParameters.getParameters();
if (!parametersMap.containsKey("variant") || !parametersMap.containsKey("metric")) {
add(new Text("Provide query parameters: variant and metric"));
return;
}
String metric = parametersMap.get("metric").get(0);
String variant = parametersMap.get("variant").get(0);
LoggerFactory.getLogger(GridBenchmark.class).info("Sample: " + variant + "-" + metric);
switch(variant) {
case "simple":
grid = getGrid();
addColumns(grid, 5, false);
break;
case "multicolumn":
grid = getGrid();
addColumns(grid, 50, false);
break;
case "componentrenderers":
grid = getGrid();
addColumns(grid, 5, true);
break;
case "detailsopened":
grid = getGrid();
addColumns(grid, 5, false);
grid.setItemDetailsRenderer(new ComponentRenderer<>(item -> new Text(item.toString())));
items.forEach(item -> grid.setDetailsVisible(item, true));
break;
case "tree":
grid = getTreeGrid();
((TreeGrid<String>) grid).addHierarchyColumn(i -> i);
addColumns(grid, 5, false);
break;
case "mixed":
grid = getTreeGrid();
((TreeGrid<String>) grid).addHierarchyColumn(i -> i);
addColumns(grid, 50, true);
grid.setItemDetailsRenderer(new ComponentRenderer<>(item -> new Text(item.toString())));
treeData.getRootItems().forEach(item -> grid.setDetailsVisible(item, true));
break;
default:
break;
}
switch(metric) {
case "verticalscrollframetime":
add(grid);
whenRendered(grid).then(v -> grid.getElement().executeJs("window.measureScrollFrameTime(this, false)"));
break;
case "horizontalscrollframetime":
add(grid);
whenRendered(grid).then(v -> grid.getElement().executeJs("window.measureScrollFrameTime(this, true)"));
break;
case "rendertime":
measureRendered(grid);
UI.getCurrent().getElement().executeJs("return window.startWhenReady()").then(v -> add(grid));
break;
case "expandtime":
add(grid);
startWhenRendered(grid).then(v -> {
measureRendered(grid);
TreeGrid<String> treeGrid = (TreeGrid<String>) grid;
TreeData<String> data = ((TreeDataProvider<String>) treeGrid.getDataProvider()).getTreeData();
treeGrid.expandRecursively(data.getRootItems(), 5);
});
break;
default:
break;
}
}
use of com.vaadin.flow.data.renderer.ComponentRenderer in project flow-components by vaadin.
the class GridWithTemplatePage method createStandaloneGridWithTemplatesInTheCells.
private void createStandaloneGridWithTemplatesInTheCells() {
Grid<String> grid = new Grid<>();
setCommonGridFeatures(grid, "standalone-template-in-cells");
grid.addColumn(value -> value);
grid.addColumn(new ComponentRenderer<>(value -> getTestTemplate(value, grid.getId().get())));
add(new H3("Grid with templates in the cells"), grid);
}
Aggregations