/*******************************************************************************
 * 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 org.eclipse.birt.report.designer.internal.ui.views.attributes.widget.PropertyDescriptorFactory;
import org.eclipse.birt.report.designer.nls.Messages;
import org.eclipse.birt.report.designer.ui.views.attributes.IPropertyDescriptor;
import org.eclipse.birt.report.model.api.DataSetHandle;
import org.eclipse.birt.report.model.api.elements.ReportDesignConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;

/**
 * 
 */

public class DataSetPage extends AttributePage
{

	/**
	 * @param parent
	 * @param style
	 */
	public DataSetPage( Composite parent, int style )
	{
		super( parent, style );
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.birt.report.designer.internal.ui.views.attributes.page.AttributePage#buildUI()
	 */
	protected void buildUI( )
	{
		this.setLayout( WidgetUtil.createGridLayout( 3 ) );

		WidgetUtil.buildGridControl( this,
				propertiesMap,
				ReportDesignConstants.DATA_SET_ELEMENT,
				DataSetHandle.NAME_PROP,
				1,
				500 );
		WidgetUtil.createGridPlaceholder( this, 1, true );
		createDataSourceControl( this, 1, 500 );
		WidgetUtil.createGridPlaceholder( this, 1, true );

	}

	private void createDataSourceControl( Composite parent, int hSpan, int width )
	{
		String elementName = ReportDesignConstants.DATA_SET_ELEMENT;
		String property = DataSetHandle.DATA_SOURCE_PROP;

		IPropertyDescriptor descriptor = PropertyDescriptorFactory.getPropertyDescriptor( elementName,
				property );
		propertiesMap.put( property, descriptor );
		Label label = new Label( parent, SWT.NONE );
		label.setText( Messages.getString( "DataSetPageGenerator.DataSourceName" ) );
		Control control = descriptor.createControl( parent );
		GridData data = new GridData( );
		data.horizontalSpan = hSpan;
		data.widthHint = width;
		control.setLayoutData( data );
	}

}
