Search in sources :

Example 36 with ComboBox

use of com.vaadin.flow.component.combobox.ComboBox in project docs by vaadin.

the class GridDynamicHeight method setupInvitationForm.

private void setupInvitationForm() {
    List<Person> people = DataService.getPeople();
    ComboBox<Person> comboBox = new ComboBox<>();
    comboBox.setItems(people);
    comboBox.setItemLabelGenerator(Person::getFullName);
    Button button = new Button("Send invite");
    button.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
    button.addClickListener(e -> {
        sendInvitation(comboBox.getValue());
        comboBox.setValue(null);
    });
    HorizontalLayout layout = new HorizontalLayout(comboBox, button);
    layout.setFlexGrow(1, comboBox);
    add(layout);
}
Also used : Button(com.vaadin.flow.component.button.Button) ComboBox(com.vaadin.flow.component.combobox.ComboBox) Person(com.vaadin.demo.domain.Person) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout)

Example 37 with ComboBox

use of com.vaadin.flow.component.combobox.ComboBox in project furms by unity-idm.

the class ProjectAllocationDashboardFormView method communityAllocation.

private ComboBox<AllocationCommunityComboBoxModel> communityAllocation(Label availableAmountLabel) {
    final ComboBox<AllocationCommunityComboBoxModel> communityAllocationComboBox = new ComboBox<>();
    communityAllocationComboBox.setItemLabelGenerator(resourceType -> resourceType.name);
    communityAllocationComboBox.setReadOnly(true);
    communityAllocationComboBox.setItems(binder.getBean().getAllocationCommunity());
    AllocationCommunityComboBoxModel allocationCommunity = binder.getBean().getAllocationCommunity();
    availableAmount = projectAllocationService.getAvailableAmount(binder.getBean().getCommunityId(), allocationCommunity.id);
    availableAmountLabel.setText(createAvailableLabelContent(allocationCommunity.split));
    binder.forField(communityAllocationComboBox).bind(ProjectAllocationViewModel::getAllocationCommunity, ProjectAllocationViewModel::setAllocationCommunity);
    return communityAllocationComboBox;
}
Also used : ComboBox(com.vaadin.flow.component.combobox.ComboBox) AllocationCommunityComboBoxModel(io.imunity.furms.ui.components.support.models.allocation.AllocationCommunityComboBoxModel)

Example 38 with ComboBox

use of com.vaadin.flow.component.combobox.ComboBox 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 39 with ComboBox

use of com.vaadin.flow.component.combobox.ComboBox in project flow-components by vaadin.

the class ComboBoxView method lazyLoadingWithCustomItemCountEstimate.

private void lazyLoadingWithCustomItemCountEstimate() {
    // The backend will have 12345 items
    PersonService service = new PersonService(12345);
    ComboBox<Person> comboBox = new ComboBox<>();
    ComboBoxLazyDataView<Person> lazyDataView = comboBox.setItems(query -> service.fetch(query.getFilter().orElse(null), query.getOffset(), query.getLimit()));
    /*
         * By default, the combo box will initially adjust the scrollbar to 200
         * items and as the user scrolls down it automatically increases the
         * size by 200 until the backend runs out of items.
         *
         * Depending on the desired UX and the backend performance, the
         * scrolling experience and the number of items in the drop down can be
         * customized accordingly by constraining the page size, estimated item
         * count and its increase.
         */
    comboBox.setPageSize(10);
    lazyDataView.setItemCountEstimate(50);
    lazyDataView.setItemCountEstimateIncrease(50);
    // Showing the item count for demo purposes
    Div countText = new Div();
    lazyDataView.addItemCountChangeListener(event -> {
        if (event.isItemCountEstimated()) {
            countText.setText("Person Count Estimate: " + event.getItemCount());
        } else {
            countText.setText("Exact Person Count: " + event.getItemCount());
        }
    });
    HorizontalLayout layout = new HorizontalLayout(comboBox, countText);
    comboBox.setId("custom-item-count-estimate");
    addCard("Lazy Loading", "Custom Item Count Estimate And Increase", layout);
}
Also used : Div(com.vaadin.flow.component.html.Div) ComboBox(com.vaadin.flow.component.combobox.ComboBox) PersonService(com.vaadin.flow.component.combobox.test.service.PersonService) Person(com.vaadin.flow.component.combobox.test.entity.Person) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout)

Example 40 with ComboBox

use of com.vaadin.flow.component.combobox.ComboBox in project flow-components by vaadin.

the class ComboBoxView method disabledAndReadonly.

private void disabledAndReadonly() {
    Div div = new Div();
    ComboBox<String> disabledComboBox = new ComboBox<>();
    disabledComboBox.setItems("Value", "Option one", "Option two");
    disabledComboBox.setEnabled(false);
    disabledComboBox.setValue("Value");
    disabledComboBox.setLabel("Disabled");
    ComboBox<String> readOnlyComboBox = new ComboBox<>();
    readOnlyComboBox.setItems("Value", "Option one", "Option two");
    readOnlyComboBox.setReadOnly(true);
    readOnlyComboBox.setValue("Value");
    readOnlyComboBox.setLabel("Read-only");
    disabledComboBox.getStyle().set("margin-right", "5px");
    div.add(disabledComboBox, readOnlyComboBox);
    addCard("Disabled and read-only", div);
}
Also used : Div(com.vaadin.flow.component.html.Div) ComboBox(com.vaadin.flow.component.combobox.ComboBox)

Aggregations

ComboBox (com.vaadin.flow.component.combobox.ComboBox)69 Div (com.vaadin.flow.component.html.Div)35 Span (com.vaadin.flow.component.html.Span)21 NativeButton (com.vaadin.flow.component.html.NativeButton)20 Route (com.vaadin.flow.router.Route)18 List (java.util.List)16 H2 (com.vaadin.flow.component.html.H2)14 Collectors (java.util.stream.Collectors)14 Label (com.vaadin.flow.component.html.Label)12 ComponentRenderer (com.vaadin.flow.data.renderer.ComponentRenderer)12 Stream (java.util.stream.Stream)12 Component (com.vaadin.flow.component.Component)10 VerticalLayout (com.vaadin.flow.component.orderedlayout.VerticalLayout)10 ArrayList (java.util.ArrayList)10 Button (com.vaadin.flow.component.button.Button)9 Person (com.vaadin.flow.component.combobox.test.entity.Person)9 PersonService (com.vaadin.flow.component.combobox.test.service.PersonService)9 IntStream (java.util.stream.IntStream)9 ItemFilter (com.vaadin.flow.component.combobox.ComboBox.ItemFilter)8 Paragraph (com.vaadin.flow.component.html.Paragraph)8