Search in sources :

Example 6 with CollectionContainer

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

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

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

the class Param method createEntityLookup.

protected Component createEntityLookup(FilterDataContext filterDataContext, ValueProperty valueProperty) {
    MetaClass metaClass = metadata.getSession().getClassNN(javaClass);
    LookupType type = null;
    if (property != null && property.getRange().isClass()) {
        type = (LookupType) metadata.getTools().getMetaAnnotationAttributes(property.getAnnotations(), Lookup.class).get("type");
    }
    PersistenceManagerClient persistenceManager = (PersistenceManagerClient) applicationContext.getBean(PersistenceManagerClient.NAME);
    boolean useLookupScreen = type != null ? type == LookupType.SCREEN : persistenceManager.useLookupScreen(metaClass.getName());
    if (useLookupScreen) {
        if (inExpr) {
            ListEditor listEditor = uiComponents.create(ListEditor.class);
            listEditor.setItemType(ListEditor.ItemType.ENTITY);
            listEditor.setEntityName(metaClass.getName());
            initListEditor(listEditor, valueProperty);
            return listEditor;
        } else {
            PickerField<Entity> picker = uiComponents.create(PickerField.NAME);
            picker.setMetaClass(metaClass);
            picker.setWidth(theme.get("cuba.gui.filter.Param.textComponent.width"));
            picker.addAction(actions.create(LookupAction.ID));
            picker.addAction(actions.create(EntityClearAction.ID));
            picker.addValueChangeListener(e -> _setValue(e.getValue(), valueProperty));
            picker.setValue((Entity) _getValue(valueProperty));
            return picker;
        }
    } else {
        if (inExpr) {
            CollectionLoader<Entity> loader = createEntityOptionsLoader(metaClass);
            CollectionContainer<Entity> container = dataComponents.createCollectionContainer(metaClass.getJavaClass());
            loader.setContainer(container);
            ListEditor listEditor = uiComponents.create(ListEditor.class);
            listEditor.setItemType(ListEditor.ItemType.ENTITY);
            listEditor.setEntityName(metaClass.getName());
            // noinspection unchecked
            listEditor.setOptions(new ContainerOptions<>(container));
            // noinspection unchecked
            initListEditor(listEditor, valueProperty);
            // noinspection unchecked
            Consumer<CollectionContainer.CollectionChangeEvent<?>> listener = e -> listEditor.setValue(null);
            if (filterDataContext != null) {
                filterDataContext.registerCollectionLoader(this, loader);
                filterDataContext.registerContainerCollectionChangeListener(this, container, listener);
            }
            return listEditor;
        } else {
            CollectionLoader<Entity> loader = createEntityOptionsLoader(metaClass);
            CollectionContainer<Entity> container = dataComponents.createCollectionContainer(metaClass.getJavaClass());
            loader.setContainer(container);
            LookupPickerField<Entity> lookup = uiComponents.create(LookupPickerField.NAME);
            lookup.setWidth(theme.get("cuba.gui.filter.Param.textComponent.width"));
            lookup.addAction(actions.create(EntityClearAction.ID));
            lookup.setOptions(new ContainerOptions<>(container));
            Consumer<CollectionContainer.CollectionChangeEvent<?>> listener = e -> lookup.setValue(null);
            lookup.addValueChangeListener(e -> _setValue(e.getValue(), valueProperty));
            lookup.setValue((Entity) _getValue(valueProperty));
            if (filterDataContext != null) {
                filterDataContext.registerCollectionLoader(this, loader);
                filterDataContext.registerContainerCollectionChangeListener(this, container, listener);
            }
            return lookup;
        }
    }
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) LookupAction(com.haulmont.cuba.gui.actions.picker.LookupAction) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) CubaProperties(com.haulmont.cuba.CubaProperties) ParamsMap(io.jmix.core.common.util.ParamsMap) EventHub(io.jmix.core.common.event.EventHub) Lookup(com.haulmont.cuba.core.entity.annotation.Lookup) AppBeans(com.haulmont.cuba.core.global.AppBeans) StringUtils(org.apache.commons.lang3.StringUtils) EntityValues(io.jmix.core.entity.EntityValues) java.time(java.time) ListEditorHelper(com.haulmont.cuba.gui.components.listeditor.ListEditorHelper) PickerField(com.haulmont.cuba.gui.components.PickerField) ParseException(java.text.ParseException) DateInIntervalComponent(com.haulmont.cuba.gui.components.filter.dateinterval.DateInIntervalComponent) MetadataTools(io.jmix.core.MetadataTools) LookupType(com.haulmont.cuba.core.entity.annotation.LookupType) Subscription(io.jmix.core.common.event.Subscription) TextStringBuilder(org.apache.commons.text.TextStringBuilder) Datatypes(com.haulmont.chile.core.datatypes.Datatypes) Messages(com.haulmont.cuba.core.global.Messages) Datatype(io.jmix.core.metamodel.datatype.Datatype) Collectors(java.util.stream.Collectors) ThemeConstantsManager(io.jmix.ui.theme.ThemeConstantsManager) ContainerOptions(io.jmix.ui.component.data.options.ContainerOptions) UiComponents(com.haulmont.cuba.gui.UiComponents) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) IgnoreUserTimeZone(io.jmix.core.entity.annotation.IgnoreUserTimeZone) io.jmix.ui.component(io.jmix.ui.component) NotImplementedException(org.apache.commons.lang3.NotImplementedException) CollectionLoader(io.jmix.ui.model.CollectionLoader) java.util(java.util) WindowManager(com.haulmont.cuba.gui.WindowManager) LookupPickerField(com.haulmont.cuba.gui.components.LookupPickerField) SimpleDateFormat(java.text.SimpleDateFormat) BooleanUtils(org.apache.commons.lang3.BooleanUtils) QueryTransformerFactory(io.jmix.data.QueryTransformerFactory) Scope(org.springframework.context.annotation.Scope) Metadata(com.haulmont.cuba.core.global.Metadata) UserSession(com.haulmont.cuba.security.global.UserSession) Strings(com.google.common.base.Strings) FilterDataContext(com.haulmont.cuba.gui.components.FilterDataContext) ImmutableList(com.google.common.collect.ImmutableList) DatatypeRegistry(io.jmix.core.metamodel.datatype.DatatypeRegistry) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) WindowManagerProvider(com.haulmont.cuba.gui.WindowManagerProvider) EntityClearAction(io.jmix.ui.action.entitypicker.EntityClearAction) QueryTransformer(io.jmix.data.QueryTransformer) Nullable(javax.annotation.Nullable) Actions(io.jmix.ui.Actions) PersistenceManagerClient(com.haulmont.cuba.client.sys.PersistenceManagerClient) Logger(org.slf4j.Logger) DynAttrUtils(io.jmix.dynattr.DynAttrUtils) CollectionContainer(io.jmix.ui.model.CollectionContainer) ThemeConstants(io.jmix.ui.theme.ThemeConstants) TemporalType(javax.persistence.TemporalType) FetchPlan(io.jmix.core.FetchPlan) NotificationType(com.haulmont.cuba.gui.components.Frame.NotificationType) UserSessionSource(com.haulmont.cuba.core.global.UserSessionSource) ListEditor(com.haulmont.cuba.gui.components.ListEditor) ApplicationContext(org.springframework.context.ApplicationContext) Consumer(java.util.function.Consumer) ValueConversionException(io.jmix.ui.component.data.ValueConversionException) LookupField(com.haulmont.cuba.gui.components.LookupField) Entity(io.jmix.core.Entity) Element(org.dom4j.Element) DataComponents(io.jmix.ui.model.DataComponents) ListEditor(com.haulmont.cuba.gui.components.ListEditor) Entity(io.jmix.core.Entity) LookupType(com.haulmont.cuba.core.entity.annotation.LookupType) PersistenceManagerClient(com.haulmont.cuba.client.sys.PersistenceManagerClient) MetaClass(io.jmix.core.metamodel.model.MetaClass) Lookup(com.haulmont.cuba.core.entity.annotation.Lookup)

