/*******************************************************************************
 * Copyright (c) 2004 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.designer.internal.ui.views.attributes.page;

import java.util.Set;

import org.eclipse.birt.report.model.api.GroupElementFactory;
import org.eclipse.birt.report.model.api.GroupPropertyHandle;
import org.eclipse.birt.report.model.api.ReportElementHandle;
import org.eclipse.birt.report.model.api.elements.ReportDesignConstants;
import org.eclipse.birt.report.model.elements.interfaces.IReportItemModel;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

/**
 * TOC expresion page.
 * 
 */
public class TOCExpressionPage extends AttributePage
{

	private Composite tocArea;

	/**
	 * Contructor
	 */
	public TOCExpressionPage( Composite parent, int style )
	{
		super( parent, style );
	}

	protected void buildUI( )
	{
		setLayout( WidgetUtil.createGridLayout( 1 ) );

		tocArea = (Composite) WidgetUtil.buildGridControl( this,
				propertiesMap,
				ReportDesignConstants.REPORT_ITEM,
				IReportItemModel.TOC_PROP,
				1,
				true );
		GridData gd = new GridData(GridData.FILL_VERTICAL);
		gd.widthHint = 500;

		tocArea.setLayoutData( gd);
	}

	protected void refreshValues( Set propertiesSet )
	{
		if ( input.size( ) > 0 )
		{
			ReportElementHandle handle = (ReportElementHandle) input.get( 0 );
			GroupPropertyHandle propertyHandle = GroupElementFactory.newGroupElement( handle.getModuleHandle( ),
					input )
					.getPropertyHandle( IReportItemModel.TOC_PROP );
			Control[] children = tocArea.getChildren( );
			for ( int i = 0; i < children.length; i++ )
			{
				children[i].setEnabled( !propertyHandle.isReadOnly( ) );
			}
		}
		super.refreshValues( propertiesSet );
	}

}
