Search in sources :

Example 1 with InstanceContainer

use of io.jmix.ui.model.InstanceContainer 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 2 with InstanceContainer

use of io.jmix.ui.model.InstanceContainer in project jmix by jmix-framework.

the class TableFieldFactoryImpl method findOptionsContainer.

@Nullable
protected CollectionContainer findOptionsContainer(Table.Column columnConf) {
    String optDcName = columnConf.getXmlDescriptor() != null ? columnConf.getXmlDescriptor().attributeValue("optionsContainer") : null;
    if (Strings.isNullOrEmpty(optDcName)) {
        return null;
    } else {
        ScreenData screenData = UiControllerUtils.getScreenData(webTable.getFrame().getFrameOwner());
        InstanceContainer container = screenData.getContainer(optDcName);
        if (container instanceof CollectionContainer) {
            return (CollectionContainer) container;
        }
        throw new IllegalStateException(String.format("'%s' is not an instance of CollectionContainer", optDcName));
    }
}
Also used : InstanceContainer(io.jmix.ui.model.InstanceContainer) CollectionContainer(io.jmix.ui.model.CollectionContainer) ScreenData(io.jmix.ui.model.ScreenData) Nullable(javax.annotation.Nullable)

Example 3 with InstanceContainer

use of io.jmix.ui.model.InstanceContainer in project jmix by jmix-framework.

the class AbstractComponentLoader method loadOptionsContainer.

protected Optional<CollectionContainer> loadOptionsContainer(Element element) {
    String containerId = element.attributeValue("optionsContainer");
    if (containerId != null) {
        FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
        ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
        InstanceContainer container = screenData.getContainer(containerId);
        if (!(container instanceof CollectionContainer)) {
            throw new GuiDevelopmentException("Not a CollectionContainer: " + containerId, context);
        }
        return Optional.of((CollectionContainer) container);
    }
    return Optional.empty();
}
Also used : FrameOwner(io.jmix.ui.screen.FrameOwner) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) InstanceContainer(io.jmix.ui.model.InstanceContainer) CollectionContainer(io.jmix.ui.model.CollectionContainer) ScreenData(io.jmix.ui.model.ScreenData)

Example 4 with InstanceContainer

use of io.jmix.ui.model.InstanceContainer 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 5 with InstanceContainer

use of io.jmix.ui.model.InstanceContainer in project jmix by jmix-framework.

the class WebTreeTable method clearFieldDatasources.

@Override
protected void clearFieldDatasources() {
    if (fieldDatasources == null) {
        return;
    }
    // detach instance containers from entities explicitly
    for (Map.Entry<Object, Object> entry : fieldDatasources.entrySet()) {
        if (entry.getValue() instanceof InstanceContainer) {
            InstanceContainer container = (InstanceContainer) entry.getValue();
            container.setItem(null);
        } else if (entry.getValue() instanceof Datasource) {
            Datasource datasource = (Datasource) entry.getValue();
            datasource.setItem(null);
        }
    }
    fieldDatasources.clear();
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) InstanceContainer(io.jmix.ui.model.InstanceContainer) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap)

Aggregations

InstanceContainer (io.jmix.ui.model.InstanceContainer)30 ScreenData (io.jmix.ui.model.ScreenData)12 GuiDevelopmentException (io.jmix.ui.GuiDevelopmentException)11 CollectionContainer (io.jmix.ui.model.CollectionContainer)11 FrameOwner (io.jmix.ui.screen.FrameOwner)11 MetaClass (io.jmix.core.metamodel.model.MetaClass)6 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)6 Nullable (javax.annotation.Nullable)5 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)3 Datasource (com.haulmont.cuba.gui.data.Datasource)3 ContainerOptions (io.jmix.ui.component.data.options.ContainerOptions)3 ContainerValueSource (io.jmix.ui.component.data.value.ContainerValueSource)3 ContainerDataProvider (io.jmix.ui.data.impl.ContainerDataProvider)3 Nested (io.jmix.ui.model.Nested)3 Map (java.util.Map)3 WeakHashMap (java.util.WeakHashMap)3 KeyValueMetaClass (io.jmix.core.impl.keyvalue.KeyValueMetaClass)2 MetaPropertyPath (io.jmix.core.metamodel.model.MetaPropertyPath)2 ValueSource (io.jmix.ui.component.data.ValueSource)2 DataContext (io.jmix.ui.model.DataContext)2