Search in sources :

Example 6 with ContainerValueSource

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

the class ImapEventHandlersFragment method handlersTableBeanNameColumnGenerator.

@Install(to = "handlersTable.beanName", subject = "columnGenerator")
protected ComboBox<String> handlersTableBeanNameColumnGenerator(ImapEventHandler eventHandler) {
    ComboBox<String> comboBox = componentsFactory.create(ComboBox.class);
    comboBox.setValueSource(new ContainerValueSource(handlersTable.getInstanceContainer(eventHandler), "beanName"));
    comboBox.setWidth("250px");
    comboBox.setOptionsList(new ArrayList<>(availableHandlers.keySet()));
    return comboBox;
}
Also used : ContainerValueSource(io.jmix.ui.component.data.value.ContainerValueSource)

Example 7 with ContainerValueSource

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

the class ImapMailBoxEdit method foldersTableEnabledColumnGenerator.

@Install(to = "foldersTable.enabled", subject = "columnGenerator")
public CheckBox foldersTableEnabledColumnGenerator(ImapFolder folder) {
    CheckBox checkBox = componentsFactory.create(CheckBox.class);
    checkBox.setValueSource(new ContainerValueSource(foldersTable.getInstanceContainer(folder), "enabled"));
    checkBox.setEditable(Boolean.TRUE.equals(folder.getCanHoldMessages() && !Boolean.TRUE.equals(folder.getDeleted())));
    checkBox.setFrame(getWindow().getFrame());
    checkBox.setWidth("20");
    return checkBox;
}
Also used : ContainerValueSource(io.jmix.ui.component.data.value.ContainerValueSource)

Example 8 with ContainerValueSource

use of io.jmix.ui.component.data.value.ContainerValueSource 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 9 with ContainerValueSource

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

the class DynAttrComponentGenerationStrategy method createEntityField.

protected EntityPicker createEntityField(ComponentGenerationContext context, AttributeDefinition attribute) {
    if (attribute.getConfiguration().isLookup()) {
        EntityComboBox entityComboBox = uiComponents.create(EntityComboBox.class);
        if (context.getValueSource() instanceof ContainerValueSource) {
            setComboBoxOptionsLoader(entityComboBox, attribute, (ContainerValueSource) context.getValueSource());
        }
        setValueSource(entityComboBox, context);
        setValidators(entityComboBox, attribute);
        return entityComboBox;
    } else {
        EntityPicker entityPicker = uiComponents.create(EntityPicker.class);
        EntityLookupAction lookupAction = actions.create(EntityLookupAction.class);
        setLookupActionScreen(lookupAction, attribute);
        entityPicker.addAction(lookupAction);
        entityPicker.addAction(actions.create(EntityClearAction.class));
        setValueSource(entityPicker, context);
        setValidators(entityPicker, attribute);
        return entityPicker;
    }
}
Also used : ContainerValueSource(io.jmix.ui.component.data.value.ContainerValueSource) EntityClearAction(io.jmix.ui.action.entitypicker.EntityClearAction) EntityLookupAction(io.jmix.ui.action.entitypicker.EntityLookupAction)

Example 10 with ContainerValueSource

use of io.jmix.ui.component.data.value.ContainerValueSource 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)

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