pl.fhframework.model.forms.Iconable Maven / Gradle / Ivy
package pl.fhframework.model.forms;
import pl.fhframework.Binding;
import pl.fhframework.BindingResult;
import pl.fhframework.binding.ModelBinding;
import pl.fhframework.model.dto.ElementChanges;
import pl.fhframework.model.forms.attribute.IconAlignment;
/**
* Interface which allows form component to have icon inside of it. Implemented class have to have
* two attributes
*
* @Getter
* @Setter
* @XMLProperty
* @DocumentedComponentAttribute("Icon id. Please refer to http://fontawesome.io/icons/ for all
* available icons.")
* private String icon;
*
* @Getter
* @Setter
* @XMLProperty
* @DocumentedComponentAttribute("Icon alignment - possible values are before or after. Final
* alignment depends of component where this attribute is used.")
* private String iconAlignment;
*
* Example of use: <OutputLabel value="This is example" icon="fa fa-image"
* iconAlignment="after"/>
*/
public interface Iconable {
String ICON = "icon";
//TODO remove workaround
static final Binding BINDING = new Binding();
ModelBinding getIconBinding();
String getIcon();
IconAlignment getIconAlignment();
default String resolveIconBinding(FormElement formElement, ElementChanges elementChanges) {
String oldValue = getIcon();
if (getIconBinding() != null) {
BindingResult bindingResult = getIconBinding().getBindingResult();
if (bindingResult != null) {
String newValue = bindingResult.getValue();
if (!formElement.areValuesTheSame(newValue, oldValue)) {
formElement.refreshView();
elementChanges.addChange(ICON, newValue);
return newValue;
}
}
}
return oldValue; // just pass-through
}
}