/*******************************************************************************
 * 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.designer.nls.Messages;
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 abstract class of i18n pages
 */

public abstract class I18nPage extends AttributePage
{

	private static final String MESSAGE_NOTE = Messages.getString( "I18nPage.text.Note" ); //$NON-NLS-1$

	/**
	 * The element name
	 */
	protected String elementName;
	/**
	 * The property name
	 */
	protected String propertyName;

	/**
	 * Constructor
	 * 
	 * @param parent
	 *            An widget which will be the parent of the new instance (cannot
	 *            be null)
	 * @param style
	 *            The style of widget to construct
	 */
	public I18nPage( Composite parent, int style )
	{
		super( parent, style );
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.birt.designer.internal.ui.views.attributes.page.AttributePage#buildUI()
	 */
	protected void buildUI( )
	{
		setLayout( WidgetUtil.createGridLayout( 5 ) );
		WidgetUtil.buildGridControl( this,
				propertiesMap,
				elementName,
				propertyName,
				1,
				true );

		WidgetUtil.createGridPlaceholder( this, 3, true );

		Label lb = new Label( this, SWT.NONE | SWT.WRAP );
		lb.setText( MESSAGE_NOTE );
		GridData data = new GridData( GridData.FILL_BOTH );
		data.horizontalSpan = 2;
		data.widthHint = 0;
		lb.setLayoutData( data );
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.birt.designer.internal.ui.views.attributes.page.AttributePage#refreshValues(java.util.Set)
	 */
	protected void refreshValues( Set propertiesSet )
	{
		boolean enable = input.size( ) == 1;
		Control[] controls = this.getChildren( );
		for ( int i = 0; i < controls.length; i++ )
		{
			controls[i].setEnabled( enable );
		}
		super.refreshValues( propertiesSet );
	}
}