use of com.haulmont.cuba.gui.components.data.value.ContainerValueSourceProvider in project cuba by cuba-platform.
the class FormLoader method loadDataContainer.
protected void loadDataContainer(Form resultComponent, Element element) {
String containerId = element.attributeValue("dataContainer");
if (!Strings.isNullOrEmpty(containerId)) {
FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
InstanceContainer container = screenData.getContainer(containerId);
// noinspection unchecked
resultComponent.setValueSourceProvider(new ContainerValueSourceProvider(container));
}
}
use of com.haulmont.cuba.gui.components.data.value.ContainerValueSourceProvider in project cuba by cuba-platform.
the class FormLoader method loadDynamicAttributeComponents.
protected List<ComponentPosition> loadDynamicAttributeComponents(ValueSourceProvider provider, @Nullable String columnWidth) {
if (provider instanceof ContainerValueSourceProvider && getMetadataTools().isPersistent(((ContainerValueSourceProvider) provider).getContainer().getEntityMetaClass())) {
String windowId = getWindowId(context);
InstanceContainer instanceContainer = ((ContainerValueSourceProvider) provider).getContainer();
MetaClass metaClass = instanceContainer.getEntityMetaClass();
List<CategoryAttribute> attributesToShow = getDynamicAttributesGuiTools().getSortedAttributesToShowOnTheScreen(metaClass, windowId, resultComponent.getId());
if (!attributesToShow.isEmpty()) {
List<ComponentPosition> components = new ArrayList<>();
if (instanceContainer instanceof HasLoader) {
DataLoader dataLoader = ((HasLoader) instanceContainer).getLoader();
if (dataLoader instanceof InstanceLoader) {
((InstanceLoader) dataLoader).setLoadDynamicAttributes(true);
}
}
for (CategoryAttribute attribute : attributesToShow) {
String code = DynamicAttributesUtils.encodeAttributeCode(attribute.getCode());
ValueSource<?> valueSource = provider.getValueSource(code);
Component dynamicAttrComponent;
if (Boolean.TRUE.equals(attribute.getIsCollection())) {
dynamicAttrComponent = getDynamicAttributesComponentsGenerator().generateComponent(provider.getValueSource(code), attribute);
} else {
ComponentGenerationContext context = new ComponentGenerationContext(metaClass, code);
context.setValueSource(valueSource);
dynamicAttrComponent = getUiComponentsGenerator().generate(context);
}
if (dynamicAttrComponent instanceof Component.HasCaption) {
((Component.HasCaption) dynamicAttrComponent).setCaption(attribute.getLocaleName());
((Component.HasCaption) dynamicAttrComponent).setDescription(attribute.getLocaleDescription());
}
if (dynamicAttrComponent instanceof HasValueSource) {
// noinspection unchecked
((HasValueSource) dynamicAttrComponent).setValueSource(valueSource);
}
if (dynamicAttrComponent instanceof Component.Editable && Boolean.TRUE.equals(attribute.getConfiguration().isReadOnly())) {
((Component.Editable) dynamicAttrComponent).setEditable(false);
}
if (dynamicAttrComponent instanceof Field) {
((Field) dynamicAttrComponent).setRequired(attribute.getRequired());
((Field) dynamicAttrComponent).setRequiredMessage(getMessages().formatMainMessage("validation.required.defaultMsg", attribute.getLocaleName()));
}
String defaultWidth = Strings.isNullOrEmpty(attribute.getWidth()) ? columnWidth : attribute.getWidth();
loadWidth(dynamicAttrComponent, defaultWidth);
components.add(new ComponentPosition(dynamicAttrComponent, 1, 1));
}
return components;
}
}
return Collections.emptyList();
}
Aggregations