<commit_before>/***********************************************************************
 * Copyright (c) 2009 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Actuate Corporation - initial API and implementation
 ***********************************************************************/

package org.eclipse.birt.report.engine.nLayout.area.impl;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.birt.core.exception.BirtException;
import org.eclipse.birt.report.engine.content.IBandContent;
import org.eclipse.birt.report.engine.content.IContent;
import org.eclipse.birt.report.engine.content.IElement;
import org.eclipse.birt.report.engine.content.IRowContent;
import org.eclipse.birt.report.engine.ir.RowDesign;
import org.eclipse.birt.report.engine.nLayout.LayoutContext;

public abstract class RepeatableArea extends BlockContainerArea
{

	protected List repeatList = null;

	protected int repeatHeight = 0;

	protected boolean inHeaderBand = false;
	
	public RepeatableArea( ContainerArea parent, LayoutContext context,
			IContent content )
	{
		super( parent, context, content );
		if ( needRepeat( ) )
		{
			repeatList = new ArrayList( );
		}
	}
	
	public void setInHeaderBand(boolean inHeaderBand)
	{
		this.inHeaderBand = inHeaderBand;
	}
	
	protected void addRepeatedItem() throws BirtException
	{
		if ( repeatList != null && repeatList.size( ) > 0 )
		{
			if ( !inHeaderBand )
			{
				if ( getRepeatedHeight( ) < getMaxAvaHeight( ) )
				{
					for ( int i = 0; i < repeatList.size( ); i++ )
					{
						ContainerArea row = (ContainerArea) repeatList.get( i );
						ContainerArea cloneRow = row.deepClone( );
						if(i==0 && cloneRow instanceof RowArea)
						{
							((RowArea)cloneRow).needResolveBorder = true;
						}
						children.add( i, cloneRow );
						cloneRow.setParent( this );
						update( cloneRow );
						cloneRow.setAllocatedY( currentBP );
					}
				}
				else
				{
					// remove repeat list.
					repeatList = null;
				}
			}
		}
	}

	public int getMaxAvaHeight( )
	{
		return super.getMaxAvaHeight( ) - getRepeatedHeight( );
	}

	protected int getRepeatedHeight( )
	{
		if ( inHeaderBand )
		{
			return 0;
		}
		if ( repeatHeight != 0 )
		{
			return repeatHeight;
		}
		else
		{
			if(repeatList!=null)
			{
				for ( int i = 0; i < repeatList.size( ); i++ )
				{
					AbstractArea area = (AbstractArea) repeatList.get( i );
					repeatHeight += area.getAllocatedHeight( );
				}
				return repeatHeight;
			}
		}
		return 0;
	}

	protected boolean isValidResult( List result )
	{
		if ( repeatList != null && !inHeaderBand )
		{
			return result.size( ) > repeatList.size( );
		}
		return super.isValidResult( result );
	}

	protected abstract boolean needRepeat( );

	public RepeatableArea( RepeatableArea area )
	{
		super( area );
	}

	public void add( AbstractArea area )
	{
		super.add( area );
		// cache repeat list;
		if ( repeatList != null )
		{
			IContent content = ( (ContainerArea) area ).getContent( );
			if ( content != null )
			{
				IElement parent = content.getParent( );
				if ( parent != null && parent instanceof IBandContent )
				{
					int type = ( (IBandContent) parent ).getBandType( );
					if ( type == IBandContent.BAND_HEADER
							|| type == IBandContent.BAND_GROUP_HEADER )
					{
						if ( content instanceof IRowContent )
						{
							RowDesign rowDesign = (RowDesign) content
									.getGenerateBy( );
							if ( rowDesign.getRepeatable( ) )
								repeatList.add( area );
						}
						else
							repeatList.add( area );
					}
				}
			}
		}
	}

}<commit_msg>Fix Bugzilla  Bug 275585 [Regression] Exception is thrown out when preview the attached report design with crosstab in PDF [1200] [1102]<commit_after>/***********************************************************************
 * Copyright (c) 2009 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Actuate Corporation - initial API and implementation
 ***********************************************************************/

