use of io.jmix.ui.component.data.value.ContainerValueSource in project jmix by jmix-framework.
the class AttributeRecalculationListener method accept.
@Override
public void accept(HasValue.ValueChangeEvent valueChangeEvent) {
if (Boolean.TRUE.equals(recalculationInProgress.get())) {
return;
}
try {
recalculationInProgress.set(true);
Component component = valueChangeEvent.getComponent();
if (component instanceof HasValueSource && ((HasValueSource<?>) component).getValueSource() instanceof ContainerValueSource) {
ContainerValueSource<?, ?> valueSource = (ContainerValueSource<?, ?>) ((HasValueSource<?>) component).getValueSource();
InstanceContainer<?> container = valueSource.getContainer();
Object entity = container.getItem();
EntityValues.setValue(entity, DynAttrUtils.getPropertyFromAttributeCode(attribute.getCode()), valueChangeEvent.getValue());
recalculationManager.recalculateByAttribute(entity, attribute);
}
} finally {
recalculationInProgress.remove();
}
}
use of io.jmix.ui.component.data.value.ContainerValueSource in project jmix by jmix-framework.
the class DynAttrComponentGenerationStrategy method createCollectionField.
protected Component createCollectionField(ComponentGenerationContext context, AttributeDefinition attribute) {
ValuesPicker valuesPicker = uiComponents.create(ValuesPicker.NAME);
setValidators(valuesPicker, attribute);
setValueSource(valuesPicker, context);
ValuesSelectAction selectAction = actions.create(ValuesSelectAction.class);
initValuesSelectActionByAttribute(selectAction, attribute);
if (valuesPicker.getValueSource() instanceof ContainerValueSource && attribute.getConfiguration().isLookup()) {
ContainerValueSource valueSource = (ContainerValueSource) valuesPicker.getValueSource();
setValuesPickerOptionsLoader(valuesPicker, attribute, valueSource);
}
valuesPicker.addAction(selectAction);
ValueClearAction valueClearAction = actions.create(ValueClearAction.class);
valuesPicker.addAction(valueClearAction);
return valuesPicker;
}
use of io.jmix.ui.component.data.value.ContainerValueSource in project jmix by jmix-framework.
the class ImapEventHandlersFragment method handlersTableMethodNameColumnGenerator.
@Install(to = "handlersTable.methodName", subject = "columnGenerator")
protected ComboBox<String> handlersTableMethodNameColumnGenerator(ImapEventHandler eventHandler) {
ComboBox<String> comboBox = handlerMethodComboBoxFields.get(eventHandler);
comboBox = comboBox != null ? comboBox : makeBeanMethodLookup(availableHandlers, eventHandler);
comboBox.setValueSource(new ContainerValueSource(handlersTable.getInstanceContainer(eventHandler), "methodName"));
comboBox.setOptionsList(methodNames(availableHandlers, eventHandler.getBeanName()));
return comboBox;
}
use of io.jmix.ui.component.data.value.ContainerValueSource in project jmix by jmix-framework.
the class ImapEventHandlersFragment method makeBeanMethodLookup.
protected ComboBox makeBeanMethodLookup(Map<String, List<String>> availableBeans, ImapEventHandler eventHandler) {
ComboBox<String> lookup = componentsFactory.create(ComboBox.class);
lookup.setValueSource(new ContainerValueSource(handlersTable.getInstanceContainer(eventHandler), "methodName"));
lookup.setWidth("250px");
String beanName = eventHandler.getBeanName();
lookup.setFrame(getHostScreen().getWindow());
lookup.setOptionsList(methodNames(availableBeans, beanName));
return lookup;
}
use of io.jmix.ui.component.data.value.ContainerValueSource in project jmix by jmix-framework.
the class AppSettingsGridLayoutBuilder method addRowToGrid.
protected void addRowToGrid(InstanceContainer container, GridLayout gridLayout, int currentRow, MetaProperty metaProperty) {
MetaClass metaClass = container.getEntityMetaClass();
Range range = metaProperty.getRange();
UiEntityAttributeContext attributeContext = new UiEntityAttributeContext(metaClass, metaProperty.getName());
accessManager.applyRegisteredConstraints(attributeContext);
if (!attributeContext.canView()) {
return;
}
if (range.isClass()) {
UiEntityContext entityContext = new UiEntityContext(range.asClass());
accessManager.applyRegisteredConstraints(entityContext);
if (!entityContext.isViewPermitted()) {
return;
}
}
// add label
Label fieldLabel = uiComponents.create(Label.class);
fieldLabel.setValue(getPropertyCaption(metaClass, metaProperty));
fieldLabel.setAlignment(io.jmix.ui.component.Component.Alignment.MIDDLE_LEFT);
gridLayout.add(fieldLabel, 0, currentRow + 1);
// current field
ValueSource valueSource = new ContainerValueSource<>(container, metaProperty.getName());
ComponentGenerationContext componentContext = new ComponentGenerationContext(metaClass, metaProperty.getName());
componentContext.setValueSource(valueSource);
gridLayout.add(createField(metaProperty, range, componentContext), 1, currentRow + 1);
// default value
ComponentGenerationContext componentContextForDefaultField = new ComponentGenerationContext(metaClass, metaProperty.getName());
ValueSource valueSourceForDefaultField = new ContainerValueSource<>(dataComponents.createInstanceContainer(metaClass.getJavaClass()), metaProperty.getName());
componentContextForDefaultField.setValueSource(valueSourceForDefaultField);
Field defaultValueField = createField(metaProperty, range, componentContextForDefaultField);
defaultValueField.setValue(appSettingsTools.getDefaultPropertyValue(metaClass.getJavaClass(), metaProperty.getName()));
defaultValueField.setEditable(false);
gridLayout.add(defaultValueField, 2, currentRow + 1);
}
Aggregations