Search in sources :

Example 1 with LayoutRegions

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

the class TestDataFixtures method createLayoutComponent.

private static LayoutComponent createLayoutComponent() {
    final Region region1 = Region.create().name("left").add(PartComponent.create().build()).add(TextComponent.create().text("text text text").build()).add(TextComponent.create().build()).build();
    final Region region2 = Region.create().name("right").add(createImageComponent("image-id", "Some Image", null)).add(createFragmentComponent("213sda-ss222", "My Fragment")).build();
    final LayoutRegions layoutRegions = LayoutRegions.create().add(region1).add(region2).build();
    return LayoutComponent.create().descriptor("layoutDescriptor:name").regions(layoutRegions).build();
}
Also used : Region(com.enonic.xp.region.Region) LayoutRegions(com.enonic.xp.region.LayoutRegions)

Example 2 with LayoutRegions

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

the class PageDataSerializerTest method createLayoutComponent.

private LayoutComponent createLayoutComponent() {
    final String layoutName = "MyLayout";
    final DescriptorKey layoutDescriptorKey = DescriptorKey.from("layoutDescriptor:name");
    final String regionName1 = "left";
    final String regionName2 = "right";
    final Region region1 = Region.create().name(regionName1).add(PartComponent.create().build()).add(TextComponent.create().text("text text text").build()).add(TextComponent.create().build()).build();
    final Region region2 = Region.create().name(regionName2).add(createImageComponent("image-id", "Some Image", null)).add(createFragmentComponent("213sda-ss222", "My Fragment")).build();
    final LayoutRegions layoutRegions = LayoutRegions.create().add(region1).add(region2).build();
    Mockito.when(layoutDescriptorService.getByKey(layoutDescriptorKey)).thenReturn(LayoutDescriptor.create().key(layoutDescriptorKey).displayName(layoutName).config(Form.create().build()).regions(RegionDescriptors.create().add(RegionDescriptor.create().name(regionName1).build()).add(RegionDescriptor.create().name(regionName2).build()).build()).build());
    return LayoutComponent.create().descriptor(layoutDescriptorKey).regions(layoutRegions).build();
}
Also used : DescriptorKey(com.enonic.xp.page.DescriptorKey) Region(com.enonic.xp.region.Region) LayoutRegions(com.enonic.xp.region.LayoutRegions)

Example 3 with LayoutRegions

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

the class ComponentInstruction method resolveComponentInFragment.

private Component resolveComponentInFragment(final Page page, final ComponentPath path) {
    final Component fragmentComponent = page.getFragment();
    if (!(fragmentComponent instanceof LayoutComponent)) {
        throw new RenderException("Component not found: [{0}]", path);
    }
    final LayoutComponent layout = (LayoutComponent) fragmentComponent;
    final LayoutRegions pageRegions = layout.getRegions();
    final Component component = pageRegions.getComponent(path);
    if (component == null) {
        throw new RenderException("Component not found: [{0}]", path);
    }
    return component;
}
Also used : RenderException(com.enonic.xp.portal.impl.rendering.RenderException) LayoutComponent(com.enonic.xp.region.LayoutComponent) Component(com.enonic.xp.region.Component) LayoutComponent(com.enonic.xp.region.LayoutComponent) LayoutRegions(com.enonic.xp.region.LayoutRegions)

Example 4 with LayoutRegions

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

the class FragmentPageResolver method replaceComponentInPage.

private PageRegions replaceComponentInPage(final PageRegions pageRegions, final ImmutableList<ComponentPath.RegionAndComponent> pathItems, final Component component) {
    final ComponentPath.RegionAndComponent regionCmp = pathItems.isEmpty() ? null : pathItems.get(0);
    final Region region = regionCmp == null ? null : pageRegions.getRegion(regionCmp.getRegionName());
    if (region == null) {
        return pageRegions;
    }
    final int componentIndex = regionCmp.getComponentIndex();
    final Component existingCmp = region.getComponent(componentIndex);
    if (existingCmp == null) {
        return pageRegions;
    }
    final int numberOfLevels = pathItems.size();
    if (numberOfLevels == 1) {
        final Region updatedRegion = Region.create(region).set(componentIndex, component).build();
        return replaceRegionInPage(pageRegions, region, updatedRegion);
    } else {
        if (!(existingCmp instanceof LayoutComponent)) {
            return pageRegions;
        }
        final LayoutComponent layoutComponent = (LayoutComponent) existingCmp;
        final LayoutRegions layoutRegions = replaceComponentInLayout(layoutComponent.getRegions(), removeFirstLevel(pathItems), component);
        final LayoutComponent updatedLayout = LayoutComponent.create(layoutComponent).regions(layoutRegions).build();
        final Region updatedRegion = Region.create(region).set(componentIndex, updatedLayout).build();
        return replaceRegionInPage(pageRegions, region, updatedRegion);
    }
}
Also used : ComponentPath(com.enonic.xp.region.ComponentPath) Region(com.enonic.xp.region.Region) LayoutComponent(com.enonic.xp.region.LayoutComponent) Component(com.enonic.xp.region.Component) LayoutComponent(com.enonic.xp.region.LayoutComponent) LayoutRegions(com.enonic.xp.region.LayoutRegions)

Aggregations

LayoutRegions (com.enonic.xp.region.LayoutRegions)4 Region (com.enonic.xp.region.Region)3 Component (com.enonic.xp.region.Component)2 LayoutComponent (com.enonic.xp.region.LayoutComponent)2 DescriptorKey (com.enonic.xp.page.DescriptorKey)1 RenderException (com.enonic.xp.portal.impl.rendering.RenderException)1 ComponentPath (com.enonic.xp.region.ComponentPath)1