Search in sources :

Example 11 with ScreenData

use of io.jmix.ui.model.ScreenData in project jmix-docs by Haulmont.

the class DeclarativeLoaderParameters method onDeclarativeLoaderParametersInit.

@Subscribe
default void onDeclarativeLoaderParametersInit(Screen.InitEvent event) {
    // <1>
    Screen screen = event.getSource();
    // <2>
    ScreenData screenData = UiControllerUtils.getScreenData(screen);
    Set<DataLoader> loadersToLoadBeforeShow = new HashSet<>();
    for (String loaderId : screenData.getLoaderIds()) {
        DataLoader loader = screenData.getLoader(loaderId);
        String query = loader.getQuery();
        Matcher matcher = CONTAINER_REF_PATTERN.matcher(query);
        while (matcher.find()) {
            // <3>
            String paramName = matcher.group(1);
            String containerId = matcher.group(2);
            InstanceContainer<?> container = screenData.getContainer(containerId);
            container.addItemChangeListener(itemChangeEvent -> {
                // <4>
                // <5>
                loader.setParameter(paramName, itemChangeEvent.getItem());
                loader.load();
            });
            if (container instanceof HasLoader) {
                // <6>
                loadersToLoadBeforeShow.add(((HasLoader) container).getLoader());
            }
        }
    }
    DeclarativeLoaderParametersState state = // <7>
    new DeclarativeLoaderParametersState(loadersToLoadBeforeShow);
    Extensions.register(screen, DeclarativeLoaderParametersState.class, state);
}
Also used : DataLoader(io.jmix.ui.model.DataLoader) Matcher(java.util.regex.Matcher) Screen(io.jmix.ui.screen.Screen) HasLoader(io.jmix.ui.model.HasLoader) ScreenData(io.jmix.ui.model.ScreenData) HashSet(java.util.HashSet) Subscribe(io.jmix.ui.screen.Subscribe)

Example 12 with ScreenData

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

the class TokenListLoader method loadOptionsContainer.

protected void loadOptionsContainer(TokenList component, 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);
        }
        // noinspection unchecked
        component.setOptions(new ContainerOptions((CollectionContainer) container));
    }
    if (component.getOptions() == null) {
        DatasourceLoaderHelper.loadOptionsDatasource(element, (ComponentLoaderContext) getComponentContext()).ifPresent(component::setOptions);
    }
}
Also used : ContainerOptions(io.jmix.ui.component.data.options.ContainerOptions) 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 13 with ScreenData

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

the class DynamicAttributesPanelLoader method loadDataContainer.

protected void loadDataContainer(DynamicAttributesPanel resultComponent, Element element) {
    String containerId = element.attributeValue("dataContainer");
    if (Strings.isNullOrEmpty(containerId)) {
        throw new GuiDevelopmentException("DynamicAttributesPanel element doesn't have 'dataContainer' attribute", context, "DynamicAttributesPanel ID", element.attributeValue("id"));
    }
    FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
    ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
    InstanceContainer container = screenData.getContainer(containerId);
    // noinspection unchecked
    resultComponent.setInstanceContainer(container);
}
Also used : FrameOwner(io.jmix.ui.screen.FrameOwner) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) InstanceContainer(io.jmix.ui.model.InstanceContainer) ScreenData(io.jmix.ui.model.ScreenData)

Example 14 with ScreenData

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

the class AbstractChartLoader method loadDataContainer.

protected void loadDataContainer(Chart chart, Element element) {
    String dataContainerId = element.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);
        }
        chart.setDataProvider(new ContainerDataProvider(dataContainer));
    }
}
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 15 with ScreenData

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

the class UiDataFilterSupport method registerConfigurationDc.

protected void registerConfigurationDc(FilterConfiguration configurationModel, FrameOwner owner) {
    InstanceContainer<FilterConfiguration> configurationDc = dataComponents.createInstanceContainer(FilterConfiguration.class);
    configurationDc.setItem(configurationModel);
    ScreenData screenData = UiControllerUtils.getScreenData(owner);
    screenData.registerContainer(CONFIGURATION_CONTAINER_ID, configurationDc);
}
Also used : FilterConfiguration(io.jmix.uidata.entity.FilterConfiguration) ScreenData(io.jmix.ui.model.ScreenData)

Aggregations

ScreenData (io.jmix.ui.model.ScreenData)25 FrameOwner (io.jmix.ui.screen.FrameOwner)16 InstanceContainer (io.jmix.ui.model.InstanceContainer)13 GuiDevelopmentException (io.jmix.ui.GuiDevelopmentException)11 CollectionContainer (io.jmix.ui.model.CollectionContainer)10 DataLoader (io.jmix.ui.model.DataLoader)4 ContainerDataProvider (io.jmix.ui.data.impl.ContainerDataProvider)3 ContainerOptions (io.jmix.ui.component.data.options.ContainerOptions)2 ScreenDataXmlLoader (io.jmix.ui.model.impl.ScreenDataXmlLoader)2 UiControllerUtils.getScreenData (io.jmix.ui.screen.UiControllerUtils.getScreenData)2 AnnotatedMethod (io.jmix.ui.sys.UiControllerReflectionInspector.AnnotatedMethod)2 FilterConfiguration (io.jmix.uidata.entity.FilterConfiguration)2 Nullable (javax.annotation.Nullable)2 Element (org.dom4j.Element)2 LoadDataBeforeShow (com.haulmont.cuba.gui.screen.LoadDataBeforeShow)1 DevelopmentException (io.jmix.core.DevelopmentException)1 Action (io.jmix.ui.action.Action)1 Filter (io.jmix.ui.component.Filter)1 ContainerTreeItems (io.jmix.ui.component.data.tree.ContainerTreeItems)1 ContainerValueSourceProvider (io.jmix.ui.component.data.value.ContainerValueSourceProvider)1