use of com.haulmont.cuba.gui.components.data.value.ContainerValueSource in project cuba by cuba-platform.
the class LookupBuilderProcessor method getViewForField.
/**
* If the value for a component (e.g. {@link com.haulmont.cuba.gui.components.PickerField}) 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.
* <p>
* The method evaluates the view that is used for the entity in the given {@code field}
*
* @return a view or null if the view cannot be evaluated
*/
@Nullable
protected <E extends Entity> View getViewForField(HasValue<E> field) {
if (field instanceof HasValueSource) {
ValueSource valueSource = ((HasValueSource) field).getValueSource();
if (valueSource instanceof ContainerValueSource) {
ContainerValueSource containerValueSource = (ContainerValueSource) valueSource;
InstanceContainer<E> container = containerValueSource.getContainer();
View view = container.getView();
if (view != null) {
MetaPropertyPath metaPropertyPath = containerValueSource.getMetaPropertyPath();
View curView = view;
for (MetaProperty metaProperty : metaPropertyPath.getMetaProperties()) {
ViewProperty viewProperty = curView.getProperty(metaProperty.getName());
if (viewProperty != null) {
curView = viewProperty.getView();
}
if (curView == null)
break;
}
if (curView != view) {
return curView;
}
}
}
}
return null;
}
use of com.haulmont.cuba.gui.components.data.value.ContainerValueSource in project cuba by cuba-platform.
the class AbstractComponentGenerationStrategy method createLookupField.
protected Component createLookupField(ComponentGenerationContext context, CategoryAttribute categoryAttribute) {
LookupField lookupField = uiComponents.create(LookupField.class);
ValueSource valueSource = context.getValueSource();
if (valueSource instanceof ContainerValueSource) {
setOptionsLoader(categoryAttribute, lookupField, (ContainerValueSource) valueSource);
}
setValueSource(lookupField, context);
setValidators(lookupField, context);
return lookupField;
}
use of com.haulmont.cuba.gui.components.data.value.ContainerValueSource in project cuba by cuba-platform.
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();
Entity 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
option.setValue(inverseProperty.getName(), masterEntity);
} else {
Entity ref = option.getValue(inverseProperty.getName());
if (ref == null) {
continue;
}
// remove ref to the master entity if option is not in value
if (Objects.equals(ref.getId(), masterEntity.getId())) {
option.setValue(inverseProperty.getName(), null);
}
}
}
}
use of com.haulmont.cuba.gui.components.data.value.ContainerValueSource in project cuba by cuba-platform.
the class DynamicAttributesPanel method generateFieldComponent.
protected Component generateFieldComponent(DynamicAttributesMetaProperty property) {
CategoryAttribute attribute = property.getAttribute();
ValueSource valueSource = new ContainerValueSource<>(instanceContainer, property.getName());
ComponentGenerationContext componentGenerationContext = new ComponentGenerationContext(instanceContainer.getEntityMetaClass(), property.getName());
componentGenerationContext.setValueSource(valueSource);
Component formField;
if (Boolean.TRUE.equals(attribute.getIsCollection())) {
formField = dynamicAttributeComponentsGenerator.generateComponent(valueSource, attribute);
} else {
formField = uiComponentsGenerator.generate(componentGenerationContext);
}
return formField;
}
Aggregations