Search in sources :

Example 1 with HasLoader

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

the class BulkEditors method refreshItems.

protected void refreshItems(@Nullable DataUnit dataSource) {
    if (dataSource instanceof ContainerDataUnit) {
        CollectionContainer<?> container = ((ContainerDataUnit<?>) dataSource).getContainer();
        DataLoader loader = null;
        if (container instanceof HasLoader) {
            loader = ((HasLoader) container).getLoader();
        }
        if (loader != null) {
            loader.load();
        } else {
            log.warn("Target container has no loader, refresh is impossible");
        }
    }
}
Also used : DataLoader(io.jmix.ui.model.DataLoader) HasLoader(io.jmix.ui.model.HasLoader) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit)

Example 2 with HasLoader

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

the class DynamicAttributesPanel method setInstanceContainer.

/**
 * Defines InstanceContainer for DynamicAttributesPanel.
 *
 * @param container {@link InstanceContainer} object with editing entity
 */
@StudioProperty(name = "dataContainer", type = PropertyType.DATACONTAINER_REF, required = true)
public void setInstanceContainer(InstanceContainer<Object> container) {
    this.instanceContainer = container;
    propertiesForm.setValueSourceProvider(new ContainerValueSourceProvider<>(instanceContainer));
    initCategoryField(instanceContainer);
    initPropertiesForm();
    instanceContainer.addItemChangeListener(this::onInstanceContainerItemChangeEvent);
    if (instanceContainer instanceof HasLoader) {
        DataLoader loader = ((HasLoader) instanceContainer).getLoader();
        if (loader != null) {
            loader.setHint(DynAttrQueryHints.LOAD_DYN_ATTR, true);
        }
    }
}
Also used : DataLoader(io.jmix.ui.model.DataLoader) HasLoader(io.jmix.ui.model.HasLoader) StudioProperty(io.jmix.ui.meta.StudioProperty)

Example 3 with HasLoader

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

the class RefreshAction method execute.

/**
 * Executes the action.
 */
@Override
public void execute() {
    if (target == null) {
        throw new IllegalStateException("RefreshAction target is not set");
    }
    if (target.getItems() instanceof EmptyDataUnit) {
        return;
    }
    if (!(target.getItems() instanceof ContainerDataUnit)) {
        throw new IllegalStateException("RefreshAction target is null or does not implement SupportsContainerBinding");
    }
    CollectionContainer container = ((ContainerDataUnit) target.getItems()).getContainer();
    if (container == null) {
        throw new IllegalStateException("RefreshAction target is not bound to CollectionContainer");
    }
    DataLoader loader = null;
    if (container instanceof HasLoader) {
        loader = ((HasLoader) container).getLoader();
    }
    if (loader != null) {
        DataContext dataContext = loader.getDataContext();
        if (dataContext != null) {
            for (Object entity : container.getItems()) {
                dataContext.evict(entity);
            }
        }
        loader.load();
    } else {
        log.warn("RefreshAction '{}' target container has no loader, refresh is impossible", getId());
    }
}
Also used : DataLoader(io.jmix.ui.model.DataLoader) DataContext(io.jmix.ui.model.DataContext) EmptyDataUnit(io.jmix.ui.component.data.meta.EmptyDataUnit) CollectionContainer(io.jmix.ui.model.CollectionContainer) HasLoader(io.jmix.ui.model.HasLoader) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit)

Example 4 with HasLoader

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

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

the class DynAttrAwareEntityTransformer method transformForCollectionContainer.

@Override
public <E> E transformForCollectionContainer(E editedEntity, CollectionContainer<E> container) {
    boolean needDynamicAttributes = false;
    boolean dynamicAttributesAreLoaded = true;
    DynamicAttributesState state = EntitySystemAccess.getExtraState(editedEntity, DynamicAttributesState.class);
    if (state != null) {
        dynamicAttributesAreLoaded = state.getDynamicAttributes() != null;
    }
    if (container instanceof HasLoader) {
        DataLoader loader = ((HasLoader) container).getLoader();
        if (loader instanceof CollectionLoader) {
            Map<String, Serializable> hints = loader.getHints();
            needDynamicAttributes = hints != null && Boolean.TRUE.equals(hints.get(DynAttrQueryHints.LOAD_DYN_ATTR));
        }
    }
    FetchPlan fetchPlan = container.getFetchPlan();
    if (fetchPlan != null && !entityStates.isLoadedWithFetchPlan(editedEntity, fetchPlan)) {
        return dataManager.load(Id.of(editedEntity)).fetchPlan(fetchPlan).hint(DynAttrQueryHints.LOAD_DYN_ATTR, needDynamicAttributes).one();
    } else if (needDynamicAttributes && !dynamicAttributesAreLoaded) {
        dynAttrManager.loadValues(Collections.singletonList(editedEntity), fetchPlan, accessConstraintsRegistry.getConstraints());
        return editedEntity;
    } else {
        return editedEntity;
    }
}
Also used : DataLoader(io.jmix.ui.model.DataLoader) Serializable(java.io.Serializable) CollectionLoader(io.jmix.ui.model.CollectionLoader) DynamicAttributesState(io.jmix.dynattr.DynamicAttributesState) HasLoader(io.jmix.ui.model.HasLoader)

Aggregations

DataLoader (io.jmix.ui.model.DataLoader)5 HasLoader (io.jmix.ui.model.HasLoader)5 ContainerDataUnit (io.jmix.ui.component.data.meta.ContainerDataUnit)2 DynamicAttributesState (io.jmix.dynattr.DynamicAttributesState)1 EmptyDataUnit (io.jmix.ui.component.data.meta.EmptyDataUnit)1 StudioProperty (io.jmix.ui.meta.StudioProperty)1 CollectionContainer (io.jmix.ui.model.CollectionContainer)1 CollectionLoader (io.jmix.ui.model.CollectionLoader)1 DataContext (io.jmix.ui.model.DataContext)1 ScreenData (io.jmix.ui.model.ScreenData)1 Screen (io.jmix.ui.screen.Screen)1 Subscribe (io.jmix.ui.screen.Subscribe)1 Serializable (java.io.Serializable)1 HashSet (java.util.HashSet)1 Matcher (java.util.regex.Matcher)1