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