use of com.vaadin.flow.data.renderer.LitRenderer in project flow-components by vaadin.
the class ComboBox method render.
private void render() {
renderingRegistrations.forEach(Registration::remove);
renderingRegistrations.clear();
Rendering<T> rendering;
if (renderer instanceof LitRenderer) {
// LitRenderer
if (template != null && template.getParent() != null) {
getElement().removeChild(template);
}
rendering = renderer.render(getElement(), dataCommunicator.getKeyMapper());
} else {
// TemplateRenderer or ComponentRenderer
if (template == null) {
template = new Element("template");
}
if (template.getParent() == null) {
getElement().appendChild(template);
}
rendering = renderer.render(getElement(), dataCommunicator.getKeyMapper(), template);
}
rendering.getDataGenerator().ifPresent(renderingDataGenerator -> {
Registration renderingDataGeneratorRegistration = dataGenerator.addDataGenerator(renderingDataGenerator);
renderingRegistrations.add(renderingDataGeneratorRegistration);
});
renderingRegistrations.add(rendering.getRegistration());
reset();
}
use of com.vaadin.flow.data.renderer.LitRenderer in project flow-components by vaadin.
the class VirtualList method setRenderer.
/**
* Sets a renderer for the items in the list.
* <p>
* When set, a same renderer is used for the placeholder item. See
* {@link #setPlaceholderItem(Object)} for details.
*
* @param renderer
* a renderer for the items in the list, not <code>null</code>
*/
public void setRenderer(Renderer<T> renderer) {
Objects.requireNonNull(renderer, "The renderer must not be null");
renderingRegistrations.forEach(Registration::remove);
renderingRegistrations.clear();
Rendering<T> rendering;
if (renderer instanceof LitRenderer) {
// LitRenderer
if (template.getParent() != null) {
getElement().removeChild(template);
}
rendering = renderer.render(getElement(), dataCommunicator.getKeyMapper());
} else {
// TemplateRenderer or ComponentRenderer
if (template.getParent() == null) {
getElement().appendChild(template);
}
rendering = renderer.render(getElement(), dataCommunicator.getKeyMapper(), template);
}
rendering.getDataGenerator().ifPresent(renderingDataGenerator -> {
Registration renderingDataGeneratorRegistration = dataGenerator.addDataGenerator(renderingDataGenerator);
renderingRegistrations.add(renderingDataGeneratorRegistration);
});
renderingRegistrations.add(rendering.getRegistration());
this.renderer = renderer;
rendererChanged = true;
registerTemplateUpdate();
getDataCommunicator().reset();
}
use of com.vaadin.flow.data.renderer.LitRenderer in project komunumo-server by komunumo.
the class MembersView method configureGrid.
private void configureGrid() {
final var sponsorDomains = databaseService.getActiveSponsorDomains();
grid.setSelectionMode(Grid.SelectionMode.NONE);
grid.addThemeVariants(GridVariant.LUMO_NO_BORDER, GridVariant.LUMO_ROW_STRIPES);
grid.addColumn(LitRenderer.<Member>of("<span style=\"font-weight: bold;\">${item.fullName}</span><br/><span>${item.company}</span>").withProperty("fullName", Member::getFullName).withProperty("company", Member::getCompany)).setHeader("Name").setAutoWidth(true).setFlexGrow(1);
grid.addColumn(LitRenderer.<Member>of("<a href=\"mailto:${item.email}\" target=\"_blank\">${item.email}</a>").withProperty("email", Member::getEmail)).setHeader("Email").setAutoWidth(true).setKey("email").setFlexGrow(0);
grid.addColumn(new ComponentRenderer<>(member -> new Text(getMembershipText(member, sponsorDomains)))).setHeader("Membership").setAutoWidth(true).setFlexGrow(0);
grid.addColumn(new ComponentRenderer<>(member -> new Icon(member.getAdmin() ? VaadinIcon.CHECK : VaadinIcon.MINUS))).setHeader("Admin").setAutoWidth(true).setTextAlign(ColumnTextAlign.CENTER).setFlexGrow(0);
grid.addColumn(new ComponentRenderer<>(member -> {
final var icon = new Icon(member.getAccountBlocked() ? VaadinIcon.BAN : VaadinIcon.MINUS);
icon.getElement().setAttribute("title", member.getAccountBlockedReason());
return icon;
})).setHeader("Blocked").setAutoWidth(true).setTextAlign(ColumnTextAlign.CENTER).setFlexGrow(0);
grid.addColumn(new ComponentRenderer<>(member -> {
final var editButton = new EnhancedButton(new Icon(VaadinIcon.EDIT), clickEvent -> showMemberDialog(member));
editButton.setTitle("Edit this member");
final var deleteButton = new EnhancedButton(new Icon(VaadinIcon.TRASH), clickEvent -> deleteMember(member));
deleteButton.setTitle("Delete this member");
return new HorizontalLayout(editButton, deleteButton);
})).setHeader("Actions").setAutoWidth(true).setFlexGrow(0);
grid.setHeightFull();
}
use of com.vaadin.flow.data.renderer.LitRenderer in project linkki by linkki-framework.
the class BindComboBoxItemStyleAspectDefinitionTest method testCreateComponentValueSetter.
@Test
void testCreateComponentValueSetter() {
MockVaadin.setup();
String styleName = "bar";
BindComboBoxItemStyleAspectDefinition aspectDefinition = new BindComboBoxItemStyleAspectDefinition(styleName);
ComboBox<Object> comboBox = spy(ComponentFactory.newComboBox());
@SuppressWarnings("unchecked") ArgumentCaptor<LitRenderer<Object>> argumentCaptor = ArgumentCaptor.forClass(LitRenderer.class);
ComponentWrapper componentWrapper = new NoLabelComponentWrapper(comboBox);
Consumer<Function<Object, String>> componentValueSetter = aspectDefinition.createComponentValueSetter(componentWrapper);
componentValueSetter.accept(o -> EXPECTED_STYLE);
verify(comboBox).setRenderer(argumentCaptor.capture());
LitRenderer<Object> renderer = argumentCaptor.getValue();
Rendering<Object> render = renderer.render(new Element("div"), new KeyMapper<>());
JreJsonObject jsonObject = new JreJsonObject(new JreJsonFactory());
render.getDataGenerator().get().generateData(EXPECTED_LABEL, jsonObject);
assertThat(jsonObject.get("lr_0_" + BindComboBoxItemStyleAspectDefinition.LABEL).asString(), is(EXPECTED_LABEL));
assertThat(jsonObject.get("lr_0_" + BindComboBoxItemStyleAspectDefinition.STYLE).asString(), is(EXPECTED_STYLE));
MockVaadin.tearDown();
}
use of com.vaadin.flow.data.renderer.LitRenderer in project flow-components by vaadin.
the class Grid method setItemDetailsRenderer.
/**
* Set the renderer to use for displaying the item details rows in this
* grid.
*
* @param renderer
* the renderer to use for displaying item details rows,
* {@code null} to remove the current renderer
*/
public void setItemDetailsRenderer(Renderer<T> renderer) {
detailsRenderingRegistrations.forEach(Registration::remove);
detailsRenderingRegistrations.clear();
if (renderer == null) {
return;
}
Rendering<T> rendering;
if (renderer instanceof LitRenderer) {
// LitRenderer
if (detailsTemplate != null && detailsTemplate.getParent() != null) {
getElement().removeChild(detailsTemplate);
}
rendering = ((LitRenderer<T>) renderer).render(getElement(), dataCommunicator.getKeyMapper(), "rowDetailsRenderer");
} else {
// TemplateRenderer or ComponentRenderer
if (detailsTemplate == null) {
rendering = renderer.render(getElement(), getDataCommunicator().getKeyMapper());
detailsTemplate = rendering.getTemplateElement();
detailsTemplate.setAttribute("class", "row-details");
} else {
getElement().appendChild(detailsTemplate);
rendering = renderer.render(getElement(), getDataCommunicator().getKeyMapper(), detailsTemplate);
}
}
rendering.getDataGenerator().ifPresent(renderingDataGenerator -> {
itemDetailsDataGenerator = renderingDataGenerator;
Registration detailsRenderingDataGeneratorRegistration = () -> {
detailsManager.destroyAllData();
itemDetailsDataGenerator = null;
};
detailsRenderingRegistrations.add(detailsRenderingDataGeneratorRegistration);
});
detailsRenderingRegistrations.add(rendering.getRegistration());
}
Aggregations