Search in sources :

Example 1 with BeanValidationBinder

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

the class TextFieldsBindSwitchingAlbum method buildBinder.

private Binder<KheopsAlbumsEntity> buildBinder() {
    Binder<KheopsAlbumsEntity> b = new BeanValidationBinder<>(KheopsAlbumsEntity.class);
    b.forField(textAuthorizationDestination).withValidator(StringUtils::isNotBlank, "Token destination is mandatory").withValidator(value -> {
        if (!textUrlAPI.getValue().isBlank()) {
            return validateToken(value, textUrlAPI.getValue(), SwitchingAlbum.MIN_SCOPE_DESTINATION);
        }
        return true;
    }, "Token can't be validate, minimum permissions: [write]").bind(KheopsAlbumsEntity::getAuthorizationDestination, KheopsAlbumsEntity::setAuthorizationDestination);
    b.forField(textAuthorizationSource).withValidator(StringUtils::isNotBlank, "Token source is mandatory").withValidator(value -> {
        if (!textUrlAPI.getValue().isBlank()) {
            return validateToken(value, textUrlAPI.getValue(), SwitchingAlbum.MIN_SCOPE_SOURCE);
        }
        return true;
    }, "Token can't be validate, minimum permissions: [read, send]").bind(KheopsAlbumsEntity::getAuthorizationSource, KheopsAlbumsEntity::setAuthorizationSource);
    b.forField(textUrlAPI).withValidator(StringUtils::isNotBlank, "Url API is mandatory").bind(KheopsAlbumsEntity::getUrlAPI, KheopsAlbumsEntity::setUrlAPI);
    b.forField(textCondition).withValidator(value -> {
        if (!textCondition.getValue().equals("")) {
            expressionError = ExpressionResult.isValid(textCondition.getValue(), new ExprCondition(), Boolean.class);
            textErrorConditionMsg.setText(expressionError.getMsg());
            return expressionError.isValid();
        }
        textErrorConditionMsg.setText("");
        return true;
    }, "Condition is not valid").bind(KheopsAlbumsEntity::getCondition, KheopsAlbumsEntity::setCondition);
    return b;
}
Also used : KheopsAlbumsEntity(org.karnak.backend.data.entity.KheopsAlbumsEntity) Binder(com.vaadin.flow.data.binder.Binder) StringUtils(org.apache.commons.lang3.StringUtils) List(java.util.List) JSONObject(org.json.JSONObject) ExpressionError(org.karnak.backend.model.expression.ExpressionError) BeanValidationBinder(com.vaadin.flow.data.binder.BeanValidationBinder) KheopsApi(org.karnak.backend.api.KheopsApi) TextField(com.vaadin.flow.component.textfield.TextField) ExpressionResult(org.karnak.backend.model.expression.ExpressionResult) Span(com.vaadin.flow.component.html.Span) SwitchingAlbum(org.karnak.backend.service.kheops.SwitchingAlbum) ExprCondition(org.karnak.backend.model.expression.ExprCondition) ExprCondition(org.karnak.backend.model.expression.ExprCondition) StringUtils(org.apache.commons.lang3.StringUtils) BeanValidationBinder(com.vaadin.flow.data.binder.BeanValidationBinder) KheopsAlbumsEntity(org.karnak.backend.data.entity.KheopsAlbumsEntity)

Example 2 with BeanValidationBinder

use of com.vaadin.flow.data.binder.BeanValidationBinder in project iesi by metadew.

the class AdminView method createCategoryEditor.

