Search in sources :

Example 11 with InstanceContainer

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

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

Example 12 with InstanceContainer

use of com.haulmont.cuba.gui.model.InstanceContainer 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 13 with InstanceContainer

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

the class ValueBinder method bind.

public <V> ValueBinding<V> bind(HasValue<V> component, ValueSource<V> valueSource) {
    if (valueSource instanceof BeanLocatorAware) {
        ((BeanLocatorAware) valueSource).setBeanLocator(beanLocator);
    }
    ValueBindingImpl<V> binding = new ValueBindingImpl<>(component, valueSource);
    if (component instanceof Component.Editable) {
        ((Component.Editable) component).setEditable(!valueSource.isReadOnly());
    }
    if (valueSource instanceof EntityValueSource) {
        EntityValueSource entityValueSource = (EntityValueSource) valueSource;
        MetaPropertyPath metaPropertyPath = entityValueSource.getMetaPropertyPath();
        if (component instanceof Field) {
            initRequired((Field) component, metaPropertyPath);
            initBeanValidator((Field<?>) component, metaPropertyPath);
        }
        if (entityValueSource.isDataModelSecurityEnabled()) {
            if (component instanceof Component.Editable) {
                MetaClass metaClass = entityValueSource.getEntityMetaClass();
                boolean permittedIfEmbedded = true;
                if (entityValueSource instanceof ContainerValueSource) {
                    InstanceContainer container = ((ContainerValueSource) entityValueSource).getContainer();
                    if (container instanceof Nested && metadataTools.isEmbeddable(metaClass)) {
                        String embeddedProperty = ((Nested) container).getProperty();
                        MetaClass masterMetaClass = ((Nested) container).getMaster().getEntityMetaClass();
                        permittedIfEmbedded = security.isEntityAttrUpdatePermitted(masterMetaClass, embeddedProperty);
                    }
                    if (permittedIfEmbedded && metaPropertyPath.length() > 1) {
                        for (MetaProperty property : metaPropertyPath.getMetaProperties()) {
                            if (metadataTools.isEmbedded(property) && !security.isEntityAttrUpdatePermitted(property.getDomain(), property.getName())) {
                                permittedIfEmbedded = false;
                                break;
                            }
                        }
                    }
                }
                if (!security.isEntityAttrUpdatePermitted(metaPropertyPath) || !permittedIfEmbedded) {
                    ((Component.Editable) component).setEditable(false);
                }
            }
            if (!security.isEntityAttrReadPermitted(metaPropertyPath)) {
                component.setVisible(false);
            }
        }
    }
    binding.bind();
    return binding;
}
Also used : EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) Nested(com.haulmont.cuba.gui.model.Nested) InstanceContainer(com.haulmont.cuba.gui.model.InstanceContainer) Field(com.haulmont.cuba.gui.components.Field) MetaClass(com.haulmont.chile.core.model.MetaClass) BeanLocatorAware(com.haulmont.cuba.core.sys.BeanLocatorAware) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 14 with InstanceContainer

use of com.haulmont.cuba.gui.model.InstanceContainer 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 15 with InstanceContainer

use of com.haulmont.cuba.gui.model.InstanceContainer 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)

Aggregations

InstanceContainer (com.haulmont.cuba.gui.model.InstanceContainer)18 ScreenData (com.haulmont.cuba.gui.model.ScreenData)9 CollectionContainer (com.haulmont.cuba.gui.model.CollectionContainer)8 FrameOwner (com.haulmont.cuba.gui.screen.FrameOwner)8 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)7 MetaProperty (com.haulmont.chile.core.model.MetaProperty)6 MetaClass (com.haulmont.chile.core.model.MetaClass)5 Nested (com.haulmont.cuba.gui.model.Nested)5 Nullable (javax.annotation.Nullable)5 Entity (com.haulmont.cuba.core.entity.Entity)4 ContainerValueSource (com.haulmont.cuba.gui.components.data.value.ContainerValueSource)4 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)3 Consumer (java.util.function.Consumer)3 Collectors (java.util.stream.Collectors)3 Datatype (com.haulmont.chile.core.datatypes.Datatype)2 com.haulmont.cuba.core.entity (com.haulmont.cuba.core.entity)2 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)2 OpenType (com.haulmont.cuba.gui.WindowManager.OpenType)2 Table (com.haulmont.cuba.gui.components.Table)2 GuiActionSupport (com.haulmont.cuba.gui.components.actions.GuiActionSupport)2