Search in sources :

Example 11 with InstanceContainer

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

the class AbstractTable method clearFieldDatasources.

@SuppressWarnings("unchecked")
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);
        }
    }
    fieldDatasources.clear();
}
Also used : InstanceContainer(io.jmix.ui.model.InstanceContainer)

Example 12 with InstanceContainer

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

the class DataLoadCoordinatorImpl method configureAutomatically.

private void configureAutomatically(DataLoader loader, FrameOwner frameOwner) {
    List<String> queryParameters = DataLoadersHelper.getQueryParameters(loader);
    List<String> allParameters = new ArrayList<>(queryParameters);
    allParameters.addAll(getConditionParameters(loader));
    // add triggers on container/component events
    for (String parameter : allParameters) {
        if (parameter.startsWith(containerPrefix)) {
            InstanceContainer container = UiControllerUtils.getScreenData(frameOwner).getContainer(parameter.substring(containerPrefix.length()));
            addOnContainerItemChangedLoadTrigger(loader, container, parameter);
        } else if (parameter.startsWith(componentPrefix)) {
            String componentId = parameter.substring(componentPrefix.length());
            Component component = frameOwner instanceof Screen ? ((Screen) frameOwner).getWindow().getComponentNN(componentId) : ((ScreenFragment) frameOwner).getFragment().getComponentNN(componentId);
            LikeClause likeClause = findLikeClause(loader, parameter);
            addOnComponentValueChangedLoadTrigger(loader, component, parameter, likeClause);
        }
    }
    // if the loader has no parameters in query, add trigger on BeforeShowEvent/AttachEvent
    if (queryParameters.isEmpty()) {
        Class eventClass = frameOwner instanceof Screen ? Screen.BeforeShowEvent.class : ScreenFragment.AttachEvent.class;
        addOnFrameOwnerEventLoadTrigger(loader, eventClass);
    }
}
Also used : ScreenFragment(io.jmix.ui.screen.ScreenFragment) Screen(io.jmix.ui.screen.Screen) ArrayList(java.util.ArrayList) InstanceContainer(io.jmix.ui.model.InstanceContainer) Component(io.jmix.ui.component.Component)

Example 13 with InstanceContainer

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

the class StockChartLoader method loadDataSet.

protected void loadDataSet(DataSet dataSet, Element dataSetElement) {
    loadFieldMappings(dataSet, dataSetElement);
    loadStockEvents(dataSet, dataSetElement);
    String id = dataSetElement.attributeValue("id");
    if (StringUtils.isNotEmpty(id)) {
        dataSet.setId(id);
    }
    checkMultipleDatasources(dataSetElement);
    String categoryField = dataSetElement.attributeValue("categoryField");
    if (StringUtils.isNotEmpty(categoryField)) {
        dataSet.setCategoryField(categoryField);
    }
    String color = dataSetElement.attributeValue("color");
    if (StringUtils.isNotEmpty(color)) {
        dataSet.setColor(Color.valueOf(color));
    }
    String compared = dataSetElement.attributeValue("compared");
    if (StringUtils.isNotEmpty(compared)) {
        dataSet.setCompared(Boolean.valueOf(compared));
    }
    String dataContainerId = dataSetElement.attributeValue("dataContainer");
    if (StringUtils.isNotEmpty(dataContainerId)) {
        FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
        ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
        CollectionContainer dataContainer;
        InstanceContainer container = screenData.getContainer(dataContainerId);
        if (container instanceof CollectionContainer) {
            dataContainer = (CollectionContainer) container;
        } else {
            throw new GuiDevelopmentException("Not a CollectionContainer: " + dataContainerId, context);
        }
        dataSet.setDataProvider(new ContainerDataProvider(dataContainer));
    }
    String showInCompare = dataSetElement.attributeValue("showInCompare");
    if (StringUtils.isNotEmpty(showInCompare)) {
        dataSet.setShowInCompare(Boolean.valueOf(showInCompare));
    }
    String showInSelect = dataSetElement.attributeValue("showInSelect");
    if (StringUtils.isNotEmpty(showInSelect)) {
        dataSet.setShowInSelect(Boolean.valueOf(showInSelect));
    }
    String title = dataSetElement.attributeValue("title");
    if (StringUtils.isNotEmpty(title)) {
        dataSet.setTitle(title);
    }
}
Also used : FrameOwner(io.jmix.ui.screen.FrameOwner) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) CollectionContainer(io.jmix.ui.model.CollectionContainer) InstanceContainer(io.jmix.ui.model.InstanceContainer) ContainerDataProvider(io.jmix.ui.data.impl.ContainerDataProvider) ScreenData(io.jmix.ui.model.ScreenData)

Example 14 with InstanceContainer

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

the class ViewAction method isReadOnlyCompositionEditor.

/**
 * In case of composition relation, editor for nested entities should be in read-only mode with hidden
 * "enableEditing" action if master editor is in read-only mode too.
 *
 * @param editor editor to check
 * @return {@code true} if the relation between entities is a composition
 */
protected boolean isReadOnlyCompositionEditor(Screen editor) {
    Frame frame = target.getFrame();
    if (frame == null) {
        throw new IllegalStateException("Component is not attached to the Frame");
    }
    FrameOwner origin = target.getFrame().getFrameOwner();
    if (!(origin instanceof ReadOnlyAwareScreen) || !((ReadOnlyAwareScreen) origin).isReadOnly() || !(editor instanceof StandardEditor)) {
        return false;
    }
    DataUnit items = target.getItems();
    if (!(items instanceof ContainerDataUnit)) {
        return false;
    }
    CollectionContainer container = ((ContainerDataUnit) target.getItems()).getContainer();
    if (!(container instanceof CollectionPropertyContainer)) {
        return false;
    }
    InstanceContainer masterContainer = ((CollectionPropertyContainer) container).getMaster();
    String property = ((CollectionPropertyContainer) container).getProperty();
    MetaClass metaClass = masterContainer.getEntityMetaClass();
    MetaProperty metaProperty = metaClass.getProperty(property);
    return metaProperty.getType() == MetaProperty.Type.COMPOSITION;
}
Also used : Frame(io.jmix.ui.component.Frame) CollectionContainer(io.jmix.ui.model.CollectionContainer) InstanceContainer(io.jmix.ui.model.InstanceContainer) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit) DataUnit(io.jmix.ui.component.data.DataUnit) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit) MetaClass(io.jmix.core.metamodel.model.MetaClass) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) CollectionPropertyContainer(io.jmix.ui.model.CollectionPropertyContainer)

Example 15 with InstanceContainer

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

the class FormLoader method loadDataContainer.

protected void loadDataContainer(Form resultComponent, Element element) {
    String containerId = element.attributeValue("dataContainer");
    if (!Strings.isNullOrEmpty(containerId)) {
        FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
        ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
        InstanceContainer container = screenData.getContainer(containerId);
        // noinspection unchecked
        resultComponent.setValueSourceProvider(new ContainerValueSourceProvider(container));
    }
}
Also used : ContainerValueSourceProvider(io.jmix.ui.component.data.value.ContainerValueSourceProvider) FrameOwner(io.jmix.ui.screen.FrameOwner) InstanceContainer(io.jmix.ui.model.InstanceContainer) ScreenData(io.jmix.ui.model.ScreenData)

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