Search in sources :

Example 36 with ComponentRenderer

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;
}
Also used : Div(com.vaadin.flow.component.html.Div) VaadinExceptionHandler.handleExceptions(io.imunity.furms.ui.utils.VaadinExceptionHandler.handleExceptions) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Component(com.vaadin.flow.component.Component) Composite(com.vaadin.flow.component.Composite) NotificationUtils.showErrorNotification(io.imunity.furms.ui.utils.NotificationUtils.showErrorNotification) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout) Div(com.vaadin.flow.component.html.Div) FurmsDialog(io.imunity.furms.ui.components.FurmsDialog) MenuButton(io.imunity.furms.ui.components.MenuButton) CommunityAllocationService(io.imunity.furms.api.community_allocation.CommunityAllocationService) DenseGrid(io.imunity.furms.ui.components.DenseGrid) RouterLink(com.vaadin.flow.router.RouterLink) SPLINE_CHART(com.vaadin.flow.component.icon.VaadinIcon.SPLINE_CHART) UI(com.vaadin.flow.component.UI) ANGLE_RIGHT(com.vaadin.flow.component.icon.VaadinIcon.ANGLE_RIGHT) Comparator.comparing(java.util.Comparator.comparing) Icon(com.vaadin.flow.component.icon.Icon) Text(com.vaadin.flow.component.Text) VaadinExceptionHandler.getResultOrException(io.imunity.furms.ui.utils.VaadinExceptionHandler.getResultOrException) AllocationDetailsComponentFactory(io.imunity.furms.ui.components.AllocationDetailsComponentFactory) Grid(com.vaadin.flow.component.grid.Grid) TRASH(com.vaadin.flow.component.icon.VaadinIcon.TRASH) EDIT(com.vaadin.flow.component.icon.VaadinIcon.EDIT) RouterGridLink(io.imunity.furms.ui.components.RouterGridLink) GridActionMenu(io.imunity.furms.ui.components.GridActionMenu) GridActionsButtonLayout(io.imunity.furms.ui.components.GridActionsButtonLayout) ResourceProgressBar(io.imunity.furms.ui.components.ResourceProgressBar) ANGLE_DOWN(com.vaadin.flow.component.icon.VaadinIcon.ANGLE_DOWN) Button(com.vaadin.flow.component.button.Button) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ColumnTextAlign(com.vaadin.flow.component.grid.ColumnTextAlign) Dialog(com.vaadin.flow.component.dialog.Dialog) Collections(java.util.Collections) ViewHeaderLayout(io.imunity.furms.ui.components.ViewHeaderLayout) RouterLink(com.vaadin.flow.router.RouterLink) DenseGrid(io.imunity.furms.ui.components.DenseGrid) Text(com.vaadin.flow.component.Text) Icon(com.vaadin.flow.component.icon.Icon) ResourceProgressBar(io.imunity.furms.ui.components.ResourceProgressBar)

Example 37 with ComponentRenderer

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);
}
Also used : ItemFilter(com.vaadin.flow.component.combobox.ComboBox.ItemFilter) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Person(com.vaadin.flow.component.combobox.test.entity.Person) Image(com.vaadin.flow.component.html.Image) SortDirection(com.vaadin.flow.data.provider.SortDirection) Component(com.vaadin.flow.component.Component) ProjectData(com.vaadin.flow.component.combobox.test.data.ProjectData) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout) ElementData(com.vaadin.flow.component.combobox.test.data.ElementData) Div(com.vaadin.flow.component.html.Div) ComboBox(com.vaadin.flow.component.combobox.ComboBox) Song(com.vaadin.flow.component.combobox.test.entity.Song) ArrayList(java.util.ArrayList) Route(com.vaadin.flow.router.Route) FlexComponent(com.vaadin.flow.component.orderedlayout.FlexComponent) FlexLayout(com.vaadin.flow.component.orderedlayout.FlexLayout) TemplateRenderer(com.vaadin.flow.data.renderer.TemplateRenderer) IntegerField(com.vaadin.flow.component.textfield.IntegerField) ElementConstants(com.vaadin.flow.dom.ElementConstants) Department(com.vaadin.flow.component.combobox.test.entity.Department) Paragraph(com.vaadin.flow.component.html.Paragraph) Notification(com.vaadin.flow.component.notification.Notification) Ticket(com.vaadin.flow.component.combobox.test.entity.Ticket) Project(com.vaadin.flow.component.combobox.test.entity.Project) Anchor(com.vaadin.flow.component.html.Anchor) Query(com.vaadin.flow.data.provider.Query) ComboBoxLazyDataView(com.vaadin.flow.component.combobox.dataview.ComboBoxLazyDataView) Collection(java.util.Collection) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) PersonService(com.vaadin.flow.component.combobox.test.service.PersonService) H2(com.vaadin.flow.component.html.H2) Element(com.vaadin.flow.component.combobox.test.entity.Element) DepartmentData(com.vaadin.flow.component.combobox.test.data.DepartmentData) List(java.util.List) Button(com.vaadin.flow.component.button.Button) Stream(java.util.stream.Stream) ComboBoxListDataView(com.vaadin.flow.component.combobox.dataview.ComboBoxListDataView) Span(com.vaadin.flow.component.html.Span) Div(com.vaadin.flow.component.html.Div) FlexLayout(com.vaadin.flow.component.orderedlayout.FlexLayout) ComboBox(com.vaadin.flow.component.combobox.ComboBox) Image(com.vaadin.flow.component.html.Image)

