Search in sources :

Example 11 with ContainerValueSource

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();
    }
}
Also used : ContainerValueSource(io.jmix.ui.component.data.value.ContainerValueSource) Component(io.jmix.ui.component.Component) HasValueSource(io.jmix.ui.component.data.HasValueSource)

Example 12 with ContainerValueSource

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;
}
Also used : ContainerValueSource(io.jmix.ui.component.data.value.ContainerValueSource) ValuesSelectAction(io.jmix.ui.action.valuespicker.ValuesSelectAction) ValueClearAction(io.jmix.ui.action.valuepicker.ValueClearAction)

Example 13 with ContainerValueSource

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;
}
Also used : ContainerValueSource(io.jmix.ui.component.data.value.ContainerValueSource)

Example 14 with ContainerValueSource

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;
}
Also used : ContainerValueSource(io.jmix.ui.component.data.value.ContainerValueSource)

Example 15 with ContainerValueSource

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);
}
Also used : UiEntityContext(io.jmix.ui.accesscontext.UiEntityContext) ContainerValueSource(io.jmix.ui.component.data.value.ContainerValueSource) MetaClass(io.jmix.core.metamodel.model.MetaClass) ContainerValueSource(io.jmix.ui.component.data.value.ContainerValueSource) ValueSource(io.jmix.ui.component.data.ValueSource) UiEntityAttributeContext(io.jmix.ui.accesscontext.UiEntityAttributeContext) Range(io.jmix.core.metamodel.model.Range)

Aggregations

ContainerValueSource (io.jmix.ui.component.data.value.ContainerValueSource)15 ValueSource (io.jmix.ui.component.data.ValueSource)5 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)4 MetaPropertyPath (io.jmix.core.metamodel.model.MetaPropertyPath)3 InstanceContainer (io.jmix.ui.model.InstanceContainer)3 MetaClass (io.jmix.core.metamodel.model.MetaClass)2 Range (io.jmix.core.metamodel.model.Range)2 UiEntityAttributeContext (io.jmix.ui.accesscontext.UiEntityAttributeContext)2 UiEntityContext (io.jmix.ui.accesscontext.UiEntityContext)2 EntityClearAction (io.jmix.ui.action.entitypicker.EntityClearAction)2 EntityLookupAction (io.jmix.ui.action.entitypicker.EntityLookupAction)2 HasValueSource (io.jmix.ui.component.data.HasValueSource)2 Nullable (javax.annotation.Nullable)2 ClearAction (com.haulmont.cuba.gui.actions.picker.ClearAction)1 LookupAction (com.haulmont.cuba.gui.actions.picker.LookupAction)1 LegacyCollectionDsValueSource (com.haulmont.cuba.gui.components.data.value.LegacyCollectionDsValueSource)1 Component (com.vaadin.ui.Component)1 ValueClearAction (io.jmix.ui.action.valuepicker.ValueClearAction)1 ValuesSelectAction (io.jmix.ui.action.valuespicker.ValuesSelectAction)1 io.jmix.ui.component (io.jmix.ui.component)1