Search in sources :

Example 66 with ComboBox

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

the class ClientSideFilterPage method createInMemoryComboBox.

private void createInMemoryComboBox() {
    ComboBox<String> inMemoryComboBox = new ComboBox<>("InMemory");
    inMemoryComboBox.setId(IN_MEMORY_COMBO_BOX);
    ComboBoxListDataView<String> listDataView = inMemoryComboBox.setItems(IntStream.range(0, inMemoryComboBox.getPageSize() * 2).mapToObj(i -> "Item " + i).collect(Collectors.toList()));
    Span itemCountSpan = new Span("0");
    itemCountSpan.setId(IN_MEMORY_COMBO_BOX_ITEM_COUNT_SPAN_ID);
    this.add(itemCountSpan);
    addListener(itemCountSpan, listDataView);
    this.add(inMemoryComboBox);
}
Also used : ComboBox(com.vaadin.flow.component.combobox.ComboBox) Span(com.vaadin.flow.component.html.Span)

Example 67 with ComboBox

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

the class DialogWithShortcutPage method createAndOpenDialog.

private Dialog createAndOpenDialog(boolean listenOnDialog, boolean preventDefault) {
    int index = dialogCounter++;
    final String dialogId = DIALOG_ID + index;
    NativeButton myDialogButton = createDialogButton();
    myDialogButton.setId(dialogId + "-button");
    final ComboBox<String> comboBox = new ComboBox<>();
    comboBox.setItems("foo", "bar", "xxx");
    Dialog dialog = new Dialog(new Div(new Div(new Text("" + index)), myDialogButton, new Input(), comboBox));
    NativeButton closeButton = new NativeButton("Close", buttonClickEvent -> dialog.close());
    dialog.add(closeButton);
    dialog.setDraggable(true);
    dialog.open();
    dialog.setId(dialogId);
    final ShortcutRegistration registration = myDialogButton.addClickShortcut(SHORTCUT_KEY);
    if (listenOnDialog) {
        registration.listenOn(dialog);
    }
    registration.setBrowserDefaultAllowed(!preventDefault);
    return dialog;
}
Also used : Div(com.vaadin.flow.component.html.Div) NativeButton(com.vaadin.flow.component.html.NativeButton) Input(com.vaadin.flow.component.html.Input) ComboBox(com.vaadin.flow.component.combobox.ComboBox) Dialog(com.vaadin.flow.component.dialog.Dialog) Text(com.vaadin.flow.component.Text) ShortcutRegistration(com.vaadin.flow.component.ShortcutRegistration)

Example 68 with ComboBox

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

the class MainView method createEditorColumns.

protected void createEditorColumns() {
    Div itemDisplayPanel = new Div();
    Div subPropertyDisplayPanel = new Div();
    subPropertyDisplayPanel.setId("prop-panel");
    Div eventsPanel = new Div();
    eventsPanel.setId("events-panel");
    GridPro<Person> grid = new GridPro<>();
    Button disableGrid = new Button("Disable Grid");
    disableGrid.setId("disable-grid-id");
    List<City> cityList = createCityItems();
    List<Person> personList = createItems();
    mapLists(personList, cityList);
    grid.setItems(personList);
    grid.addCellEditStartedListener(e -> eventsPanel.add(e.getItem().toString()));
    grid.addColumn(Person::getAge).setHeader("Age");
    grid.addEditColumn(Person::getName, "name").text((item, newValue) -> {
        item.setName(newValue);
        itemDisplayPanel.setText(item.toString());
        subPropertyDisplayPanel.setText(newValue);
    }).setHeader("Name").setWidth("300px");
    ComboBox<Department> cb = new ComboBox<>();
    cb.setItems(Department.values());
    grid.addEditColumn(Person::getDepartment).custom(cb, (item, newValue) -> {
        item.setDepartment(newValue);
        itemDisplayPanel.setText(item.toString());
        subPropertyDisplayPanel.setText(String.valueOf(newValue));
    }).setHeader("Department").setWidth("300px");
    ComponentRenderer<Span, Person> booleanRenderer = new ComponentRenderer<>(person -> new Span(person.isSubscriber() ? "Yes" : "No"));
    grid.addEditColumn(Person::isSubscriber, booleanRenderer).checkbox((item, newValue) -> {
        item.setSubscriber(newValue);
        itemDisplayPanel.setText(item.toString());
        subPropertyDisplayPanel.setText(newValue.toString());
    }).setHeader("Subscriber").setWidth("300px");
    ComboBox<City> cityCb = new ComboBox<>();
    cityCb.setItems(cityList);
    cityCb.setItemLabelGenerator(City::getName);
    ComponentRenderer<Span, Person> cityRenderer = new ComponentRenderer<>(person -> {
        if (person.getCity() != null) {
            return new Span(person.getCity().getName());
        } else {
            return new Span("");
        }
    });
    grid.addEditColumn(Person::getCity, cityRenderer).custom(cityCb, (item, newValue) -> {
        item.setCity(newValue);
        newValue.setPerson(item);
        itemDisplayPanel.setText(item.toString());
        subPropertyDisplayPanel.setText(newValue.toString());
    }).setHeader("City").setWidth("300px");
    Input customField = new Input();
    grid.addEditColumn(Person::getEmail).custom(customField, (item, newValue) -> item.setEmail(newValue)).setHeader("Email").setWidth("300px");
    disableGrid.addClickListener(click -> grid.setEnabled(false));
    add(grid, itemDisplayPanel, subPropertyDisplayPanel, eventsPanel, disableGrid);
}
Also used : ComboBox(com.vaadin.flow.component.combobox.ComboBox) Span(com.vaadin.flow.component.html.Span) Div(com.vaadin.flow.component.html.Div) Input(com.vaadin.flow.component.html.Input) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Button(com.vaadin.flow.component.button.Button) GridPro(com.vaadin.flow.component.gridpro.GridPro)

