Search in sources :

Example 6 with ValueSource

use of io.jmix.ui.component.data.ValueSource in project jmix by jmix-framework.

the class InspectorFormBuilder method addField.

/**
 * Adds field to the specified form.
 * If the field should be custom, adds it to the specified customFields collection
 * which can be used later to create fieldGenerators
 *
 * @param metaProperty meta property of the item's property which field is creating
 * @param form         field group to which created field will be added
 */
protected void addField(InstanceContainer container, Form form, MetaProperty metaProperty, boolean isReadonly) {
    MetaClass metaClass = container.getEntityMetaClass();
    Range range = metaProperty.getRange();
    boolean isRequired = isRequired(metaProperty);
    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;
        }
    }
    ValueSource valueSource = new ContainerValueSource<>(container, metaProperty.getName());
    ComponentGenerationContext componentContext = new ComponentGenerationContext(metaClass, metaProperty.getName());
    componentContext.setValueSource(valueSource);
    Field field = (Field) uiComponentsGenerator.generate(componentContext);
    if (requireTextArea(metaProperty, getItem(), MAX_TEXTFIELD_STRING_LENGTH)) {
        field = uiComponents.create(TextArea.NAME);
    }
    if (isBoolean(metaProperty)) {
        field = createBooleanField();
    }
    if (range.isClass()) {
        EntityPicker pickerField = uiComponents.create(EntityPicker.class);
        EntityLookupAction lookupAction = actions.create(EntityLookupAction.class);
        lookupAction.setScreenClass(EntityInspectorBrowser.class);
        lookupAction.setScreenOptionsSupplier(() -> new MapScreenOptions(ParamsMap.of("entity", metaProperty.getRange().asClass().getName())));
        lookupAction.setOpenMode(OpenMode.THIS_TAB);
        pickerField.addAction(lookupAction);
        pickerField.addAction(actions.create(EntityClearAction.class));
        field = pickerField;
    }
    field.setValueSource(valueSource);
    field.setCaption(getPropertyCaption(metaClass, metaProperty));
    field.setRequired(isRequired);
    isReadonly = isReadonly || (disabledProperties != null && disabledProperties.contains(metaProperty.getName()));
    if (range.isClass() && !metadataTools.isEmbedded(metaProperty)) {
        field.setEditable(metadataTools.isOwningSide(metaProperty) && !isReadonly);
    } else {
        field.setEditable(!isReadonly);
    }
    field.setWidth(fieldWidth);
    if (isRequired) {
        field.setRequiredMessage(messageTools.getDefaultRequiredMessage(metaClass, metaProperty.getName()));
    }
    form.add(field);
}
Also used : UiEntityContext(io.jmix.ui.accesscontext.UiEntityContext) UiEntityAttributeContext(io.jmix.ui.accesscontext.UiEntityAttributeContext) Range(io.jmix.core.metamodel.model.Range) ContainerValueSource(io.jmix.ui.component.data.value.ContainerValueSource) EntityClearAction(io.jmix.ui.action.entitypicker.EntityClearAction) MetaClass(io.jmix.core.metamodel.model.MetaClass) ContainerValueSource(io.jmix.ui.component.data.value.ContainerValueSource) ValueSource(io.jmix.ui.component.data.ValueSource) EntityLookupAction(io.jmix.ui.action.entitypicker.EntityLookupAction) MapScreenOptions(io.jmix.ui.screen.MapScreenOptions)

Example 7 with ValueSource

use of io.jmix.ui.component.data.ValueSource in project jmix by jmix-framework.

the class DynamicAttributesPanel method generateFieldComponent.

protected Component generateFieldComponent(AttributeDefinition attribute) {
    MetaProperty metaProperty = attribute.getMetaProperty();
    ValueSource valueSource = new ContainerValueSource<>(instanceContainer, metaProperty.getName());
    ComponentGenerationContext componentContext = new ComponentGenerationContext(instanceContainer.getEntityMetaClass(), metaProperty.getName());
    componentContext.setValueSource(valueSource);
    Component resultComponent = uiComponentsGenerator.generate(componentContext);
    setWidth(resultComponent, attribute);
    return resultComponent;
}
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) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) StudioComponent(io.jmix.ui.meta.StudioComponent)

Example 8 with ValueSource

use of io.jmix.ui.component.data.ValueSource in project jmix by jmix-framework.

the class GuiActionSupport method createActionsByMetaAnnotations.