package org.eclipse.birt.report.engine.nLayout.area.impl;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.birt.core.exception.BirtException;
import org.eclipse.birt.report.engine.content.IBandContent;
import org.eclipse.birt.report.engine.content.IContent;
import org.eclipse.birt.report.engine.content.IElement;
import org.eclipse.birt.report.engine.content.IRowContent;
import org.eclipse.birt.report.engine.ir.RowDesign;
import org.eclipse.birt.report.engine.nLayout.LayoutContext;

public abstract class RepeatableArea extends BlockContainerArea
{

	protected List repeatList = null;

	protected int repeatHeight = 0;

	protected boolean inHeaderBand = false;
	
	public RepeatableArea( ContainerArea parent, LayoutContext context,
			IContent content )
	{
		super( parent, context, content );
		if ( needRepeat( ) )
		{
			repeatList = new ArrayList( );
		}
	}
	
	public void setInHeaderBand(boolean inHeaderBand)
	{
		this.inHeaderBand = inHeaderBand;
	}
	
	protected void addRepeatedItem() throws BirtException
	{
		if ( repeatList != null && repeatList.size( ) > 0 )
		{
			if ( !inHeaderBand )
			{
				if ( getRepeatedHeight( ) < getMaxAvaHeight( ) )
				{
					for ( int i = 0; i < repeatList.size( ); i++ )
					{
						ContainerArea row = (ContainerArea) repeatList.get( i );
						ContainerArea cloneRow = row.deepClone( );
						if(i==0 && cloneRow instanceof RowArea)
						{
							((RowArea)cloneRow).needResolveBorder = true;
						}
						children.add( i, cloneRow );
						cloneRow.setParent( this );
						update( cloneRow );
						cloneRow.setAllocatedY( currentBP );
					}
				}
				else
				{
					// remove repeat list.
					repeatList = null;
				}
			}
		}
	}

	public int getMaxAvaHeight( )
	{
		return super.getMaxAvaHeight( ) - getRepeatedHeight( );
	}

	protected int getRepeatedHeight( )
	{
		if ( inHeaderBand )
		{
			return 0;
		}
		if ( repeatHeight != 0 )
		{
			return repeatHeight;
		}
		else
		{
			if(repeatList!=null)
			{
				for ( int i = 0; i < repeatList.size( ); i++ )
				{
					AbstractArea area = (AbstractArea) repeatList.get( i );
					repeatHeight += area.getAllocatedHeight( );
				}
				return repeatHeight;
			}
		}
		return 0;
	}

	protected boolean isValidResult( List result )
	{
		if ( repeatList != null && !inHeaderBand )
		{
			return result.size( ) > repeatList.size( );
		}
		return super.isValidResult( result );
	}

	protected abstract boolean needRepeat( );

	public RepeatableArea( RepeatableArea area )
	{
		super( area );
	}

	public void add( AbstractArea area )
	{
		super.add( area );
		// cache repeat list;
		if ( repeatList != null )
		{
			IContent content = ( (ContainerArea) area ).getContent( );
			if ( content != null )
			{
				IElement parent = content.getParent( );
				if ( parent != null && parent instanceof IBandContent )
				{
					int type = ( (IBandContent) parent ).getBandType( );
					if ( type == IBandContent.BAND_HEADER
							|| type == IBandContent.BAND_GROUP_HEADER )
					{
						if ( content instanceof IRowContent )
						{
							RowDesign rowDesign = (RowDesign) content
									.getGenerateBy( );
							if ( rowDesign != null && rowDesign.getRepeatable( ) )
							{
								repeatList.add( area );
							}
						}
						else
						{
							repeatList.add( area );
						}
					}
				}
			}
		}
	}

}
{'fraction_non_alphanumeric': 0.14282061117504155, 'fraction_numerical': 0.005881600818309679, 'mean_word_length': 3.027806385169928, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2376893', 'n_tokens_mistral': 2993, 'n_tokens_neox': 2380, 'n_words': 571}