Search in sources :

Example 1 with ContainerValueSource

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;
    }
}
Also used : ContainerValueSource(io.jmix.ui.component.data.value.ContainerValueSource) LookupAction(com.haulmont.cuba.gui.actions.picker.LookupAction) ClearAction(com.haulmont.cuba.gui.actions.picker.ClearAction)

Example 2 with ContainerValueSource

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);
}
Also used : AbstractTable(io.jmix.ui.component.impl.AbstractTable) BelongToFrame(io.jmix.ui.component.Component.BelongToFrame) InstanceContainer(io.jmix.ui.model.InstanceContainer) ContainerValueSource(io.jmix.ui.component.data.value.ContainerValueSource) io.jmix.ui.component(io.jmix.ui.component) Component(com.vaadin.ui.Component)

Example 3 with ContainerValueSource

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;
}
Also used : ContainerValueSource(io.jmix.ui.component.data.value.ContainerValueSource) ContainerValueSource(io.jmix.ui.component.data.value.ContainerValueSource) LegacyCollectionDsValueSource(com.haulmont.cuba.gui.components.data.value.LegacyCollectionDsValueSource) ValueSource(io.jmix.ui.component.data.ValueSource) EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) InstanceContainer(io.jmix.ui.model.InstanceContainer) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) Nullable(javax.annotation.Nullable)

Example 4 with ContainerValueSource

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);
            }
        }
    }
}
Also used : ContainerValueSource(io.jmix.ui.component.data.value.ContainerValueSource) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) ListEntityOptions(io.jmix.ui.component.data.options.ListEntityOptions) EntityOptions(io.jmix.ui.component.data.meta.EntityOptions) MapEntityOptions(io.jmix.ui.component.data.options.MapEntityOptions)

Example 5 with ContainerValueSource

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;
}
Also used : ContainerValueSource(io.jmix.ui.component.data.value.ContainerValueSource) ContainerValueSource(io.jmix.ui.component.data.value.ContainerValueSource) ValueSource(io.jmix.ui.component.data.ValueSource) HasValueSource(io.jmix.ui.component.data.HasValueSource) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) InstanceContainer(io.jmix.ui.model.InstanceContainer) HasValueSource(io.jmix.ui.component.data.HasValueSource) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) Nullable(javax.annotation.Nullable)

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