use of io.jmix.ui.component.data.value.ContainerValueSource in project jmix by jmix-framework.
the class CubaDynAttrComponentGenerationStrategy method createEntityField.
protected EntityPicker createEntityField(ComponentGenerationContext context, AttributeDefinition attribute) {
if (attribute.getConfiguration().isLookup()) {
LookupPickerField lookupPickerField = cubaUiComponents.create(LookupPickerField.class);
if (context.getValueSource() instanceof ContainerValueSource) {
setComboBoxOptionsLoader(lookupPickerField, attribute, (ContainerValueSource) context.getValueSource());
}
setValueSource(lookupPickerField, context);
setValidators(lookupPickerField, attribute);
return lookupPickerField;
} else {
PickerField pickerField = cubaUiComponents.create(PickerField.class);
LookupAction lookupAction = actions.create(LookupAction.class);
setLookupActionScreen(lookupAction, attribute);
pickerField.addAction(lookupAction);
pickerField.addAction(actions.create(ClearAction.class));
setValueSource(pickerField, context);
setValidators(pickerField, attribute);
return pickerField;
}
}
use of io.jmix.ui.component.data.value.ContainerValueSource in project jmix by jmix-framework.
the class TableFieldFactoryImpl method createField.
@SuppressWarnings("unchecked")
@Override
public com.vaadin.v7.ui.Field<?> createField(com.vaadin.v7.data.Container container, Object itemId, Object propertyId, Component uiContext) {
String fieldPropertyId = String.valueOf(propertyId);
Table.Column columnConf = webTable.getColumnsInternal().get(propertyId);
TableDataContainer tableDataContainer = (TableDataContainer) container;
Object entity = tableDataContainer.getInternalItem(itemId);
InstanceContainer instanceContainer = webTable.getInstanceContainer((E) entity);
io.jmix.ui.component.Component columnComponent = createField(new ContainerValueSource(instanceContainer, fieldPropertyId), fieldPropertyId, columnConf.getXmlDescriptor());
if (columnComponent instanceof Field) {
Field jmixField = (Field) columnComponent;
Map<Table.Column, String> requiredColumns = webTable.getRequiredColumnsInternal();
if (requiredColumns != null && requiredColumns.containsKey(columnConf)) {
jmixField.setRequired(true);
jmixField.setRequiredMessage(requiredColumns.get(columnConf));
}
}
if (!(columnComponent instanceof CheckBox)) {
// todo get rid of concrete CheckBox class !
columnComponent.setWidthFull();
}
if (columnComponent instanceof BelongToFrame) {
BelongToFrame belongToFrame = (BelongToFrame) columnComponent;
if (belongToFrame.getFrame() == null) {
belongToFrame.setFrame(webTable.getFrame());
}
}
applyPermissions(columnComponent);
columnComponent.setParent(webTable);
Component componentImpl = getComponentImplementation(columnComponent);
if (componentImpl instanceof com.vaadin.v7.ui.Field) {
return (com.vaadin.v7.ui.Field<?>) componentImpl;
}
return new EditableColumnFieldWrapper(componentImpl, columnComponent);
}
use of io.jmix.ui.component.data.value.ContainerValueSource in project jmix by jmix-framework.
the class WebTokenList method getViewForField.
/**
* If the value for a component is selected from the lookup screen there may be cases when lookup screen contains a list of entities loaded with a
* view that doesn't contain all attributes, required by the token list.
* <p>
* The method evaluates the view that was is for loading entities in the token list
*
* @return a view or null if the view cannot be evaluated
*/
@Nullable
protected FetchPlan getViewForField() {
ValueSource valueSource = getValueSource();
if (valueSource instanceof ContainerValueSource) {
ContainerValueSource containerValueSource = (ContainerValueSource) valueSource;
InstanceContainer container = containerValueSource.getContainer();
FetchPlan view = container.getFetchPlan();
if (view != null) {
MetaPropertyPath metaPropertyPath = containerValueSource.getMetaPropertyPath();
FetchPlan curView = view;
if (metaPropertyPath != null) {
for (MetaProperty metaProperty : metaPropertyPath.getMetaProperties()) {
FetchPlanProperty viewProperty = curView.getProperty(metaProperty.getName());
if (viewProperty != null) {
curView = viewProperty.getFetchPlan();
if (curView == null)
return null;
}
}
MetaProperty inverseMetaProperty = metaPropertyPath.getMetaProperty().getInverse();
if (inverseMetaProperty != null && !inverseMetaProperty.getRange().getCardinality().isMany()) {
curView = fetchPlans.builder(curView).add(inverseMetaProperty.getName()).build();
}
}
if (curView != view) {
return curView;
}
}
}
return null;
}
use of io.jmix.ui.component.data.value.ContainerValueSource in project jmix by jmix-framework.
the class WebTokenList method updateMasterRefIfOptionsRefreshed.
/**
* Sets master-entity reference to the value and remove master-entity reference
* from options if they are not in nested container.
*
* @param value value items
*/
protected void updateMasterRefIfOptionsRefreshed(Collection<V> value) {
if (!isRefreshOptionsEnabled()) {
return;
}
if (!(getValueSource() instanceof ContainerValueSource)) {
return;
}
EntityOptions<V> options = (EntityOptions<V>) getOptions();
if (options == null) {
return;
}
ContainerValueSource valueSource = (ContainerValueSource) getValueSource();
MetaPropertyPath mpp = valueSource.getMetaPropertyPath();
MetaProperty inverseProperty = mpp.getMetaProperty().getInverse();
Object masterEntity = valueSource.getItem();
if (inverseProperty == null || masterEntity == null) {
return;
}
List<V> optionItems = getOptions().getOptions().collect(Collectors.toList());
for (V option : optionItems) {
// skip all options that did not load master-reference
if (!entityStates.isLoaded(option, inverseProperty.getName())) {
continue;
}
if (value.contains(option)) {
// reset master-entity reference
EntityValues.setValue(option, inverseProperty.getName(), masterEntity);
} else {
Entity ref = EntityValues.getValue(option, inverseProperty.getName());
if (ref == null) {
continue;
}
// remove ref to the master entity if option is not in value
if (Objects.equals(EntityValues.getId(ref), EntityValues.getId(masterEntity))) {
EntityValues.setValue(option, inverseProperty.getName(), null);
}
}
}
}
use of io.jmix.ui.component.data.value.ContainerValueSource in project jmix by jmix-framework.
the class LookupBuilderProcessor method getFetchPlanForField.
/**
* The method evaluates the fetch plan that is used for the entity in the given {@code field}
* <p>
* If the value for a component (e.g. {@link EntityPicker}) is selected from lookup screen then there may be cases
* when in entities in lookup screen some attributes required in the editor are not loaded.
*
* @return a view or {@code null} if the fetch plan cannot be evaluated
*/
@Nullable
protected FetchPlan getFetchPlanForField(HasValue field) {
if (field instanceof HasValueSource) {
ValueSource valueSource = ((HasValueSource) field).getValueSource();
if (valueSource instanceof ContainerValueSource) {
ContainerValueSource containerValueSource = (ContainerValueSource) valueSource;
InstanceContainer container = containerValueSource.getContainer();
FetchPlan fetchPlan = container.getFetchPlan();
if (fetchPlan != null) {
MetaPropertyPath metaPropertyPath = containerValueSource.getMetaPropertyPath();
FetchPlan curFetchPlan = fetchPlan;
for (MetaProperty metaProperty : metaPropertyPath.getMetaProperties()) {
FetchPlanProperty viewProperty = curFetchPlan.getProperty(metaProperty.getName());
if (viewProperty != null) {
curFetchPlan = viewProperty.getFetchPlan();
}
if (curFetchPlan == null)
break;
}
if (curFetchPlan != fetchPlan) {
return curFetchPlan;
}
}
}
}
return null;
}
Aggregations