br.com.jarch.faces.parameter.ParameterView Maven / Gradle / Ivy
package br.com.jarch.faces.parameter;
import br.com.jarch.core.crud.parameter.IParameter;
import br.com.jarch.faces.controller.BaseFilterSelectController;
import br.com.jarch.util.CharacterUtils;
import javax.enterprise.inject.Instance;
import javax.enterprise.inject.spi.CDI;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
public class ParameterView {
private final String idJsf;
private final IParameter> parameter;
private Class extends Converter>> converter;
private Class extends Validator>> validator;
private Class extends BaseFilterSelectController>> filterSelection;
private final boolean rendered;
private final boolean disabled;
private final boolean hideCode;
private final int size;
public ParameterView(String menu, String tab, String fieldSet, IParameter> parameter, JArchParametersViewConfig.ViewConfig annotation) {
this.parameter = parameter;
idJsf = CharacterUtils.removeCharEspecial(CharacterUtils.onlyNumberOrLetter(menu.concat(tab).concat(fieldSet).concat(parameter.getClass().getName())));
if (annotation == null) {
rendered = true;
disabled = false;
hideCode = false;
size = 0;
} else {
converter = annotation.converter();
validator = annotation.validator();
filterSelection = annotation.filterSelection();
rendered = annotation.rendered();
disabled = annotation.disabled();
hideCode = annotation.hideCode();
size = annotation.size();
}
}
public String getIdJsf() {
return idJsf;
}
public IParameter> getParameter() {
return parameter;
}
public Class extends Converter>> getConverter() {
return converter;
}
public Class extends Validator>> getValidator() {
return validator;
}
public Class extends BaseFilterSelectController>> getFilterSelection() {
return filterSelection;
}
public boolean isRendered() {
return rendered;
}
public boolean isDisabled() {
return disabled;
}
public boolean isHideCode() {
return hideCode;
}
public int getSize() {
return size;
}
public String getNameValidator() {
if (validator == null || DefaultValidator.class.equals(validator))
return "";
if (validator.getAnnotation(FacesValidator.class).value().isEmpty())
return validator.getSimpleName().substring(0, 1).toLowerCase().concat(validator.getSimpleName().substring(1));
return validator.getAnnotation(FacesValidator.class).value();
}
public String getNameConverter() {
if (converter == null || DefaultConverter.class.equals(converter))
return "";
if (converter.getAnnotation(FacesConverter.class).value().isEmpty())
return converter.getSimpleName().substring(0, 1).toLowerCase().concat(converter.getSimpleName().substring(1));
return converter.getAnnotation(FacesConverter.class).value();
}
public String getNameFilterSelection() {
if (filterSelection == null || DefaultBaseFilterSelectController.class.equals(filterSelection))
return "";
Instance instance = CDI.current().select(filterSelection);
if (instance.isUnsatisfied()
|| instance.isAmbiguous()
|| !instance.isResolvable()) {
return "";
}
return filterSelection
.getSimpleName()
.substring(0, 1)
.toLowerCase()
.concat(filterSelection.getSimpleName().substring(1));
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy