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);
}
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;
}
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);
}
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);
}
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);
}
Aggregations