Search in sources :

Example 6 with Person

use of com.vaadin.demo.domain.Person in project docs by vaadin.

the class GridDynamicHeight method setupGrid.

private void setupGrid() {
    // tag::snippet[]
    grid = new Grid<>(Person.class, false);
    grid.setAllRowsVisible(true);
    // end::snippet[]
    grid.addColumn(Person::getFullName).setHeader("Name");
    grid.addColumn(Person::getEmail).setHeader("Email");
    grid.addColumn(person -> person.getAddress().getPhone()).setHeader("Phone");
    grid.addColumn(new ComponentRenderer<>(Button::new, (button, person) -> {
        button.addThemeVariants(ButtonVariant.LUMO_ICON, ButtonVariant.LUMO_ERROR, ButtonVariant.LUMO_TERTIARY);
        button.addClickListener(e -> this.removeInvitation(person));
        button.setIcon(new Icon(VaadinIcon.TRASH));
    })).setHeader("Manage");
    grid.setItems(invitedPeople);
    hint = new Div();
    hint.setText("No invitation has been sent");
    hint.getStyle().set("padding", "var(--lumo-size-l)").set("text-align", "center").set("font-style", "italic").set("color", "var(--lumo-contrast-70pct)");
    add(hint, grid);
}
Also used : ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) DemoExporter(com.vaadin.demo.DemoExporter) DataService(com.vaadin.demo.domain.DataService) Grid(com.vaadin.flow.component.grid.Grid) ButtonVariant(com.vaadin.flow.component.button.ButtonVariant) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout) Div(com.vaadin.flow.component.html.Div) VaadinIcon(com.vaadin.flow.component.icon.VaadinIcon) ComboBox(com.vaadin.flow.component.combobox.ComboBox) ArrayList(java.util.ArrayList) Route(com.vaadin.flow.router.Route) List(java.util.List) Button(com.vaadin.flow.component.button.Button) Icon(com.vaadin.flow.component.icon.Icon) Person(com.vaadin.demo.domain.Person) Div(com.vaadin.flow.component.html.Div) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Button(com.vaadin.flow.component.button.Button) VaadinIcon(com.vaadin.flow.component.icon.VaadinIcon) Icon(com.vaadin.flow.component.icon.Icon) Person(com.vaadin.demo.domain.Person)

Example 7 with Person

use of com.vaadin.demo.domain.Person in project docs by vaadin.

the class DialogResizable method createDialogLayout.

private static VerticalLayout createDialogLayout() {
    Grid<Person> grid = new Grid<>(Person.class, false);
    grid.addColumn(Person::getFirstName).setHeader("First name");
    grid.addColumn(Person::getLastName).setHeader("Last name");
    grid.addColumn(Person::getEmail).setHeader("Email");
    grid.addColumn(Person::getProfession).setHeader("Profession");
    grid.addColumn(Person::getMembership).setHeader("Membership");
    List<Person> people = DataService.getPeople();
    grid.setItems(people);
    VerticalLayout dialogLayout = new VerticalLayout(grid);
    dialogLayout.setPadding(false);
    dialogLayout.setAlignItems(FlexComponent.Alignment.STRETCH);
    dialogLayout.getStyle().set("min-width", "300px").set("max-width", "100%").set("height", "100%");
    return dialogLayout;
}
Also used : Grid(com.vaadin.flow.component.grid.Grid) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) Person(com.vaadin.demo.domain.Person)

Example 8 with Person

use of com.vaadin.demo.domain.Person 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 9 with Person

use of com.vaadin.demo.domain.Person in project docs by vaadin.

the class CrudColumns method createEditor.

private CrudEditor<Person> createEditor() {
    TextField firstName = new TextField("First name");
    EmailField email = new EmailField("Email");
    TextField profession = new TextField("Profession");
    DatePicker birthday = new DatePicker("Birthday");
    FormLayout form = new FormLayout(firstName, email, profession, birthday);
    Binder<Person> binder = new Binder<>(Person.class);
    binder.forField(firstName).asRequired().bind(Person::getFirstName, Person::setFirstName);
    binder.forField(email).asRequired().bind(Person::getEmail, Person::setEmail);
    binder.forField(profession).asRequired().bind(Person::getProfession, Person::setProfession);
    binder.forField(birthday).asRequired().withConverter(new LocalDateToDateConverter()).bind(Person::getBirthday, Person::setBirthday);
    return new BinderCrudEditor<>(binder, form);
}
Also used : FormLayout(com.vaadin.flow.component.formlayout.FormLayout) Binder(com.vaadin.flow.data.binder.Binder) EmailField(com.vaadin.flow.component.textfield.EmailField) TextField(com.vaadin.flow.component.textfield.TextField) DatePicker(com.vaadin.flow.component.datepicker.DatePicker) BinderCrudEditor(com.vaadin.flow.component.crud.BinderCrudEditor) Person(com.vaadin.demo.domain.Person) LocalDateToDateConverter(com.vaadin.flow.data.converter.LocalDateToDateConverter)

Example 10 with Person

use of com.vaadin.demo.domain.Person in project docs by vaadin.

the class CrudEditorBottom method createEditor.

private CrudEditor<Person> createEditor() {
    TextField firstName = new TextField("First name");
    TextField lastName = new TextField("Last name");
    EmailField email = new EmailField("Email");
    TextField profession = new TextField("Profession");
    FormLayout form = new FormLayout(firstName, lastName, email, profession);
    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);
}
Also used : FormLayout(com.vaadin.flow.component.formlayout.FormLayout) Binder(com.vaadin.flow.data.binder.Binder) EmailField(com.vaadin.flow.component.textfield.EmailField) TextField(com.vaadin.flow.component.textfield.TextField) BinderCrudEditor(com.vaadin.flow.component.crud.BinderCrudEditor) Person(com.vaadin.demo.domain.Person)

Aggregations

Person (com.vaadin.demo.domain.Person)16 BinderCrudEditor (com.vaadin.flow.component.crud.BinderCrudEditor)12 FormLayout (com.vaadin.flow.component.formlayout.FormLayout)12 TextField (com.vaadin.flow.component.textfield.TextField)12 Binder (com.vaadin.flow.data.binder.Binder)12 EmailField (com.vaadin.flow.component.textfield.EmailField)9 Button (com.vaadin.flow.component.button.Button)3 ComboBox (com.vaadin.flow.component.combobox.ComboBox)3 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)3 Grid (com.vaadin.flow.component.grid.Grid)2 DemoExporter (com.vaadin.demo.DemoExporter)1 DataService (com.vaadin.demo.domain.DataService)1 Html (com.vaadin.flow.component.Html)1 ButtonVariant (com.vaadin.flow.component.button.ButtonVariant)1 DatePicker (com.vaadin.flow.component.datepicker.DatePicker)1 Div (com.vaadin.flow.component.html.Div)1 Icon (com.vaadin.flow.component.icon.Icon)1 VaadinIcon (com.vaadin.flow.component.icon.VaadinIcon)1 VerticalLayout (com.vaadin.flow.component.orderedlayout.VerticalLayout)1 LocalDateToDateConverter (com.vaadin.flow.data.converter.LocalDateToDateConverter)1