use of com.vaadin.flow.component.combobox.ComboBox in project vaadin-spinkit by mcollovati.
the class DemoUI method spinnerSizesContainer.
private Component spinnerSizesContainer() {
List<Spinner> spinners = EnumSet.complementOf(EnumSet.of(SpinnerSize.DEFAULT)).stream().map(size -> {
Spinner s = createSpinner(SpinnerType.PLANE);
s.setSize(size);
s.setTitle(size.name());
return s;
}).collect(Collectors.toList());
List<SpinnerType> spinnerTypes = Stream.of(SpinnerType.values()).filter(t -> !t.isAlias()).collect(Collectors.toList());
ComboBox<SpinnerType> selector = new ComboBox<>("Select spinner type", spinnerTypes);
selector.setPreventInvalidInput(true);
selector.setValue(SpinnerType.ROTATING_PLANE);
selector.addValueChangeListener(e -> spinners.forEach(s -> s.setType(selector.getValue())));
TextField baseSize = new TextField("Base size (--sk-size)", "40px");
baseSize.addValueChangeListener(e -> spinners.forEach(s -> s.setBaseSize(e.getValue())));
FlexibleGridLayout spinnersContainer = new FlexibleGridLayout().withColumns(Repeat.RepeatMode.AUTO_FILL, new Length("25%")).withPadding(true).withSpacing(true).withItems(spinners.stream().map(s -> spinnerWithName(s, Spinner::getSize)).toArray(Component[]::new));
for (SpinnerSize size : EnumSet.complementOf(EnumSet.of(SpinnerSize.DEFAULT))) {
Spinner spinner = new Spinner(SpinnerType.PLANE);
spinner.setSize(size);
spinner.setTitle(size.name());
spinners.add(spinner);
}
VerticalLayout commands = new VerticalLayout();
commands.setSizeUndefined();
commands.setAlignItems(FlexComponent.Alignment.START);
commands.setMargin(false);
commands.setSpacing(true);
commands.add(selector, baseSize);
VHorizontalLayout layout = new VHorizontalLayout(commands, spinnersContainer);
layout.setSizeFull();
layout.setMargin(true);
layout.setSpacing(true);
layout.setFlexGrow(1, spinnersContainer);
return layout;
}
use of com.vaadin.flow.component.combobox.ComboBox in project linkki by linkki-framework.
the class AvailableValuesAspectDefinitionTest method testUiUpdater_SetComboBoxValueBeforeUiUpdate.
@Test
void testUiUpdater_SetComboBoxValueBeforeUiUpdate() {
AvailableValuesAspectDefinition<ComboBox<Object>> availableValuesAspectDefinition = new AvailableValuesAspectDefinition<>(AvailableValuesType.DYNAMIC, ComboBox::setItems);
ComboBox<TestEnum> component = new ComboBox<>();
availableValuesAspectDefinition.createUiUpdater(mock(PropertyDispatcher.class), new NoLabelComponentWrapper(component));
// linkki sets values before the UI updater has been called for the first time
component.setValue(TestEnum.ONE);
}
use of com.vaadin.flow.component.combobox.ComboBox in project linkki by linkki-framework.
the class GenericAvailableValuesAspectDefinitionTest method testHandleNullItems_ComboBox_WithNullValue.
@Test
public void testHandleNullItems_ComboBox_WithNullValue() {
GenericAvailableValuesAspectDefinition hasItemsAvailableValuesAspectDefinition = new GenericAvailableValuesAspectDefinition(AvailableValuesType.DYNAMIC);
ComboBox<TestEnum> comboBox = new ComboBox<>();
ComponentWrapper componentWrapper = new NoLabelComponentWrapper(comboBox, WrapperType.FIELD);
hasItemsAvailableValuesAspectDefinition.handleNullItems(componentWrapper, new LinkedList<>(Arrays.asList(TestEnum.ONE, null)));
assertThat(comboBox.isAllowCustomValue());
}
use of com.vaadin.flow.component.combobox.ComboBox in project linkki by linkki-framework.
the class GenericAvailableValuesAspectDefinitionTest method testHandleNullItems_ComboBox_NoNullValue.
@Test
public void testHandleNullItems_ComboBox_NoNullValue() {
GenericAvailableValuesAspectDefinition hasItemsAvailableValuesAspectDefinition = new GenericAvailableValuesAspectDefinition(AvailableValuesType.DYNAMIC);
ComboBox<TestEnum> comboBox = new ComboBox<>();
ComponentWrapper componentWrapper = new NoLabelComponentWrapper(comboBox, WrapperType.FIELD);
hasItemsAvailableValuesAspectDefinition.handleNullItems(componentWrapper, new LinkedList<>(Arrays.asList(TestEnum.TWO)));
assertThat(comboBox.isAllowCustomValue(), is(false));
}
use of com.vaadin.flow.component.combobox.ComboBox in project docs by vaadin.
the class CrudEditorContent method createEditor.
// tag::snippet2[]
private CrudEditor<Person> createEditor() {
TextField firstName = new TextField("First name");
TextField lastName = new TextField("Last name");
EmailField email = new EmailField("Email");
ComboBox<String> profession = new ComboBox<>("Profession");
profession.setItems(professions);
FormLayout form = new FormLayout(firstName, lastName, email, profession);
form.setColspan(email, 2);
form.setColspan(profession, 2);
form.setMaxWidth("480px");
form.setResponsiveSteps(new FormLayout.ResponsiveStep("0", 1), new FormLayout.ResponsiveStep("30em", 2));
Binder<Person> binder = new Binder<>(Person.class);
binder.forField(firstName).asRequired().bind(Person::getFirstName, Person::setFirstName);
binder.forField(lastName).asRequired().bind(Person::getLastName, Person::setLastName);
binder.forField(email).asRequired().bind(Person::getEmail, Person::setEmail);
binder.forField(profession).asRequired().bind(Person::getProfession, Person::setProfession);
return new BinderCrudEditor<>(binder, form);
}
Aggregations