Search in sources :

Example 26 with Binder

use of com.vaadin.flow.data.binder.Binder in project docs by vaadin.

the class CrudOpenEditor 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)

Example 27 with Binder

use of com.vaadin.flow.data.binder.Binder in project docs by vaadin.

the class CrudToolbar method createEditor.

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

Example 28 with Binder

use of com.vaadin.flow.data.binder.Binder in project karnak by OsiriX-Foundation.

the class ExternalIDGrid method setElements.

private void setElements() {
    extidColumn = addColumn(CachedPatient::getPseudonym).setHeader("External Pseudonym").setSortable(true);
    patientIdColumn = addColumn(CachedPatient::getPatientId).setHeader("Patient ID").setSortable(true);
    patientFirstNameColumn = addColumn(CachedPatient::getPatientFirstName).setHeader("Patient first name").setSortable(true);
    patientLastNameColumn = addColumn(CachedPatient::getPatientLastName).setHeader("Patient last name").setSortable(true);
    issuerOfPatientIDColumn = addColumn(CachedPatient::getIssuerOfPatientId).setHeader("Issuer of patient ID").setSortable(true);
    Grid.Column<CachedPatient> editorColumn = addComponentColumn(patient -> {
        Button edit = new Button("Edit");
        edit.addClassName("edit");
        edit.addClickListener(e -> {
            editor.editItem(patient);
            externalIdField.focus();
        });
        edit.setEnabled(!editor.isOpen());
        editButtons.add(edit);
        return edit;
    });
    addFilterElements();
    editButtons = Collections.newSetFromMap(new WeakHashMap<>());
    editor = getEditor();
    editor.setBinder(binder);
    editor.setBuffered(true);
    externalIdField = new TextField();
    patientIdField = new TextField();
    patientFirstNameField = new TextField();
    patientLastNameField = new TextField();
    issuerOfPatientIdField = new TextField();
    extidColumn.setEditorComponent(externalIdField);
    patientIdColumn.setEditorComponent(patientIdField);
    patientFirstNameColumn.setEditorComponent(patientFirstNameField);
    patientLastNameColumn.setEditorComponent(patientLastNameField);
    issuerOfPatientIDColumn.setEditorComponent(issuerOfPatientIdField);
    deleteColumn = addComponentColumn(patient -> {
        deletePatientButton = new Button("Delete");
        deletePatientButton.addThemeVariants(ButtonVariant.LUMO_ERROR, ButtonVariant.LUMO_PRIMARY);
        deletePatientButton.addClickListener(e -> {
            externalIDCache.remove(PatientClientUtil.generateKey(patient, projectEntity.getId()));
            readAllCacheValue();
        });
        return deletePatientButton;
    });
    saveEditPatientButton = new Button(LABEL_SAVE);
    cancelEditPatientButton = new Button(LABEL_CANCEL);
    Div buttons = new Div(saveEditPatientButton, cancelEditPatientButton);
    editorColumn.setEditorComponent(buttons);
}
Also used : CachedPatient(org.karnak.backend.cache.CachedPatient) Binder(com.vaadin.flow.data.binder.Binder) Div(com.vaadin.flow.component.html.Div) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) HeaderRow(com.vaadin.flow.component.grid.HeaderRow) AppConfig(org.karnak.backend.config.AppConfig) ProjectEntity(org.karnak.backend.data.entity.ProjectEntity) PaginatedGrid(org.vaadin.klaudeta.PaginatedGrid) TextField(com.vaadin.flow.component.textfield.TextField) ValueChangeMode(com.vaadin.flow.data.value.ValueChangeMode) WeakHashMap(java.util.WeakHashMap) PatientClient(org.karnak.backend.cache.PatientClient) Grid(com.vaadin.flow.component.grid.Grid) CachedPatient(org.karnak.backend.cache.CachedPatient) Iterator(java.util.Iterator) ButtonVariant(com.vaadin.flow.component.button.ButtonVariant) Editor(com.vaadin.flow.component.grid.editor.Editor) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) StringLengthValidator(com.vaadin.flow.data.validator.StringLengthValidator) Button(com.vaadin.flow.component.button.Button) List(java.util.List) PseudonymPatient(org.karnak.backend.cache.PseudonymPatient) Collections(java.util.Collections) PatientClientUtil(org.karnak.backend.util.PatientClientUtil) Div(com.vaadin.flow.component.html.Div) Button(com.vaadin.flow.component.button.Button) PaginatedGrid(org.vaadin.klaudeta.PaginatedGrid) Grid(com.vaadin.flow.component.grid.Grid) TextField(com.vaadin.flow.component.textfield.TextField) WeakHashMap(java.util.WeakHashMap)

Example 29 with Binder

use of com.vaadin.flow.data.binder.Binder in project karnak by OsiriX-Foundation.

the class GridSwitchingAlbums method setEditorColumn.

