Search in sources :

Example 6 with Region

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

the class PageDefaultValuesProcessor method applyRegionsDefaultValues.

private void applyRegionsDefaultValues(final Page editedPage, final Page sourcePage) {
    for (Region region : editedPage.getRegions()) {
        final Region sourceRegion = sourcePage != null ? sourcePage.getRegion(region.getName()) : null;
        applyRegionDefaultValues(region, sourceRegion);
    }
}
Also used : Region(com.enonic.xp.region.Region)

Example 7 with Region

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

the class PageDataSerializerTest method createPage.

private Page createPage() {
    final PropertyTree myPartConfig = new PropertyTree();
    myPartConfig.addString("some", "somevalue");
    final PropertyTree imageConfig = new PropertyTree();
    imageConfig.addString("caption", "Caption");
    final DescriptorKey pageDescriptorKey = DescriptorKey.from("app-key:d-name");
    final String regionName1 = "top";
    final String regionName2 = "bottom";
    final Region mainRegion1 = Region.create().name(regionName1).add(createPartComponent("MyPart1", "app-descriptor-x:name-x", myPartConfig)).add(createLayoutComponent()).add(LayoutComponent.create().build()).build();
    final Region mainRegion2 = Region.create().name(regionName2).add(createPartComponent("MyPart2", "app-descriptor-y:name-y", myPartConfig)).add(createImageComponent("img-id-x", "Image Component", imageConfig)).add(ImageComponent.create().build()).build();
    final PageRegions regions = PageRegions.create().add(mainRegion1).add(mainRegion2).build();
    final PropertyTree pageConfig = new PropertyTree();
    pageConfig.addString("some", "config");
    pageConfig.addDouble("aim", 42.0);
    final Page page = Page.create().config(pageConfig).descriptor(pageDescriptorKey).regions(regions).build();
    Mockito.when(pageDescriptorService.getByKey(pageDescriptorKey)).thenReturn(PageDescriptor.create().config(Form.create().build()).key(pageDescriptorKey).regions(RegionDescriptors.create().add(RegionDescriptor.create().name(regionName1).build()).add(RegionDescriptor.create().name(regionName2).build()).build()).build());
    return page;
}
Also used : PageRegions(com.enonic.xp.page.PageRegions) PropertyTree(com.enonic.xp.data.PropertyTree) DescriptorKey(com.enonic.xp.page.DescriptorKey) Region(com.enonic.xp.region.Region) Page(com.enonic.xp.page.Page)

Example 8 with Region

use of com.enonic.xp.region.Region 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 9 with Region

use of com.enonic.xp.region.Region 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)

Example 10 with Region

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

the class RegionDataSerializerTest method region.

@Test
public void region() {
    final PropertyTree myPartConfig = new PropertyTree();
    myPartConfig.addString("some", "config");
    final String layoutName = "MyOtherPart";
    final DescriptorKey layoutDescriptorKey = DescriptorKey.from("app-descr:layout-name");
    final Region region = Region.create().name("main").add(createPartComponent("MyPart", "app-descr:part-name", myPartConfig)).add(ImageComponent.create().build()).add(LayoutComponent.create().descriptor(layoutDescriptorKey).build()).build();
    Mockito.when(layoutDescriptorService.getByKey(layoutDescriptorKey)).thenReturn(LayoutDescriptor.create().key(layoutDescriptorKey).displayName(layoutName).config(Form.create().build()).regions(RegionDescriptors.create().build()).build());
    final PropertyTree regionAsData = new PropertyTree();
    // exercise
    regionSerializer.toData(region, regionAsData.getRoot());
    final RegionDescriptor regionDescriptor = RegionDescriptor.create().name("main").build();
    final List<PropertySet> components = regionAsData.getProperties(ComponentDataSerializer.COMPONENTS).stream().map(item -> item.getSet()).collect(Collectors.toList());
    final Region parsedRegion = regionSerializer.fromData(regionDescriptor, ComponentPath.DIVIDER, components);
    // verify
    assertEquals(region, parsedRegion);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) PropertySet(com.enonic.xp.data.PropertySet) RegionDescriptors(com.enonic.xp.region.RegionDescriptors) Collectors(java.util.stream.Collectors) ComponentPath(com.enonic.xp.region.ComponentPath) LayoutDescriptor(com.enonic.xp.region.LayoutDescriptor) Test(org.junit.jupiter.api.Test) Form(com.enonic.xp.form.Form) Region(com.enonic.xp.region.Region) Mockito(org.mockito.Mockito) List(java.util.List) LayoutComponent(com.enonic.xp.region.LayoutComponent) DescriptorKey(com.enonic.xp.page.DescriptorKey) AbstractDataSerializerTest(com.enonic.xp.core.impl.content.page.AbstractDataSerializerTest) ImageComponent(com.enonic.xp.region.ImageComponent) RegionDescriptor(com.enonic.xp.region.RegionDescriptor) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PropertyTree(com.enonic.xp.data.PropertyTree) RegionDescriptor(com.enonic.xp.region.RegionDescriptor) PropertyTree(com.enonic.xp.data.PropertyTree) DescriptorKey(com.enonic.xp.page.DescriptorKey) Region(com.enonic.xp.region.Region) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test) AbstractDataSerializerTest(com.enonic.xp.core.impl.content.page.AbstractDataSerializerTest)

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