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);
}
}
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;
}
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();
}
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);
}
}
}
}
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);
}
Aggregations