private Component createCategoryEditor(Category category) {
    TextField nameField = new TextField();
    if (category.getId() < 0) {
        nameField.focus();
    }
    Button deleteButton = new Button(VaadinIcon.MINUS_CIRCLE_O.create(), event -> {
        DataService.get().deleteCategory(category.getId());
        dataProvider.getItems().remove(category);
        dataProvider.refreshAll();
        Notification.show("Category Deleted.");
    });
    deleteButton.addThemeVariants(ButtonVariant.LUMO_ERROR);
    BeanValidationBinder<Category> binder = new BeanValidationBinder<>(Category.class);
    binder.forField(nameField).bind("name");
    binder.setBean(category);
    binder.addValueChangeListener(event -> {
        if (binder.isValid()) {
            DataService.get().updateCategory(category);
            deleteButton.setEnabled(true);
            newCategoryButton.setEnabled(true);
            Notification.show("Category Saved.");
        }
    });
    deleteButton.setEnabled(category.getId() > 0);
    HorizontalLayout layout = new HorizontalLayout(nameField, deleteButton);
    layout.setFlexGrow(1);
    return layout;
}
Also used : Category(io.metadew.iesi.cockpit.backend.data.Category) Button(com.vaadin.flow.component.button.Button) TextField(com.vaadin.flow.component.textfield.TextField) BeanValidationBinder(com.vaadin.flow.data.binder.BeanValidationBinder) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout)

Example 3 with BeanValidationBinder

use of com.vaadin.flow.data.binder.BeanValidationBinder in project bookstore-example by vaadin.

the class AdminView method createCategoryEditor.

private Component createCategoryEditor(Category category) {
    final TextField nameField = new TextField();
    if (category.getId() < 0) {
        nameField.focus();
    }
    final Button deleteButton = new Button(VaadinIcon.MINUS_CIRCLE_O.create(), event -> {
        // Ask for confirmation before deleting stuff
        final ConfirmDialog dialog = new ConfirmDialog("Please confirm", "Are you sure you want to delete the category? Books in this category will not be deleted.", "Delete", () -> {
            DataService.get().deleteCategory(category.getId());
            dataProvider.getItems().remove(category);
            dataProvider.refreshAll();
            Notification.show("Category Deleted.");
        });
        dialog.open();
    });
    deleteButton.addThemeVariants(ButtonVariant.LUMO_ERROR);
    final BeanValidationBinder<Category> binder = new BeanValidationBinder<>(Category.class);
    binder.forField(nameField).bind("name");
    binder.setBean(category);
    binder.addValueChangeListener(event -> {
        if (binder.isValid()) {
            DataService.get().updateCategory(category);
            deleteButton.setEnabled(true);
            newCategoryButton.setEnabled(true);
            Notification.show("Category Saved.");
        }
    });
    deleteButton.setEnabled(category.getId() > 0);
    final HorizontalLayout layout = new HorizontalLayout(nameField, deleteButton);
    layout.setFlexGrow(1);
    return layout;
}
Also used : Category(org.vaadin.example.bookstore.backend.data.Category) Button(com.vaadin.flow.component.button.Button) TextField(com.vaadin.flow.component.textfield.TextField) BeanValidationBinder(com.vaadin.flow.data.binder.BeanValidationBinder) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout)

Aggregations

TextField (com.vaadin.flow.component.textfield.TextField)3 BeanValidationBinder (com.vaadin.flow.data.binder.BeanValidationBinder)3 Button (com.vaadin.flow.component.button.Button)2 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)2 Span (com.vaadin.flow.component.html.Span)1 Binder (com.vaadin.flow.data.binder.Binder)1 Category (io.metadew.iesi.cockpit.backend.data.Category)1 List (java.util.List)1 StringUtils (org.apache.commons.lang3.StringUtils)1 JSONObject (org.json.JSONObject)1 KheopsApi (org.karnak.backend.api.KheopsApi)1 KheopsAlbumsEntity (org.karnak.backend.data.entity.KheopsAlbumsEntity)1 ExprCondition (org.karnak.backend.model.expression.ExprCondition)1 ExpressionError (org.karnak.backend.model.expression.ExpressionError)1 ExpressionResult (org.karnak.backend.model.expression.ExpressionResult)1 SwitchingAlbum (org.karnak.backend.service.kheops.SwitchingAlbum)1 Category (org.vaadin.example.bookstore.backend.data.Category)1