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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations