/*******************************************************************************
 * 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.birt.report.designer.ui.IReportGraphicConstants;
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.core.runtime.Platform;
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.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

/**
 * The general attribute page of Module element.
 */
public class ModulePage extends AttributePage
{

	private Text path;

	/**
	 * 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 ModulePage( 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( 5 ) );

		int comboxWidth;
		if ( Platform.getOS( ).equals( Platform.OS_LINUX ) )
		{
			comboxWidth = 500;
		}
		else
		{
			comboxWidth = 480;
		}
		WidgetUtil.buildGridControl( this,
				propertiesMap,
				ReportDesignConstants.MODULE_ELEMENT,
				ModuleHandle.AUTHOR_PROP,
				3,
				500 );

		WidgetUtil.createGridPlaceholder( this, 1, true );

		WidgetUtil.buildGridControl( this,
				propertiesMap,
				ReportDesignConstants.MODULE_ELEMENT,
				ModuleHandle.CREATED_BY_PROP,
				3,
				500 );

		WidgetUtil.createGridPlaceholder( this, 1, true );

		new Label( this, SWT.NONE ).setText( Messages.getString( "ModulePage.text.Path" ) ); //$NON-NLS-1$
		path = new Text( this, SWT.READ_ONLY | SWT.BORDER );
		GridData gd = new GridData( );
		gd.horizontalSpan = 3;
		gd.widthHint = 500;
		path.setLayoutData( gd );

		WidgetUtil.createGridPlaceholder( this, 1, true );
		WidgetUtil.buildGridControl( this,
				propertiesMap,
				ReportDesignConstants.MODULE_ELEMENT,
				ModuleHandle.TITLE_PROP,
				3,
				500 );

		WidgetUtil.createGridPlaceholder( this, 1, true );

		WidgetUtil.buildGridControl( this,
				propertiesMap,
				ReportDesignConstants.MODULE_ELEMENT,
				ModuleHandle.UNITS_PROP,
				3,
				comboxWidth );

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

		WidgetUtil.buildGridControl( this,
				propertiesMap,
				ReportDesignConstants.MODULE_ELEMENT,
				ModuleHandle.THEME_PROP,
				3,
				comboxWidth + 4 );

		WidgetUtil.createGridPlaceholder( this, 1, true );

		// temp fix for bug 195498
		WidgetUtil.createHorizontalLine( this, 5 );

		WidgetUtil.buildGridControl( this,
				propertiesMap,
				ReportDesignConstants.REPORT_DESIGN_ELEMENT,
				ReportDesignHandle.DISPLAY_NAME_PROP,
				3,
				500 );

		WidgetUtil.createGridPlaceholder( this, 1, true );

	}

	protected void refreshValues( Set propertiesSet )
	{
		super.refreshValues( propertiesSet );
		ModuleHandle handle = (ModuleHandle) input.get( 0 );
		path.setText( handle.getFileName( ) );
	}
}