private void setEditorColumn() {
    editor = getEditor();
    editor.setBinder(binder);
    editor.setBuffered(true);
    Column<KheopsAlbumsEntity> editorColumn = addComponentColumn(kheopsAlbums -> {
        Button edit = new Button("Edit");
        edit.addClickListener(e -> editor.editItem(kheopsAlbums));
        edit.setEnabled(!editor.isOpen());
        Button remove = new Button("Remove");
        remove.addThemeVariants(ButtonVariant.LUMO_ERROR, ButtonVariant.LUMO_PRIMARY);
        remove.addClickListener(e -> {
            dataProvider.getItems().remove(kheopsAlbums);
            dataProvider.refreshAll();
        });
        remove.setEnabled(!editor.isOpen());
        editButtons.add(edit);
        editButtons.add(remove);
        return new Div(edit, remove);
    }).setFlexGrow(15);
    editor.addOpenListener(e -> editButtons.stream().forEach(button -> button.setEnabled(!editor.isOpen())));
    editor.addCloseListener(e -> editButtons.stream().forEach(button -> button.setEnabled(!editor.isOpen())));
    Button save = new Button("Validate");
    save.addClickListener(event -> {
        // Get the current edited Kheops album
        KheopsAlbumsEntity currentEditedKheopsAlbumsEntity = new KheopsAlbumsEntity();
        if (binder.writeBeanIfValid(currentEditedKheopsAlbumsEntity)) {
            // Save only if not already existing in table
            if (!dataProvider.getItems().contains(currentEditedKheopsAlbumsEntity)) {
                editor.save();
                setItems(dataProvider);
            } else {
                // Show a notification
                Span content = new Span("Already existing");
                content.getStyle().set("color", "var(--lumo-error-text-color)");
                Notification notification = new Notification(content);
                notification.setDuration(3000);
                notification.setPosition(Position.BOTTOM_END);
                notification.open();
            }
        }
    });
    save.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
    Button cancel = new Button("Cancel", e -> editor.cancel());
    Div buttons = new Div(save, cancel);
    editorColumn.setEditorComponent(buttons);
}
Also used : ListDataProvider(com.vaadin.flow.data.provider.ListDataProvider) Grid(com.vaadin.flow.component.grid.Grid) ButtonVariant(com.vaadin.flow.component.button.ButtonVariant) KheopsAlbumsEntity(org.karnak.backend.data.entity.KheopsAlbumsEntity) Editor(com.vaadin.flow.component.grid.editor.Editor) Binder(com.vaadin.flow.data.binder.Binder) Collection(java.util.Collection) Position(com.vaadin.flow.component.notification.Notification.Position) Div(com.vaadin.flow.component.html.Div) ArrayList(java.util.ArrayList) Button(com.vaadin.flow.component.button.Button) TextField(com.vaadin.flow.component.textfield.TextField) Collections(java.util.Collections) Span(com.vaadin.flow.component.html.Span) Notification(com.vaadin.flow.component.notification.Notification) WeakHashMap(java.util.WeakHashMap) Div(com.vaadin.flow.component.html.Div) Button(com.vaadin.flow.component.button.Button) KheopsAlbumsEntity(org.karnak.backend.data.entity.KheopsAlbumsEntity) Span(com.vaadin.flow.component.html.Span) Notification(com.vaadin.flow.component.notification.Notification)

Example 30 with Binder

use of com.vaadin.flow.data.binder.Binder in project DoodleVerse by davidemarcoli.

the class CompanyManagementView method createEditor.

/**
 * Create the Company CRUD-Editor
 * @return the created Crud-Editor
 */
private CrudEditor<Company> createEditor() {
    TextField companyName = new TextField("Company");
    FormLayout form = new FormLayout(companyName);
    form.setMaxWidth("480px");
    form.setResponsiveSteps(new FormLayout.ResponsiveStep("0", 1), new FormLayout.ResponsiveStep("30em", 2));
    Binder<Company> binder = new Binder<>(Company.class);
    binder.forField(companyName).asRequired().bind(Company::getCompanyName, Company::setCompanyName);
    return new BinderCrudEditor<>(binder, form);
}
Also used : FormLayout(com.vaadin.flow.component.formlayout.FormLayout) Binder(com.vaadin.flow.data.binder.Binder) Company(com.dala.data.company.Company) TextField(com.vaadin.flow.component.textfield.TextField) BinderCrudEditor(com.vaadin.flow.component.crud.BinderCrudEditor)

Aggregations

Binder (com.vaadin.flow.data.binder.Binder)36 TextField (com.vaadin.flow.component.textfield.TextField)29 FormLayout (com.vaadin.flow.component.formlayout.FormLayout)21 BinderCrudEditor (com.vaadin.flow.component.crud.BinderCrudEditor)15 Person (com.vaadin.demo.domain.Person)12 Div (com.vaadin.flow.component.html.Div)11 Button (com.vaadin.flow.component.button.Button)10 EmailField (com.vaadin.flow.component.textfield.EmailField)9 Route (com.vaadin.flow.router.Route)8 List (java.util.List)8 Grid (com.vaadin.flow.component.grid.Grid)7 Editor (com.vaadin.flow.component.grid.editor.Editor)7 ArrayList (java.util.ArrayList)7 Checkbox (com.vaadin.flow.component.checkbox.Checkbox)6 Collection (java.util.Collection)6 Collections (java.util.Collections)6 WeakHashMap (java.util.WeakHashMap)6 RichTextEditor (com.vaadin.flow.component.richtexteditor.RichTextEditor)5 EmailValidator (com.vaadin.flow.data.validator.EmailValidator)5 StringLengthValidator (com.vaadin.flow.data.validator.StringLengthValidator)5