use of com.vaadin.flow.data.renderer.ComponentRenderer in project furms by unity-idm.
the class CommunityAllocationComponent method createCommunityGrid.
private Grid<CommunityAllocationGridModel> createCommunityGrid() {
Grid<CommunityAllocationGridModel> grid = new DenseGrid<>(CommunityAllocationGridModel.class);
grid.addComponentColumn(model -> {
Icon icon = grid.isDetailsVisible(model) ? ANGLE_DOWN.create() : ANGLE_RIGHT.create();
return new Div(icon, new Text(model.siteName));
}).setHeader(getTranslation("view.fenix-admin.resource-credits-allocation.grid.column.1")).setSortable(true);
grid.addComponentColumn(model -> new RouterLink(model.name, CommunityAllocationFormView.class, model.id)).setHeader(getTranslation("view.fenix-admin.resource-credits-allocation.grid.column.2")).setSortable(true).setComparator(model -> model.name.toLowerCase());
grid.addColumn(model -> model.resourceCreditName).setHeader(getTranslation("view.fenix-admin.resource-credits-allocation.grid.column.3")).setSortable(true);
grid.addColumn(model -> model.resourceTypeName).setHeader(getTranslation("view.fenix-admin.resource-credits-allocation.grid.column.4")).setSortable(true);
grid.addColumn(model -> model.amountWithUnit).setHeader(getTranslation("view.fenix-admin.resource-credits-allocation.grid.column.5")).setSortable(true).setComparator(comparing(model -> model.amountWithUnit.amount));
grid.addColumn(model -> model.distributedWithUnit).setHeader(getTranslation("view.fenix-admin.resource-credits-allocation.grid.column.6")).setSortable(true).setComparator(comparing(model -> model.distributedWithUnit.amount));
grid.addColumn(model -> model.remainingWithUnit).setHeader(getTranslation("view.fenix-admin.resource-credits-allocation.grid.column.7")).setSortable(true).setComparator(comparing(model -> model.remainingWithUnit.amount));
grid.addComponentColumn(model -> new ResourceProgressBar(model.amountWithUnit.amount, model.consumed, 0)).setHeader(getTranslation("view.fenix-admin.resource-credits-allocation.grid.column.8")).setComparator(comparing(model -> model.consumed));
grid.addComponentColumn(this::createLastColumnContent).setHeader(getTranslation("view.fenix-admin.resource-credits-allocation.grid.column.9")).setTextAlign(ColumnTextAlign.END);
grid.setItemDetailsRenderer(new ComponentRenderer<>(model -> AllocationDetailsComponentFactory.create(model.creationTime, model.validFrom, model.validTo)));
return grid;
}
use of com.vaadin.flow.data.renderer.ComponentRenderer in project flow-components by vaadin.
the class ComboBoxView method customOptionsDemo.
private void customOptionsDemo() {
// ComponentRenderer
ComboBox<Information> comboBox = new ComboBox<>();
comboBox.setLabel("User");
comboBox.setItems(new Information("Gabriella", "https://randomuser.me/api/portraits/women/43.jpg"), new Information("Rudi", "https://randomuser.me/api/portraits/men/77.jpg"), new Information("Hamsa", "https://randomuser.me/api/portraits/men/35.jpg"), new Information("Jacob", "https://randomuser.me/api/portraits/men/76.jpg"));
comboBox.setRenderer(new ComponentRenderer<>(information -> {
Div text = new Div();
text.setText(information.getText());
Image image = new Image();
image.setWidth("21px");
image.setHeight("21px");
image.setSrc(information.getImage());
FlexLayout wrapper = new FlexLayout();
text.getStyle().set("margin-left", "0.5em");
wrapper.add(image, text);
return wrapper;
}));
comboBox.setItemLabelGenerator(Information::getText);
addCard("Presentation", "Customizing drop down items with ComponentRenderer", comboBox);
}
use of com.vaadin.flow.data.renderer.ComponentRenderer in project flow-components by vaadin.
the class ComboBoxDemoPage method createComboBoxUsingComponentRenderer.
private void createComboBoxUsingComponentRenderer() {
Div message = createMessageDiv("component-selection-message");
ComboBox<Song> comboBox = new ComboBox<>();
List<Song> listOfSongs = createListOfSongs();
/*
* Providing a custom item filter allows filtering based on all of the
* rendered properties:
*/
ItemFilter<Song> filter = (song, filterString) -> song.getName().toLowerCase().contains(filterString.toLowerCase()) || song.getArtist().toLowerCase().contains(filterString.toLowerCase());
comboBox.setItems(filter, listOfSongs);
comboBox.setItemLabelGenerator(Song::getName);
comboBox.setRenderer(new ComponentRenderer<>(item -> {
VerticalLayout container = new VerticalLayout();
Label song = new Label(item.getName());
container.add(song);
Label artist = new Label(item.getArtist());
artist.getStyle().set("fontSize", "smaller");
container.add(artist);
return container;
}));
comboBox.addValueChangeListener(event -> {
if (event.getSource().isEmpty()) {
message.setText("No artist selected");
} else if (event.getOldValue() == null) {
message.setText("Selected artist: " + event.getValue().getArtist());
} else {
message.setText("Selected artist: " + event.getValue().getArtist() + "\nThe old selection was: " + event.getOldValue().getArtist());
}
});
comboBox.getStyle().set(ElementConstants.STYLE_WIDTH, WIDTH_STRING);
comboBox.setId("component-selection-box");
add(new Div(new H2("Using components"), new H2("Rendering items using ComponentTemplateRenderer"), comboBox, message));
}
use of com.vaadin.flow.data.renderer.ComponentRenderer in project flow-components by vaadin.
the class LazyLoadingPage method createListDataProviderWithBeans.
private void createListDataProviderWithBeans() {
addTitle("ListDataProvider with beans");
ComboBox<Person> comboBox = new ComboBox<>();
comboBox.setId("lazy-beans");
List<Person> people = IntStream.range(0, 987).mapToObj(i -> new Person("Person " + i, i)).collect(Collectors.toList());
ListDataProvider<Person> personDataProvider = new ListDataProvider<>(people);
comboBox.setDataProvider(personDataProvider);
NativeButton setButton = new NativeButton("set value", e -> comboBox.setValue(people.get(3)));
setButton.setId("set-bean-value");
NativeButton componentRendererButton = new NativeButton("set renderer", e -> comboBox.setRenderer(new ComponentRenderer<H4, Person>(person -> new H4(person.getName()))));
componentRendererButton.setId("component-renderer");
NativeButton itemLabelGeneratorButton = new NativeButton("change item label generator", e -> comboBox.setItemLabelGenerator(person -> "Born " + person.getBorn()));
itemLabelGeneratorButton.setId("item-label-generator");
List<Person> altPeople = IntStream.range(0, 220).mapToObj(i -> new Person("Changed " + i, 2000 + i)).collect(Collectors.toList());
ListDataProvider<Person> altPersonDataProvider = new ListDataProvider<>(altPeople);
NativeButton dataProviderButton = new NativeButton("Change data provider", e -> comboBox.setDataProvider(altPersonDataProvider));
dataProviderButton.setId("data-provider");
NativeButton updateButton = new NativeButton("Update first item", e -> {
people.get(0).setName("Updated");
personDataProvider.refreshItem(people.get(0));
});
updateButton.setId("update-item");
NativeButton removeButton = new NativeButton("Remove third item", e -> {
people.remove(2);
personDataProvider.refreshAll();
});
removeButton.setId("remove-item");
add(comboBox, setButton, componentRendererButton, itemLabelGeneratorButton, dataProviderButton, updateButton, removeButton);
}
use of com.vaadin.flow.data.renderer.ComponentRenderer in project flow-components by vaadin.
the class IronListTestPage method createListWithComponentRendererWithBeansAndPlaceholder.
private void createListWithComponentRendererWithBeansAndPlaceholder() {
IronList<Person> list = new IronList<>();
list.setHeight("100px");
List<Person> people = createPeople(100);
list.setRenderer(new ComponentRenderer<Label, Person>(person -> {
Label label = new Label(person.getName());
label.addClassName("component-rendered");
return label;
}));
list.setItems(people);
list.setId("component-renderer-with-beans");
Person placeholder = new Person();
placeholder.setName("the-placeholder");
list.setPlaceholderItem(placeholder);
add(list);
}
Aggregations