@Override public ValueSource<?> getValueSource(String property) { return new ContainerValueSource<>(container, property); } }
@SuppressWarnings("unchecked") protected void loadContainer(T component, Element element) { String containerId = element.attributeValue("dataContainer"); String property = element.attributeValue("property"); // In case a component has only a property, // we try to obtain `dataContainer` from a parent element. // For instance, a component is placed within the Form component if (Strings.isNullOrEmpty(containerId) && property != null) { containerId = getParentDataContainer(element); } if (!Strings.isNullOrEmpty(containerId)) { if (property == null) { throw new GuiDevelopmentException( String.format("Can't set container '%s' for component '%s' because 'property' " + "attribute is not defined", containerId, component.getId()), context.getFullFrameId()); } FrameOwner frameOwner = context.getFrame().getFrameOwner(); ScreenData screenData = UiControllerUtils.getScreenData(frameOwner); InstanceContainer container = screenData.getContainer(containerId); if (component instanceof HasValueSource) { ((HasValueSource) component).setValueSource(new ContainerValueSource<>(container, property)); } } }
createField(new ContainerValueSource(instanceContainer, fieldPropertyId), fieldPropertyId, columnConf.getXmlDescriptor());
@Override public CubaEditorField<?> createField(E bean, Grid.Column<E, ?> gridColumn) { ColumnImpl<E> column = dataGrid.getColumnByGridColumn(gridColumn); if (column == null || !column.isShouldBeEditable()) { return null; } Field columnComponent; if (column.getEditFieldGenerator() != null) { ValueSourceProvider valueSourceProvider = dataGrid.createValueSourceProvider(bean); EditorFieldGenerationContext<E> context = new EditorFieldGenerationContext<>(bean, valueSourceProvider); columnComponent = column.getEditFieldGenerator().apply(context); } else { String fieldPropertyId = String.valueOf(column.getPropertyId()); if (column.getEditorFieldGenerator() != null) { Datasource fieldDatasource = dataGrid.createItemDatasource(bean); columnComponent = column.getEditorFieldGenerator().createField(fieldDatasource, fieldPropertyId); } else { InstanceContainer<E> container = dataGrid.createInstanceContainer(bean); columnComponent = fieldFactory.createField( new ContainerValueSource<>(container, fieldPropertyId), fieldPropertyId); } } columnComponent.setParent(dataGrid); columnComponent.setFrame(dataGrid.getFrame()); return createCustomField(columnComponent); }