/*******************************************************************************
 * 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.ui.views.attributes.IPropertyDescriptor;
import org.eclipse.birt.report.designer.ui.views.attributes.providers.PropertyProcessor;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
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;

/**
 * The comments attribute page of Report element.
 */
public class DescriptionPage extends AttributePage
{

	/**
	 * Constructor
	 * 
	 * @param parent
	 *            A widget which will be the parent of the new instance (cannot
	 *            be null)
	 * @param style
	 *            The style of widget to construct
	 */
	public DescriptionPage( 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( )
	{
		setLayout( WidgetUtil.createGridLayout( 2 ) );

		IPropertyDescriptor descriptor = PropertyDescriptorFactory.getPropertyDescriptor( ReportDesignConstants.REPORT_DESIGN_ELEMENT,
				ReportDesignHandle.DESCRIPTION_PROP );
		propertiesMap.put( ReportDesignHandle.DESCRIPTION_PROP, descriptor );
		Label label = new Label( this, SWT.NONE );
		GridData gridData = new GridData( );
		gridData.verticalAlignment = GridData.BEGINNING;
		label.setLayoutData( gridData );
		label.setText( getDisplayName( descriptor ) );

		Control control = descriptor.createControl( this );
		gridData = new GridData( );
//		gridData.grabExcessHorizontalSpace = true;
//		gridData.horizontalAlignment = GridData.FILL;
		gridData.widthHint = 500;
		gridData.grabExcessVerticalSpace = true;
		gridData.verticalAlignment = GridData.FILL;
		control.setLayoutData( gridData );
	}

	private String getDisplayName( IPropertyDescriptor descriptor )
	{
		String name = null;
		PropertyProcessor processor = null;
		if ( descriptor != null )
			processor = descriptor.getPropertyProcessor( );
		if ( processor != null )
			name = processor.getDisplayName( );
		return name == null ? "" : name;//$NON-NLS-1$

	}
}