Search in sources :

Example 6 with CollectionContainer

use of com.haulmont.cuba.gui.model.CollectionContainer in project cuba by cuba-platform.

the class TestCommentaryPanelLoader method loadDataContainer.

@SuppressWarnings("unchecked")
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(com.haulmont.cuba.gui.screen.FrameOwner) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) InstanceContainer(com.haulmont.cuba.gui.model.InstanceContainer) CollectionContainer(com.haulmont.cuba.gui.model.CollectionContainer) ScreenData(com.haulmont.cuba.gui.model.ScreenData)

Example 7 with CollectionContainer

use of com.haulmont.cuba.gui.model.CollectionContainer in project cuba by cuba-platform.

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));
    }
}
Also used : ContainerOptions(com.haulmont.cuba.gui.components.data.options.ContainerOptions) FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) InstanceContainer(com.haulmont.cuba.gui.model.InstanceContainer) CollectionContainer(com.haulmont.cuba.gui.model.CollectionContainer) ScreenData(com.haulmont.cuba.gui.model.ScreenData)

Example 8 with CollectionContainer

use of com.haulmont.cuba.gui.model.CollectionContainer in project cuba by cuba-platform.

the class TreeLoader method loadTreeChildren.

@SuppressWarnings("unchecked")
protected void loadTreeChildren() {
    Element itemsElem = element.element("treechildren");
    String containerId = element.attributeValue("dataContainer");
    if (containerId != null) {
        FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
        ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
        InstanceContainer container = screenData.getContainer(containerId);
        CollectionContainer collectionContainer;
        if (container instanceof CollectionContainer) {
            collectionContainer = (CollectionContainer) container;
        } else {
            throw new GuiDevelopmentException("Not a CollectionContainer: " + containerId, context);
        }
        String hierarchyProperty = element.attributeValue("hierarchyProperty");
        if (hierarchyProperty == null && itemsElem != null) {
            // legacy behaviour
            hierarchyProperty = itemsElem.attributeValue("hierarchyProperty");
        }
        if (Strings.isNullOrEmpty(hierarchyProperty)) {
            throw new GuiDevelopmentException("Tree doesn't have 'hierarchyProperty' attribute of the 'treechildren' element", context, "Tree ID", element.attributeValue("id"));
        }
        String showOrphansAttr = element.attributeValue("showOrphans");
        boolean showOrphans = showOrphansAttr == null || Boolean.parseBoolean(showOrphansAttr);
        resultComponent.setItems(new ContainerTreeItems(collectionContainer, hierarchyProperty, showOrphans));
    } else if (itemsElem != null) {
        String datasource = itemsElem.attributeValue("datasource");
        if (!StringUtils.isBlank(datasource)) {
            HierarchicalDatasource ds = (HierarchicalDatasource) getComponentContext().getDsContext().get(datasource);
            resultComponent.setDatasource(ds);
        }
    }
    String captionProperty = element.attributeValue("captionProperty");
    if (captionProperty == null && itemsElem != null) {
        captionProperty = itemsElem.attributeValue("captionProperty");
    }
    if (!StringUtils.isEmpty(captionProperty)) {
        resultComponent.setCaptionProperty(captionProperty);
        resultComponent.setCaptionMode(CaptionMode.PROPERTY);
    }
}
Also used : HierarchicalDatasource(com.haulmont.cuba.gui.data.HierarchicalDatasource) FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) Element(org.dom4j.Element) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) InstanceContainer(com.haulmont.cuba.gui.model.InstanceContainer) CollectionContainer(com.haulmont.cuba.gui.model.CollectionContainer) ScreenData(com.haulmont.cuba.gui.model.ScreenData) ContainerTreeItems(com.haulmont.cuba.gui.components.data.tree.ContainerTreeItems)

Example 9 with CollectionContainer

use of com.haulmont.cuba.gui.model.CollectionContainer in project cuba by cuba-platform.

the class WebEntityLinkField method afterCommitOpenedEntity.

protected void afterCommitOpenedEntity(Entity item) {
    MetaProperty metaProperty = getMetaPropertyForEditedValue();
    if (metaProperty != null && metaProperty.getRange().isClass()) {
        if (getValueSource() != null) {
            boolean ownerDsModified = false;
            boolean nonModifiedInTable = false;
            DatasourceImplementation ownerDs = null;
            CollectionContainer ownerCollectionCont = null;
            if (getCollectionDatasourceFromOwner() != null) {
                ownerDs = ((DatasourceImplementation) getCollectionDatasourceFromOwner());
                nonModifiedInTable = !ownerDs.getItemsToUpdate().contains(((EntityValueSource) getValueSource()).getItem());
                ownerDsModified = ownerDs.isModified();
            } else if (getCollectionContainerFromOwner() != null) {
                ownerCollectionCont = ((ContainerDataUnit) owner.getItems()).getContainer();
                ownerCollectionCont.mute();
            }
            // noinspection unchecked
            setValueSilently((V) item);
            // remove from items to update if it was not modified before setValue
            if (ownerDs != null) {
                if (nonModifiedInTable) {
                    ownerDs.getItemsToUpdate().remove(getDatasource().getItem());
                }
                ownerDs.setModified(ownerDsModified);
            } else if (ownerCollectionCont != null) {
                ownerCollectionCont.unmute();
            }
        } else {
            // noinspection unchecked
            setValue((V) item);
        }
    // if we edit property with non Entity type and set ListComponent owner
    } else if (owner != null) {
        if (getCollectionDatasourceFromOwner() != null) {
            // noinspection unchecked
            getCollectionDatasourceFromOwner().updateItem(item);
        } else if (getCollectionContainerFromOwner() != null) {
            // do not listen changes in collection
            getCollectionContainerFromOwner().mute();
            // noinspection unchecked
            getCollectionContainerFromOwner().replaceItem(item);
            setValueSilently(item.getValueEx(getMetaPropertyPath()));
            // listen changes
            getCollectionContainerFromOwner().unmute();
        }
        if (owner instanceof Focusable) {
            // focus owner
            ((Focusable) owner).focus();
        }
    // if we edit property with non Entity type
    } else {
        // noinspection unchecked
        setValueSilently((V) item);
    }
}
Also used : DatasourceImplementation(com.haulmont.cuba.gui.data.impl.DatasourceImplementation) CollectionContainer(com.haulmont.cuba.gui.model.CollectionContainer) MetaProperty(com.haulmont.chile.core.model.MetaProperty) ContainerDataUnit(com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit)

