/*******************************************************************************
 * 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.List;

import org.eclipse.birt.report.designer.internal.ui.dialogs.resource.NewResourceFileDialog;
import org.eclipse.birt.report.designer.internal.ui.views.attributes.provider.JarFileFormProvider;
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.ModuleHandle;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.elements.ReportDesignConstants;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;

/**
 * 
 */

public class ResourcesPage extends AttributePage
{

	/**
	 * SWT widgets presented JAR files of Table element
	 */
	private JarFileFormPage JarFilePage;

	/**
	 * @param parent
	 * @param style
	 */
	public ResourcesPage( Composite parent, int style )
	{
		super( parent, style );
		// TODO Auto-generated constructor stub
	}

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

		WidgetUtil.buildGridControl( this,
				propertiesMap,
				ReportDesignConstants.MODULE_ELEMENT,
				ModuleHandle.INCLUDE_RESOURCE_PROP,
				2,
				335 );
		final Text resourceText = (Text) ( (IPropertyDescriptor) propertiesMap.get( ReportDesignHandle.INCLUDE_RESOURCE_PROP ) ).getControl( );

		Button btn = new Button( this, SWT.PUSH );
		btn.setText( Messages.getString( "ReportPage.text.Resource.Add" ) ); //$NON-NLS-1$
		GridData data = new GridData( );
		data.widthHint = Math.max( btn.computeSize( -1, -1 ).x, 60 );
		btn.setLayoutData( data );

		btn.addSelectionListener( new SelectionAdapter( ) {

			public void widgetSelected( SelectionEvent e )
			{
				final NewResourceFileDialog dialog = new NewResourceFileDialog( );
				if ( dialog.open( ) == Window.OK )
				{
					resourceText.setText( dialog.getPath( ).substring( 0,
							dialog.getPath( ).lastIndexOf( "." ) ) ); //$NON-NLS-1$
					resourceText.setFocus( );
				}
			}
		} );

		WidgetUtil.createGridPlaceholder( this, 1, true );
		WidgetUtil.createHorizontalLine( this, 5 );

		Composite jarFileParent = new Composite( this, SWT.NONE );
		data = new GridData( GridData.FILL_VERTICAL );
		data.horizontalSpan = 4;
		data.horizontalIndent = -10;
		data.heightHint = 200;
		jarFileParent.setLayoutData( data );
		jarFileParent.setLayout( new GridLayout( ) );;
		if ( JarFilePage == null )
		{
			JarFilePage = new JarFileFormPage( jarFileParent,
					new JarFileFormProvider( ) );
		}
		JarFilePage.setLayoutData( new GridData( GridData.FILL_BOTH ) );

	}

	public void setInput( List elements )
	{
		super.setInput( elements );
		JarFilePage.setInput( input );
	}
}
