use of com.vaadin.flow.component.combobox.ComboBox in project linkki by linkki-framework.
the class AvailableValuesAspectDefinitionTest method testSetDataProvider.
@Test
void testSetDataProvider() {
@SuppressWarnings("unchecked") BiConsumer<HasListDataView<Object, ?>, List<Object>> dataProviderSetter = mock(BiConsumer.class);
AvailableValuesAspectDefinition<HasListDataView<Object, ?>> availableValuesAspectDefinition = new AvailableValuesAspectDefinition<>(AvailableValuesType.DYNAMIC, dataProviderSetter);
List<Object> data = new ArrayList<>();
ComboBox<Object> component = new ComboBox<>();
availableValuesAspectDefinition.setDataProvider(new NoLabelComponentWrapper(component), data);
verify(dataProviderSetter).accept(component, data);
}
use of com.vaadin.flow.component.combobox.ComboBox in project linkki by linkki-framework.
the class UICustomFieldIntegrationTest method testWidth.
@Test
void testWidth() {
ComponentAnnotationTestPmo pmo = new ComponentAnnotationTestPmo(getDefaultModelObject());
BindingContext bindingContext = new BindingContext();
Function<Component, ComponentWrapper> wrapperCreator = c -> new NoLabelComponentWrapper(c);
ComboBox<?> componentWithWidth = (ComboBox<?>) UiCreator.createUiElements(pmo, bindingContext, wrapperCreator).collect(Collectors.toList()).get(2).getComponent();
assertThat(componentWithWidth.getWidth(), is("100px"));
}
use of com.vaadin.flow.component.combobox.ComboBox in project linkki by linkki-framework.
the class DynamicFieldBindingTest method testDynamicField_shouldBindToComboBox.
@Test
void testDynamicField_shouldBindToComboBox() {
String value = "semi-annual";
Pmo pmo = new Pmo(new Model(value, true));
BindingContext bindingContext = new BindingContext();
Component component = TestUiUtil.createFirstComponentOf(pmo, bindingContext);
assertNotNull(component);
assertThat(component, is(instanceOf(ComboBox.class)));
@SuppressWarnings("unchecked") ComboBox<String> cb = (ComboBox<String>) component;
assertThat(TestUiUtil.getData(cb), contains(pmo.getPaymentMethodAvailableValues().toArray()));
assertThat(cb.getValue(), is(value));
String newValue = "annual";
TestUiUtil.setUserOriginatedValue(cb, newValue);
assertThat(pmo.model.paymentMethod, is(newValue));
pmo.model.paymentMethod = null;
bindingContext.modelChanged();
assertThat(cb.getValue(), is(nullValue()));
}
use of com.vaadin.flow.component.combobox.ComboBox in project komunumo-server by komunumo.
the class EventDialog method createForm.
// just a lot of fields for the form
@SuppressWarnings("checkstyle:MethodLength")
@Override
public void createForm(@NotNull final FormLayout formLayout, @NotNull final Binder<Event> binder) {
final var type = new Select<>(EventType.values());
final var title = new TextField("Title");
final var subtitle = new TextField("Subtitle");
final var speaker = new MultiselectComboBox<EventSpeakerEntity>("Speaker");
final var organizer = new MultiselectComboBox<Member>("Organizer");
final var description = new RichTextEditor();
final var keyword = new MultiselectComboBox<KeywordEntity>("Keyword");
final var agenda = new RichTextEditor();
final var level = new Select<>(EventLevel.values());
final var language = new Select<>(EventLanguage.values());
final var room = new TextField("Room");
final var travelInstructions = new TextField("Travel instructions");
final var location = new ComboBox<String>("Location");
final var webinarUrl = new TextField("Webinar URL");
final var youtTube = new TextField("YouTube");
final var date = new DateTimePicker("Date & Time");
final var duration = new TimePicker("Duration");
final var eventUrl = new TextField("Event URL");
final var attendeeLimit = new IntegerField("Attendee limit (0 = no limit)");
final var membersOnly = new Checkbox("Members only");
final var published = new Checkbox("Published");
type.setLabel("Type");
type.setRequiredIndicatorVisible(true);
title.setRequiredIndicatorVisible(true);
title.setValueChangeMode(EAGER);
title.addValueChangeListener(changeEvent -> {
if (eventUrl.getValue().equals(URLUtil.createReadableUrl(changeEvent.getOldValue()))) {
eventUrl.setValue(URLUtil.createReadableUrl(changeEvent.getValue()));
}
});
subtitle.setValueChangeMode(EAGER);
speaker.setOrdered(true);
speaker.setItemLabelGenerator(EventSpeakerEntity::fullName);
speaker.setItems(databaseService.getAllEventSpeakers());
organizer.setOrdered(true);
organizer.setItemLabelGenerator(value -> String.format("%s %s", value.getFirstName(), value.getLastName()));
organizer.setItems(databaseService.getAllAdmins());
organizer.setRequiredIndicatorVisible(true);
keyword.setOrdered(true);
keyword.setItemLabelGenerator(KeywordEntity::keyword);
keyword.setItems(databaseService.getAllKeywords());
level.setLabel("Level");
language.setLabel("Language");
location.setItems(databaseService.getAllEventLocations());
location.setAllowCustomValue(true);
location.addValueChangeListener(changeEvent -> {
final var value = changeEvent.getValue();
final var isOnline = "Online".equalsIgnoreCase(value);
webinarUrl.setEnabled(isOnline);
webinarUrl.setRequiredIndicatorVisible(published.getValue() && isOnline);
room.setRequiredIndicatorVisible(!isOnline);
updateEventUrlPrefix(location, date, eventUrl);
binder.validate();
});
room.setValueChangeMode(EAGER);
travelInstructions.setValueChangeMode(EAGER);
webinarUrl.setValueChangeMode(EAGER);
date.setMin(LocalDateTime.now());
date.addValueChangeListener(changeEvent -> updateEventUrlPrefix(location, date, eventUrl));
duration.setStep(Duration.ofMinutes(15));
duration.setMin(LocalTime.of(1, 0));
duration.setMax(LocalTime.of(3, 0));
eventUrl.setValueChangeMode(EAGER);
updateEventUrlPrefix(location, date, eventUrl);
attendeeLimit.setMin(0);
attendeeLimit.setMax(500);
attendeeLimit.setStep(10);
attendeeLimit.setHasControls(true);
published.addValueChangeListener(changeEvent -> {
final var value = changeEvent.getValue();
speaker.setRequiredIndicatorVisible(value);
level.setRequiredIndicatorVisible(value);
description.setRequiredIndicatorVisible(value);
language.setRequiredIndicatorVisible(value);
location.setRequiredIndicatorVisible(value);
room.setRequiredIndicatorVisible(!"Online".equalsIgnoreCase(location.getValue()));
date.setRequiredIndicatorVisible(value);
duration.setRequiredIndicatorVisible(value);
eventUrl.setRequiredIndicatorVisible(value);
binder.validate();
});
formLayout.add(type, title, subtitle, speaker, organizer, level, new CustomLabel("Description"), description, keyword, new CustomLabel("Agenda"), agenda, language, location, room, travelInstructions, webinarUrl, youtTube, date, duration, eventUrl, attendeeLimit, membersOnly, published);
binder.forField(type).withValidator(value -> !published.getValue() || value != null, "Please select a type").bind(Event::getType, Event::setType);
binder.forField(title).withValidator(new StringLengthValidator("Please enter a title (max. 255 chars)", 1, 255)).bind(Event::getTitle, Event::setTitle);
binder.forField(subtitle).withValidator(new StringLengthValidator("The subtitle is too long (max. 255 chars)", 0, 255)).bind(Event::getSubtitle, Event::setSubtitle);
binder.forField(speaker).withValidator(value -> !published.getValue() || !value.isEmpty(), "Please select at least one speaker").bind(this::getSpeakers, this::setSpeakers);
binder.forField(organizer).withValidator(value -> !value.isEmpty(), "Please select at least one organizer").bind(this::getOrganizer, this::setOrganizer);
binder.forField(level).withValidator(value -> !published.getValue() || value != null, "Please select a level").bind(Event::getLevel, Event::setLevel);
binder.forField(description.asHtml()).withValidator(value -> !published.getValue() || value != null && !value.isBlank(), "Please enter a description").bind(Event::getDescription, Event::setDescription);
binder.forField(keyword).bind(this::getKeyword, this::setKeyword);
binder.forField(agenda.asHtml()).bind(Event::getAgenda, Event::setAgenda);
binder.forField(language).withValidator(value -> !published.getValue() || value != null, "Please select a language").bind(Event::getLanguage, Event::setLanguage);
binder.forField(location).withValidator(value -> !published.getValue() || value != null, "Please select a location").bind(Event::getLocation, Event::setLocation);
binder.forField(room).withValidator(value -> !published.getValue() || "Online".equalsIgnoreCase(location.getValue()) || !value.isBlank(), "Please enter a room").bind(Event::getRoom, Event::setRoom);
binder.forField(travelInstructions).withValidator(value -> value.isBlank() || URLUtil.isValid(value), "Please enter a valid URL").bind(Event::getTravelInstructions, Event::setTravelInstructions);
binder.forField(webinarUrl).withValidator(value -> !published.getValue() || !"Online".equalsIgnoreCase(location.getValue()) || URLUtil.isValid(value), "Please enter a valid URL").bind(Event::getWebinarUrl, Event::setWebinarUrl);
binder.forField(youtTube).bind(Event::getYoutube, Event::setYoutube);
binder.forField(date).withValidator(value -> isPastEvent(date) || !published.getValue() && (value == null || value.isAfter(LocalDateTime.now())) || value != null && value.isAfter(LocalDateTime.now()), "Please enter a date and time in the future").bind(Event::getDate, Event::setDate);
binder.forField(duration).withValidator(value -> !published.getValue() || (value != null && value.isAfter(LocalTime.MIN) && value.isBefore(LocalTime.MAX)), "Please enter a duration").bind(Event::getDuration, Event::setDuration);
// TODO check for duplicates
binder.forField(eventUrl).withValidator(value -> !published.getValue() || value != null && !value.isBlank(), "Please enter a valid event URL").bind(Event::getEventUrl, Event::setEventUrl);
binder.forField(attendeeLimit).bind(Event::getAttendeeLimit, Event::setAttendeeLimit);
binder.forField(membersOnly).bind(Event::getMembersOnly, Event::setMembersOnly);
binder.forField(published).bind(Event::getPublished, Event::setPublished);
afterOpen = () -> {
webinarUrl.setEnabled("Online".equalsIgnoreCase(location.getValue()));
if (isPastEvent(date)) {
binder.setReadOnly(true);
binder.setValidatorsDisabled(true);
youtTube.setReadOnly(false);
}
};
}
use of com.vaadin.flow.component.combobox.ComboBox in project komunumo-server by komunumo.
the class SponsorDialog method createForm.
@Override
public void createForm(@NotNull final FormLayout formLayout, @NotNull final Binder<SponsorRecord> binder) {
final var name = new TextField("Name");
final var website = new TextField("Website");
final var level = new ComboBox<SponsorLevel>("Level");
final var logo = new ImageUploadField("Logo");
final var description = new RichTextEditor();
final var validFrom = new DatePicker("Valid from");
final var validTo = new DatePicker("Valid to");
final var domains = new TagField("Domains");
name.setRequiredIndicatorVisible(true);
name.setValueChangeMode(EAGER);
website.setValueChangeMode(EAGER);
level.setItems(SponsorLevel.values());
formLayout.add(name, website, level, logo, new CustomLabel("Description"), description, validFrom, validTo, domains);
binder.forField(name).withValidator(new StringLengthValidator("Please enter the name of the sponsor (max. 255 chars)", 1, 255)).bind(SponsorRecord::getName, SponsorRecord::setName);
binder.forField(website).withValidator(value -> value.isEmpty() || value.startsWith("https://"), "The website address must start with \"https://\"").withValidator(new StringLengthValidator("The website address is too long (max. 255 chars)", 0, 255)).bind(SponsorRecord::getWebsite, SponsorRecord::setWebsite);
binder.forField(level).bind(SponsorRecord::getLevel, SponsorRecord::setLevel);
binder.forField(logo).withValidator(value -> value.isEmpty() || value.startsWith("data:") || value.startsWith("https://"), "The logo must be uploaded or the logo address must be secure (HTTPS)").withValidator(new StringLengthValidator("The logo is too big (max. 100 KB)", 0, 100_000)).bind(SponsorRecord::getLogo, SponsorRecord::setLogo);
binder.forField(description.asHtml()).withValidator(new StringLengthValidator("The description is too long (max. 100'000 chars)", 0, 100_000)).bind(SponsorRecord::getDescription, SponsorRecord::setDescription);
binder.forField(validFrom).withValidator(value -> value == null || validTo.isEmpty() || value.isBefore(validTo.getValue()), "The valid from date must be before the valid to date").bind(SponsorRecord::getValidFrom, SponsorRecord::setValidFrom);
binder.forField(validTo).withValidator(value -> value == null || validFrom.isEmpty() || value.isAfter(validFrom.getValue()), "The valid to date must be after the valid from date").bind(SponsorRecord::getValidTo, SponsorRecord::setValidTo);
binder.forField(domains).bind(this::getDomains, this::setDomains);
}
Aggregations