Example 10 with CollectionContainer

use of com.haulmont.cuba.gui.model.CollectionContainer in project cuba by cuba-platform.

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 = beanLocator.get(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.addLookupAction();
            picker.addClearAction();
            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.addClearAction();
            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 : LoggerFactory(org.slf4j.LoggerFactory) DatatypeRegistry(com.haulmont.chile.core.datatypes.DatatypeRegistry) Lookup(com.haulmont.cuba.core.entity.annotation.Lookup) StringUtils(org.apache.commons.lang3.StringUtils) java.time(java.time) ListEditorHelper(com.haulmont.cuba.gui.components.listeditor.ListEditorHelper) CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) ParseException(java.text.ParseException) DateInIntervalComponent(com.haulmont.cuba.gui.components.filter.dateinterval.DateInIntervalComponent) IgnoreUserTimeZone(com.haulmont.cuba.core.entity.annotation.IgnoreUserTimeZone) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) LookupType(com.haulmont.cuba.core.entity.annotation.LookupType) TextStringBuilder(org.apache.commons.text.TextStringBuilder) Datatypes(com.haulmont.chile.core.datatypes.Datatypes) ThemeConstantsManager(com.haulmont.cuba.gui.theme.ThemeConstantsManager) DataComponents(com.haulmont.cuba.gui.model.DataComponents) Collectors(java.util.stream.Collectors) EventHub(com.haulmont.bali.events.EventHub) ThemeConstants(com.haulmont.cuba.gui.theme.ThemeConstants) ClientConfig(com.haulmont.cuba.client.ClientConfig) UiComponents(com.haulmont.cuba.gui.UiComponents) CollectionContainer(com.haulmont.cuba.gui.model.CollectionContainer) java.util(java.util) WindowManager(com.haulmont.cuba.gui.WindowManager) ValueConversionException(com.haulmont.chile.core.datatypes.ValueConversionException) ParamsMap(com.haulmont.bali.util.ParamsMap) SimpleDateFormat(java.text.SimpleDateFormat) DynamicAttributesUtils(com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesUtils) BooleanUtils(org.apache.commons.lang3.BooleanUtils) MetaClass(com.haulmont.chile.core.model.MetaClass) Scope(org.springframework.context.annotation.Scope) com.haulmont.cuba.core.global(com.haulmont.cuba.core.global) UserSession(com.haulmont.cuba.security.global.UserSession) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) Datatype(com.haulmont.chile.core.datatypes.Datatype) ImmutableList(com.google.common.collect.ImmutableList) Subscription(com.haulmont.bali.events.Subscription) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) WindowManagerProvider(com.haulmont.cuba.gui.WindowManagerProvider) Nullable(javax.annotation.Nullable) PersistenceManagerClient(com.haulmont.cuba.client.sys.PersistenceManagerClient) Logger(org.slf4j.Logger) ContainerOptions(com.haulmont.cuba.gui.components.data.options.ContainerOptions) TemporalType(javax.persistence.TemporalType) MetaProperty(com.haulmont.chile.core.model.MetaProperty) Consumer(java.util.function.Consumer) CollectionLoader(com.haulmont.cuba.gui.model.CollectionLoader) Element(org.dom4j.Element) PropertyType(com.haulmont.cuba.core.app.dynamicattributes.PropertyType) Entity(com.haulmont.cuba.core.entity.Entity) Entity(com.haulmont.cuba.core.entity.Entity) LookupType(com.haulmont.cuba.core.entity.annotation.LookupType) PersistenceManagerClient(com.haulmont.cuba.client.sys.PersistenceManagerClient) MetaClass(com.haulmont.chile.core.model.MetaClass) Lookup(com.haulmont.cuba.core.entity.annotation.Lookup)

Aggregations

CollectionContainer (com.haulmont.cuba.gui.model.CollectionContainer)13 InstanceContainer (com.haulmont.cuba.gui.model.InstanceContainer)8 ScreenData (com.haulmont.cuba.gui.model.ScreenData)8 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)6 FrameOwner (com.haulmont.cuba.gui.screen.FrameOwner)6 ContainerOptions (com.haulmont.cuba.gui.components.data.options.ContainerOptions)5 MetaClass (com.haulmont.chile.core.model.MetaClass)4 MetaProperty (com.haulmont.chile.core.model.MetaProperty)3 ContainerDataUnit (com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit)3 Nullable (javax.annotation.Nullable)3 Entity (com.haulmont.cuba.core.entity.Entity)2 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)2 Table (com.haulmont.cuba.gui.components.Table)2 Element (org.dom4j.Element)2 Strings (com.google.common.base.Strings)1 ImmutableList (com.google.common.collect.ImmutableList)1 EventHub (com.haulmont.bali.events.EventHub)1 Subscription (com.haulmont.bali.events.Subscription)1 ParamsMap (com.haulmont.bali.util.ParamsMap)1 Preconditions.checkNotNullArgument (com.haulmont.bali.util.Preconditions.checkNotNullArgument)1