public boolean createActionsByMetaAnnotations(PickerField pickerField) {
    ValueSource valueSource = pickerField.getValueSource();
    if (!(valueSource instanceof EntityValueSource)) {
        return false;
    }
    EntityValueSource entityValueSource = (EntityValueSource) pickerField.getValueSource();
    MetaPropertyPath mpp = entityValueSource.getMetaPropertyPath();
    if (mpp == null) {
        return false;
    }
    String[] actionIds = (String[]) metadataTools.getMetaAnnotationAttributes(mpp.getMetaProperty().getAnnotations(), Lookup.class).get("actions");
    if (actionIds != null && actionIds.length > 0) {
        for (String actionId : actionIds) {
            createActionById(pickerField, actionId);
        }
        return true;
    }
    return false;
}
Also used : EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) DatasourceValueSource(com.haulmont.cuba.gui.components.data.value.DatasourceValueSource) ValueSource(io.jmix.ui.component.data.ValueSource) EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath)

Example 9 with ValueSource

use of io.jmix.ui.component.data.ValueSource in project jmix by jmix-framework.

the class DatePickerLoader method getJavaType.

protected Class getJavaType(DatePicker resultComponent) {
    ValueSource valueSource = resultComponent.getValueSource();
    if (valueSource instanceof EntityValueSource) {
        MetaProperty metaProperty = ((EntityValueSource) valueSource).getMetaPropertyPath().getMetaProperty();
        return metaProperty.getRange().asDatatype().getJavaClass();
    }
    Datatype datatype = resultComponent.getDatatype();
    return datatype == null ? Date.class : datatype.getJavaClass();
}
Also used : EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) ValueSource(io.jmix.ui.component.data.ValueSource) EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) Datatype(io.jmix.core.metamodel.datatype.Datatype)

Example 10 with ValueSource

use of io.jmix.ui.component.data.ValueSource in project jmix-docs by jmix-framework.

the class ColorComponentGenerationStrategy method createComponent.

@Nullable
@Override
public Component createComponent(ComponentGenerationContext context) {
    String property = context.getProperty();
    MetaPropertyPath mpp = context.getMetaClass().getPropertyPath(property);
    if (mpp != null) {
        Range mppRange = mpp.getRange();
        if (mppRange.isDatatype() && (Datatype) mppRange.asDatatype() instanceof ColorDatatype) {
            ColorPicker colorPicker = uiComponents.create(ColorPicker.class);
            colorPicker.setDefaultCaptionEnabled(true);
            ValueSource valueSource = context.getValueSource();
            if (valueSource != null) {
                colorPicker.setValueSource(valueSource);
            }
            return colorPicker;
        }
    }
    return null;
}
Also used : ColorPicker(io.jmix.ui.component.ColorPicker) ValueSource(io.jmix.ui.component.data.ValueSource) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) Range(io.jmix.core.metamodel.model.Range) Datatype(io.jmix.core.metamodel.datatype.Datatype) Nullable(javax.annotation.Nullable)

Aggregations

ValueSource (io.jmix.ui.component.data.ValueSource)18 EntityValueSource (io.jmix.ui.component.data.meta.EntityValueSource)10 Nullable (javax.annotation.Nullable)8 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)7 MetaPropertyPath (io.jmix.core.metamodel.model.MetaPropertyPath)7 Datatype (io.jmix.core.metamodel.datatype.Datatype)5 MetaClass (io.jmix.core.metamodel.model.MetaClass)5 ContainerValueSource (io.jmix.ui.component.data.value.ContainerValueSource)5 Range (io.jmix.core.metamodel.model.Range)4 HasValueSource (io.jmix.ui.component.data.HasValueSource)4 UiEntityAttributeContext (io.jmix.ui.accesscontext.UiEntityAttributeContext)3 UiEntityContext (io.jmix.ui.accesscontext.UiEntityContext)2 io.jmix.ui.component (io.jmix.ui.component)2 ColorPicker (io.jmix.ui.component.ColorPicker)2 DataContext (io.jmix.ui.model.DataContext)2 InstanceContainer (io.jmix.ui.model.InstanceContainer)2 DatasourceValueSource (com.haulmont.cuba.gui.components.data.value.DatasourceValueSource)1 LegacyCollectionDsValueSource (com.haulmont.cuba.gui.components.data.value.LegacyCollectionDsValueSource)1 HasValue (com.vaadin.data.HasValue)1 ErrorMessage (com.vaadin.server.ErrorMessage)1