All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pl.fhframework.model.forms.attributes.BoundableAttribute Maven / Gradle / Ivy

There is a newer version: 4.10.401
Show newest version
package pl.fhframework.model.forms.attributes;

import com.fasterxml.jackson.annotation.JsonIgnore;

import pl.fhframework.core.FhBindingException;
import pl.fhframework.binding.ModelBinding;
import pl.fhframework.model.dto.ElementChanges;
import pl.fhframework.model.dto.ValueChange;
import pl.fhframework.model.forms.Component;

import java.util.Optional;

public interface BoundableAttribute {

    ElementChanges updateView(Component component, ElementChanges elementChanges);

    void updateModel(Component component, ValueChange valueChange);

    default void updateBinding(ValueChange valueChange, ModelBinding modelBinding, Object binding) {
        updateBinding(valueChange, modelBinding, binding, Optional.empty());
    }

    default void updateBinding(ValueChange valueChange, ModelBinding modelBinding, Object binding, Optional formatter) {
        updateBinding(valueChange.getMainValue(), modelBinding, binding, formatter);
    }

    default void updateBindingForValue(Object newValue, ModelBinding modelBinding, Object binding) {
        updateBinding(newValue, modelBinding, binding, Optional.empty());
    }

    default void updateBinding(Object newValue, ModelBinding modelBinding, Object binding, Optional formatter) {
        if (modelBinding != null) {
            if (modelBinding.canChange()) {
                modelBinding.setValue(newValue);
            } else {
                throw new FhBindingException("Can't change read only property '" + binding + "'. Usually this error occurs when  curly brackets '{}' are omitted !");
            }
        }
    }

    @JsonIgnore
    default Optional getOptionalFormatter() {
        return Optional.empty();
    }

    @JsonIgnore
    ModelBinding getModelBinding();

    @JsonIgnore
    void setModelBinding(ModelBinding modelBinding);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy