/*! * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2002-2013 Pentaho Corporation.. All rights reserved. */ package org.pentaho.reporting.engine.classic.core.layout.build; import org.pentaho.reporting.engine.classic.core.layout.model.RenderBox; import org.pentaho.reporting.engine.classic.core.states.ReportStateKey; public class SectionLayoutModelBuilderContext implements LayoutModelBuilderContext, Cloneable { private GroupSection section; private LayoutModelBuilderContext parent; private boolean strictLegacyMode; private boolean empty; private boolean keepWrapperBoxAlive; private boolean autoGeneratedWrapperBox; public SectionLayoutModelBuilderContext( final LayoutModelBuilderContext parent, final GroupSection section, final boolean strictLegacyMode ) { this.section = section; this.parent = parent; this.strictLegacyMode = strictLegacyMode; this.parent.addChild( section.getGroupBox() ); this.parent.setEmpty( false ); } public RenderBox getRenderBox() { return section.getAddBox(); } public LayoutModelBuilderContext getParent() { return parent; } public boolean mergeSection( final ReportStateKey stateKey ) { if ( stateKey == null && strictLegacyMode == false ) { return false; } return section.mergeSection( stateKey ); } public boolean isEmpty() { return empty; } public void setEmpty( final boolean empty ) { this.empty = empty; } public boolean isKeepWrapperBoxAlive() { return keepWrapperBoxAlive; } public void setKeepWrapperBoxAlive( final boolean keepWrapperBoxAlive ) { this.keepWrapperBoxAlive = keepWrapperBoxAlive; } public boolean isAutoGeneratedWrapperBox() { return autoGeneratedWrapperBox; } public void setAutoGeneratedWrapperBox( final boolean autoGeneratedWrapperBox ) { this.autoGeneratedWrapperBox = autoGeneratedWrapperBox; } public LayoutModelBuilderContext close() { this.section.close(); return this.parent; } public void commitAsEmpty() { } public void addChild( final RenderBox child ) { section.addedSection( child ); } public void removeChild( final RenderBox child ) { section.removedLastSection( child ); } public Object clone() { try { return super.clone(); } catch ( CloneNotSupportedException e ) { throw new IllegalStateException( e ); } } public LayoutModelBuilderContext deriveForPagebreak() { final SectionLayoutModelBuilderContext clone = (SectionLayoutModelBuilderContext) clone(); clone.section = section.deriveForPagebreak(); if ( clone.parent != null ) { clone.parent = parent.deriveForPagebreak(); } return clone; } public LayoutModelBuilderContext deriveForStorage( final RenderBox clonedRoot ) { final SectionLayoutModelBuilderContext clone = (SectionLayoutModelBuilderContext) clone(); if ( clone.parent != null ) { clone.parent = parent.deriveForStorage( clonedRoot ); clone.section = section.deriveForStorage( clone.parent.getRenderBox() ); } else { clone.section = section.deriveForStorage( null ); } return clone; } public void validateAfterCommit() { section.performPostCommitModelCheck(); } public void performParanoidModelCheck() { section.performParanoidModelCheck(); } public void restoreStateAfterRollback() { section.restoreStateAfterRollback(); } public int getDepth() { if ( parent == null ) { return 1; } return 1 + parent.getDepth(); } }