use of com.enonic.xp.region.DescriptorBasedComponent 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);
}
}
}
}
Aggregations