Search in sources :

Example 1 with LayoutComponentType

use of com.enonic.xp.region.LayoutComponentType in project xp by enonic.

the class PageDefaultValuesProcessor method applyRegionDefaultValues.

private void applyRegionDefaultValues(final Region region, final Region sourceRegion) {
    for (Component cmp : region.getComponents()) {
        if (!(cmp.getType() instanceof PartComponentType || cmp.getType() instanceof LayoutComponentType)) {
            // skip if not Part or Layout
            continue;
        }
        final DescriptorBasedComponent layoutOrPart = (DescriptorBasedComponent) cmp;
        final PropertyTree cmpData = layoutOrPart.getConfig();
        final Component sourceCmp = sourceRegion != null ? sourceRegion.getComponents().stream().filter(c -> c.equals(cmp)).findFirst().orElse(null) : null;
        if (sourceCmp == null && cmpData.getRoot().getPropertySize() == 0) {
            applyComponentDefaultValues(layoutOrPart);
        }
        // layout regions
        if (cmp.getType() instanceof LayoutComponentType) {
            final LayoutComponent layout = (LayoutComponent) cmp;
            final LayoutComponent sourceLayout = (LayoutComponent) sourceCmp;
            for (Region layoutRegion : layout.getRegions()) {
                final Region sourceLayoutRegion = sourceLayout != null ? sourceLayout.getRegion(region.getName()) : null;
                applyRegionDefaultValues(layoutRegion, sourceLayoutRegion);
            }
        }
    }
}
Also used : PartComponentType(com.enonic.xp.region.PartComponentType) FormDefaultValuesProcessor(com.enonic.xp.form.FormDefaultValuesProcessor) PartDescriptorService(com.enonic.xp.region.PartDescriptorService) PageDescriptor(com.enonic.xp.page.PageDescriptor) Page(com.enonic.xp.page.Page) LayoutDescriptorService(com.enonic.xp.region.LayoutDescriptorService) PartDescriptor(com.enonic.xp.region.PartDescriptor) LayoutComponentType(com.enonic.xp.region.LayoutComponentType) DescriptorBasedComponent(com.enonic.xp.region.DescriptorBasedComponent) LayoutDescriptor(com.enonic.xp.region.LayoutDescriptor) Objects(java.util.Objects) Form(com.enonic.xp.form.Form) Region(com.enonic.xp.region.Region) PageDescriptorService(com.enonic.xp.page.PageDescriptorService) LayoutComponent(com.enonic.xp.region.LayoutComponent) PartComponentType(com.enonic.xp.region.PartComponentType) PartComponent(com.enonic.xp.region.PartComponent) Component(com.enonic.xp.region.Component) PropertyTree(com.enonic.xp.data.PropertyTree) PropertyTree(com.enonic.xp.data.PropertyTree) Region(com.enonic.xp.region.Region) DescriptorBasedComponent(com.enonic.xp.region.DescriptorBasedComponent) LayoutComponent(com.enonic.xp.region.LayoutComponent) PartComponent(com.enonic.xp.region.PartComponent) Component(com.enonic.xp.region.Component) LayoutComponentType(com.enonic.xp.region.LayoutComponentType) DescriptorBasedComponent(com.enonic.xp.region.DescriptorBasedComponent) LayoutComponent(com.enonic.xp.region.LayoutComponent)

Aggregations

PropertyTree (com.enonic.xp.data.PropertyTree)1 Form (com.enonic.xp.form.Form)1 FormDefaultValuesProcessor (com.enonic.xp.form.FormDefaultValuesProcessor)1 Page (com.enonic.xp.page.Page)1 PageDescriptor (com.enonic.xp.page.PageDescriptor)1 PageDescriptorService (com.enonic.xp.page.PageDescriptorService)1 Component (com.enonic.xp.region.Component)1 DescriptorBasedComponent (com.enonic.xp.region.DescriptorBasedComponent)1 LayoutComponent (com.enonic.xp.region.LayoutComponent)1 LayoutComponentType (com.enonic.xp.region.LayoutComponentType)1 LayoutDescriptor (com.enonic.xp.region.LayoutDescriptor)1 LayoutDescriptorService (com.enonic.xp.region.LayoutDescriptorService)1 PartComponent (com.enonic.xp.region.PartComponent)1 PartComponentType (com.enonic.xp.region.PartComponentType)1 PartDescriptor (com.enonic.xp.region.PartDescriptor)1 PartDescriptorService (com.enonic.xp.region.PartDescriptorService)1 Region (com.enonic.xp.region.Region)1 Objects (java.util.Objects)1