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");
}
}
}
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);
}
}
}
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());
}
}
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);
}
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;
}
}
Aggregations