Example 69 with ComboBox

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

the class DemoUI method spinnersContainer.

private Component spinnersContainer() {
    List<Spinner> spinners = Stream.of(SpinnerType.values()).filter(t -> !t.isAlias()).map(DemoUI::createSpinner).collect(Collectors.toList());
    FlexibleGridLayout spinnersContainer = new FlexibleGridLayout().withColumns(Repeat.RepeatMode.AUTO_FILL, new Length("25%")).withPadding(true).withSpacing(true).withItems(spinners.stream().map(s -> spinnerWithName(s, Spinner::getType)).toArray(Component[]::new));
    TextField color = new TextField("Color (--sk-color)", "#333");
    color.addValueChangeListener(e -> spinners.forEach(s -> s.setColor(e.getValue())));
    ComboBox<String> theme = new ComboBox<>("Css class", "", "green", "red");
    theme.setPreventInvalidInput(true);
    theme.addValueChangeListener(e -> spinners.forEach(s -> {
        Optional.ofNullable(e.getOldValue()).ifPresent(css -> s.removeClassName("sk-demo-" + css));
        s.addClassName("sk-demo-" + e.getValue());
    }));
    VerticalLayout commands = new VerticalLayout();
    commands.setAlignItems(FlexComponent.Alignment.START);
    commands.setMargin(false);
    commands.setSpacing(true);
    commands.add(color, theme);
    commands.setSizeUndefined();
    VHorizontalLayout layout = new VHorizontalLayout(commands, spinnersContainer);
    layout.setSizeFull();
    layout.setMargin(true);
    layout.setSpacing(true);
    layout.setFlexGrow(1, spinnersContainer);
    return layout;
}
Also used : Component(com.vaadin.flow.component.Component) CssImport(com.vaadin.flow.component.dependency.CssImport) Div(com.vaadin.flow.component.html.Div) VTabSheet(org.vaadin.firitin.layouts.VTabSheet) PageTitle(com.vaadin.flow.router.PageTitle) ComboBox(com.vaadin.flow.component.combobox.ComboBox) Function(java.util.function.Function) Spinner(org.vaadin.spinkit.Spinner) VVerticalLayout(org.vaadin.firitin.components.orderedlayout.VVerticalLayout) Route(com.vaadin.flow.router.Route) FlexComponent(com.vaadin.flow.component.orderedlayout.FlexComponent) Repeat(com.github.appreciated.css.grid.sizes.Repeat) Length(com.github.appreciated.css.grid.sizes.Length) TextField(com.vaadin.flow.component.textfield.TextField) EnumSet(java.util.EnumSet) RichText(org.vaadin.firitin.components.RichText) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) Collectors(java.util.stream.Collectors) FlexibleGridLayout(com.github.appreciated.layout.FlexibleGridLayout) List(java.util.List) Button(com.vaadin.flow.component.button.Button) Stream(java.util.stream.Stream) Optional(java.util.Optional) VHorizontalLayout(org.vaadin.firitin.components.orderedlayout.VHorizontalLayout) SpinnerType(org.vaadin.spinkit.SpinnerType) Dialog(com.vaadin.flow.component.dialog.Dialog) SpinnerSize(org.vaadin.spinkit.SpinnerSize) Span(com.vaadin.flow.component.html.Span) Length(com.github.appreciated.css.grid.sizes.Length) VHorizontalLayout(org.vaadin.firitin.components.orderedlayout.VHorizontalLayout) Spinner(org.vaadin.spinkit.Spinner) ComboBox(com.vaadin.flow.component.combobox.ComboBox) FlexibleGridLayout(com.github.appreciated.layout.FlexibleGridLayout) TextField(com.vaadin.flow.component.textfield.TextField) VVerticalLayout(org.vaadin.firitin.components.orderedlayout.VVerticalLayout) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) Component(com.vaadin.flow.component.Component) FlexComponent(com.vaadin.flow.component.orderedlayout.FlexComponent)

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