Example 9 with CollectionContainer

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

the class CalendarLoader method loadDataContainer.

@SuppressWarnings("unchecked")
protected void loadDataContainer(Calendar component, Element element) {
    String containerId = element.attributeValue("dataContainer");
    if (Strings.isNullOrEmpty(containerId)) {
        return;
    }
    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);
    }
    component.setEventProvider(new ContainerCalendarEventProvider<>(((CollectionContainer) container)));
}
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 10 with CollectionContainer

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

the class TestCommentaryPanelLoader method loadDataContainer.

private void loadDataContainer(TestCommentaryPanel resultComponent, Element element) {
    String containerId = this.element.attributeValue("dataContainer");
    if (Strings.isNullOrEmpty(containerId)) {
        throw new GuiDevelopmentException("CommentaryPanel element doesn't have 'dataContainer' attribute", context, "CommentaryPanel ID", element.attributeValue("id"));
    }
    FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
    ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
    InstanceContainer container = screenData.getContainer(containerId);
    if (container instanceof CollectionContainer) {
        resultComponent.setDataContainer((CollectionContainer) container);
    } else {
        throw new GuiDevelopmentException("Not a CollectionContainer: " + containerId, context);
    }
}
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)

Aggregations

CollectionContainer (io.jmix.ui.model.CollectionContainer)17 InstanceContainer (io.jmix.ui.model.InstanceContainer)11 ScreenData (io.jmix.ui.model.ScreenData)10 GuiDevelopmentException (io.jmix.ui.GuiDevelopmentException)9 FrameOwner (io.jmix.ui.screen.FrameOwner)9 MetaClass (io.jmix.core.metamodel.model.MetaClass)3 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)3 ContainerDataUnit (io.jmix.ui.component.data.meta.ContainerDataUnit)3 ContainerOptions (io.jmix.ui.component.data.options.ContainerOptions)3 ContainerDataProvider (io.jmix.ui.data.impl.ContainerDataProvider)3 Nullable (javax.annotation.Nullable)3 Strings (com.google.common.base.Strings)1 ImmutableList (com.google.common.collect.ImmutableList)1 Datatypes (com.haulmont.chile.core.datatypes.Datatypes)1 CubaProperties (com.haulmont.cuba.CubaProperties)1 PersistenceManagerClient (com.haulmont.cuba.client.sys.PersistenceManagerClient)1 Lookup (com.haulmont.cuba.core.entity.annotation.Lookup)1 LookupType (com.haulmont.cuba.core.entity.annotation.LookupType)1 AppBeans (com.haulmont.cuba.core.global.AppBeans)1 Messages (com.haulmont.cuba.core.global.Messages)1