use of com.haulmont.cuba.gui.components.FieldGroupFieldFactory in project cuba by cuba-platform.
the class FieldGroupLoader method loadComponent.
@Override
public void loadComponent() {
assignFrame(resultComponent);
String fieldFactoryBean = element.attributeValue("fieldFactoryBean");
if (StringUtils.isNotEmpty(fieldFactoryBean)) {
FieldGroupFieldFactory fieldFactory = beanLocator.get(fieldFactoryBean, FieldGroupFieldFactory.class);
resultComponent.setFieldFactory(fieldFactory);
}
assignXmlDescriptor(resultComponent, element);
loadVisible(resultComponent, element);
loadWidth(resultComponent, element);
loadEditable(resultComponent, element);
loadEnable(resultComponent, element);
loadStyleName(resultComponent, element);
loadCss(resultComponent, element);
loadHtmlSanitizerEnabled(resultComponent, element);
loadIcon(resultComponent, element);
loadCaption(resultComponent, element);
loadDescription(resultComponent, element);
loadContextHelp(resultComponent, element);
loadHeight(resultComponent, element);
loadAlign(resultComponent, element);
loadCaptionAlignment(resultComponent, element);
loadFieldCaptionWidth(resultComponent, element);
Datasource ds = loadDatasource(element);
resultComponent.setDatasource(ds);
if (element.elements("column").isEmpty()) {
Iterable<FieldGroup.FieldConfig> rootFields = loadFields(resultComponent, element, ds, null);
Iterable<FieldGroup.FieldConfig> dynamicAttributeFields = loadDynamicAttributeFields(ds);
for (FieldGroup.FieldConfig field : dynamicAttributeFields) {
if (resultComponent.getWidth() > 0 && field.getWidth() == null) {
field.setWidth("100%");
}
}
for (FieldGroup.FieldConfig field : Iterables.concat(rootFields, dynamicAttributeFields)) {
resultComponent.addField(field);
}
} else {
List<Element> columnElements = element.elements("column");
List<Element> fieldElements = element.elements("field");
if (fieldElements.size() > 0) {
Map<String, Object> params = new HashMap<>();
String fieldGroupId = resultComponent.getId();
if (StringUtils.isNotEmpty(fieldGroupId)) {
params.put("FieldGroup ID", fieldGroupId);
}
throw new GuiDevelopmentException("FieldGroup field elements should be placed within its column.", context, params);
}
resultComponent.setColumns(columnElements.size());
int colIndex = 0;
for (Element columnElement : columnElements) {
String flex = columnElement.attributeValue("flex");
if (StringUtils.isNotEmpty(flex)) {
resultComponent.setColumnExpandRatio(colIndex, Float.parseFloat(flex));
}
String columnWidth = loadThemeString(columnElement.attributeValue("width"));
Iterable<FieldGroup.FieldConfig> columnFields = loadFields(resultComponent, columnElement, ds, columnWidth);
if (colIndex == 0) {
columnFields = Iterables.concat(columnFields, loadDynamicAttributeFields(ds));
}
for (FieldGroup.FieldConfig field : columnFields) {
resultComponent.addField(field, colIndex);
}
String columnFieldCaptionWidth = columnElement.attributeValue("fieldCaptionWidth");
if (StringUtils.isNotEmpty(columnFieldCaptionWidth)) {
if (columnFieldCaptionWidth.startsWith(MessageTools.MARK)) {
columnFieldCaptionWidth = loadResourceString(columnFieldCaptionWidth);
}
if (columnFieldCaptionWidth.endsWith("px")) {
columnFieldCaptionWidth = columnFieldCaptionWidth.substring(0, columnFieldCaptionWidth.indexOf("px"));
}
resultComponent.setFieldCaptionWidth(colIndex, Integer.parseInt(columnFieldCaptionWidth));
}
colIndex++;
}
}
for (FieldGroup.FieldConfig field : resultComponent.getFields()) {
if (!field.isCustom()) {
if (!DynamicAttributesUtils.isDynamicAttribute(field.getProperty())) {
// the following does not make sense for dynamic attributes
loadValidators(resultComponent, field);
loadRequired(resultComponent, field);
loadEnable(resultComponent, field);
}
loadVisible(resultComponent, field);
loadEditable(resultComponent, field);
}
}
resultComponent.bind();
ComponentContext componentContext = getComponentContext();
for (FieldGroup.FieldConfig field : resultComponent.getFields()) {
if (field.getXmlDescriptor() != null) {
String generator = field.getXmlDescriptor().attributeValue("generator");
if (generator != null) {
componentContext.addInjectTask((boundContext, window) -> {
DeclarativeFieldGenerator fieldGenerator = new DeclarativeFieldGenerator(resultComponent, generator);
Component fieldComponent = fieldGenerator.generateField(field.getTargetDatasource(), field.getProperty());
field.setComponent(fieldComponent);
});
}
}
}
}
Aggregations