Search in sources :

Example 11 with Region

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

the class EditablePageTest method createPage.

private Page createPage() {
    final PropertyTree config1 = new PropertyTree();
    config1.addString("some", "config");
    final Region region1 = Region.create().name("main").add(PartComponent.create().descriptor("descriptor-x").config(new PropertyTree()).build()).add(PartComponent.create().descriptor("descriptor-y").config(new PropertyTree()).build()).build();
    return Page.create().config(config1).template(PageTemplateKey.from("template-x")).regions(PageRegions.create().add(region1).build()).build();
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Region(com.enonic.xp.region.Region)

Example 12 with Region

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

the class PageTest method copy.

@Test
public void copy() {
    final PropertyTree config1 = new PropertyTree();
    config1.addString("some", "config");
    final Region region1 = Region.create().name("main").add(PartComponent.create().descriptor("descriptor-x").config(new PropertyTree()).build()).add(PartComponent.create().descriptor("descriptor-y").config(new PropertyTree()).build()).build();
    final Page sourcePage = Page.create().config(config1).template(PageTemplateKey.from("template-x")).regions(PageRegions.create().add(region1).build()).build();
    final Page copiedPage = sourcePage.copy();
    assertEquals(sourcePage.getConfig(), copiedPage.getConfig());
    assertEquals(sourcePage.getTemplate(), copiedPage.getTemplate());
    assertEquals(sourcePage.getRegions(), sourcePage.getRegions());
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Region(com.enonic.xp.region.Region) Test(org.junit.jupiter.api.Test) AbstractEqualsTest(com.enonic.xp.support.AbstractEqualsTest)

Example 13 with Region

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

the class RegionDataSerializer method fromData.

public Region fromData(final RegionDescriptor regionDescriptor, final String parentPath, final List<PropertySet> componentsAsData) {
    final Region.Builder region = Region.create();
    region.name(regionDescriptor.getName());
    final StringBuilder regionPathBuilder = new StringBuilder(ComponentPath.DIVIDER + regionDescriptor.getName());
    if (!ComponentPath.DIVIDER.equals(parentPath)) {
        regionPathBuilder.insert(0, parentPath);
    }
    for (final Component component : getComponents(regionPathBuilder.toString(), componentsAsData)) {
        region.add(component);
    }
    return region.build();
}
Also used : Region(com.enonic.xp.region.Region) Component(com.enonic.xp.region.Component)

Example 14 with Region

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

the class PageMapper method serializeRegions.

private void serializeRegions(final MapGenerator gen, final PageRegions values) {
    gen.map(REGIONS);
    if (values != null) {
        for (final Region region : values) {
            new RegionMapper(region).serialize(gen);
        }
    }
    gen.end();
}
Also used : Region(com.enonic.xp.region.Region)

Example 15 with Region

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

the class FragmentPageResolver method replaceComponentInLayout.

private LayoutRegions replaceComponentInLayout(final LayoutRegions layoutRegions, final ImmutableList<ComponentPath.RegionAndComponent> pathItems, final Component component) {
    final ComponentPath.RegionAndComponent regionCmp = pathItems.isEmpty() ? null : pathItems.get(0);
    final Region region = regionCmp == null ? null : layoutRegions.getRegion(regionCmp.getRegionName());
    if (region == null) {
        return layoutRegions.copy();
    }
    final int componentIndex = regionCmp.getComponentIndex();
    final Component existingCmp = region.getComponent(componentIndex);
    if (existingCmp != null) {
        final Region updatedRegion = Region.create(region).set(componentIndex, component).build();
        return replaceRegionInLayout(layoutRegions, region, updatedRegion);
    }
    return layoutRegions.copy();
}
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)

Aggregations

Region (com.enonic.xp.region.Region)17 PropertyTree (com.enonic.xp.data.PropertyTree)8 Component (com.enonic.xp.region.Component)4 LayoutComponent (com.enonic.xp.region.LayoutComponent)4 DescriptorKey (com.enonic.xp.page.DescriptorKey)3 Page (com.enonic.xp.page.Page)3 PageRegions (com.enonic.xp.page.PageRegions)3 ComponentPath (com.enonic.xp.region.ComponentPath)3 LayoutRegions (com.enonic.xp.region.LayoutRegions)3 PartComponent (com.enonic.xp.region.PartComponent)3 Test (org.junit.jupiter.api.Test)3 Form (com.enonic.xp.form.Form)2 LayoutDescriptor (com.enonic.xp.region.LayoutDescriptor)2 AbstractEqualsTest (com.enonic.xp.support.AbstractEqualsTest)2 AbstractDataSerializerTest (com.enonic.xp.core.impl.content.page.AbstractDataSerializerTest)1 PropertySet (com.enonic.xp.data.PropertySet)1 FormDefaultValuesProcessor (com.enonic.xp.form.FormDefaultValuesProcessor)1 PageDescriptor (com.enonic.xp.page.PageDescriptor)1 PageDescriptorService (com.enonic.xp.page.PageDescriptorService)1 DescriptorBasedComponent (com.enonic.xp.region.DescriptorBasedComponent)1