Example 38 with ComponentRenderer

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));
}
Also used : Div(com.vaadin.flow.component.html.Div) IntStream(java.util.stream.IntStream) ItemFilter(com.vaadin.flow.component.combobox.ComboBox.ItemFilter) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) Div(com.vaadin.flow.component.html.Div) Label(com.vaadin.flow.component.html.Label) H2(com.vaadin.flow.component.html.H2) ComboBox(com.vaadin.flow.component.combobox.ComboBox) Collectors(java.util.stream.Collectors) Route(com.vaadin.flow.router.Route) ArrayList(java.util.ArrayList) List(java.util.List) Faker(com.github.javafaker.Faker) TemplateRenderer(com.vaadin.flow.data.renderer.TemplateRenderer) ElementConstants(com.vaadin.flow.dom.ElementConstants) ComboBox(com.vaadin.flow.component.combobox.ComboBox) Label(com.vaadin.flow.component.html.Label) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) H2(com.vaadin.flow.component.html.H2)

Example 39 with ComponentRenderer

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);
}
Also used : IntStream(java.util.stream.IntStream) ListDataProvider(com.vaadin.flow.data.provider.ListDataProvider) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Div(com.vaadin.flow.component.html.Div) Label(com.vaadin.flow.component.html.Label) NativeButton(com.vaadin.flow.component.html.NativeButton) CallbackDataProvider(com.vaadin.flow.data.provider.CallbackDataProvider) ComboBox(com.vaadin.flow.component.combobox.ComboBox) Collectors(java.util.stream.Collectors) H4(com.vaadin.flow.component.html.H4) Serializable(java.io.Serializable) Route(com.vaadin.flow.router.Route) ComboBoxInATemplate(com.vaadin.flow.component.combobox.test.template.ComboBoxInATemplate) List(java.util.List) Stream(java.util.stream.Stream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DataProvider(com.vaadin.flow.data.provider.DataProvider) Element(com.vaadin.flow.dom.Element) Collections(java.util.Collections) Paragraph(com.vaadin.flow.component.html.Paragraph) Span(com.vaadin.flow.component.html.Span) ListDataProvider(com.vaadin.flow.data.provider.ListDataProvider) NativeButton(com.vaadin.flow.component.html.NativeButton) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) ComboBox(com.vaadin.flow.component.combobox.ComboBox) H4(com.vaadin.flow.component.html.H4)

Example 40 with ComponentRenderer

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);
}
Also used : IntStream(java.util.stream.IntStream) LocalDateRenderer(com.vaadin.flow.data.renderer.LocalDateRenderer) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Arrays(java.util.Arrays) Query(com.vaadin.flow.data.provider.Query) ValueProvider(com.vaadin.flow.function.ValueProvider) LocalDateTime(java.time.LocalDateTime) Div(com.vaadin.flow.component.html.Div) Label(com.vaadin.flow.component.html.Label) NativeButton(com.vaadin.flow.component.html.NativeButton) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Route(com.vaadin.flow.router.Route) NumberRenderer(com.vaadin.flow.data.renderer.NumberRenderer) LocalDateTimeRenderer(com.vaadin.flow.data.renderer.LocalDateTimeRenderer) List(java.util.List) NativeButtonRenderer(com.vaadin.flow.data.renderer.NativeButtonRenderer) Locale(java.util.Locale) DataProvider(com.vaadin.flow.data.provider.DataProvider) TemplateRenderer(com.vaadin.flow.data.renderer.TemplateRenderer) LocalDate(java.time.LocalDate) IronList(com.vaadin.flow.component.ironlist.IronList) HasComponents(com.vaadin.flow.component.HasComponents) Renderer(com.vaadin.flow.data.renderer.Renderer) Label(com.vaadin.flow.component.html.Label) IronList(com.vaadin.flow.component.ironlist.IronList)

Aggregations

ComponentRenderer (com.vaadin.flow.data.renderer.ComponentRenderer)49 Div (com.vaadin.flow.component.html.Div)33 Route (com.vaadin.flow.router.Route)30 Grid (com.vaadin.flow.component.grid.Grid)23 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)20 List (java.util.List)19 Icon (com.vaadin.flow.component.icon.Icon)18 NativeButton (com.vaadin.flow.component.html.NativeButton)14 VaadinIcon (com.vaadin.flow.component.icon.VaadinIcon)14 TemplateRenderer (com.vaadin.flow.data.renderer.TemplateRenderer)14 Collectors (java.util.stream.Collectors)14 Label (com.vaadin.flow.component.html.Label)13 Span (com.vaadin.flow.component.html.Span)12 EnhancedButton (org.komunumo.ui.component.EnhancedButton)12 Component (com.vaadin.flow.component.Component)10 H2 (com.vaadin.flow.component.html.H2)10 ArrayList (java.util.ArrayList)10 Element (com.vaadin.flow.dom.Element)9 Collections (java.util.Collections)9 UI (com.vaadin.flow.component.UI)8