/*
 * Created on 2004-08-13
 *
 * Part of the Symbian development plug-in for Eclipse
 * Copyright (C) Mikołaj Zalewski, 2004
 */
package pl.zalewski.mikolaj.symbdev.widgets;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

import pl.zalewski.mikolaj.symbdev.SymbdevPlugin;
import pl.zalewski.mikolaj.symbdev.SymbianSDKEntry;
import pl.zalewski.mikolaj.symbdev.SymbianSDKsList;

/**
 * @author mikolaj
 *
 * A dialog a ComboBox to choose the Win32 tool and a ComboBox to
 * choose the SDK
 */
public class ChooseWin32ToolAndSDKDialog extends Dialog {

	/**
	 * @param parentShell the parent shell
	 */
	public ChooseWin32ToolAndSDKDialog(Shell parentShell, boolean allowNone)
	{
		super(parentShell);
		this.allowNone=allowNone;
		SymbianSDKEntry defaultSDK=SymbianSDKsList.getInstance().getDefaultEntry();
		if (defaultSDK!=null)
			sdkResult=defaultSDK.name;
	}
	
	protected Control createDialogArea(Composite parent)
	{
	  	GridData data;
	  	Composite panel=new Composite(parent, SWT.NONE);
	  	
		GridLayout layout= new GridLayout();
		layout.numColumns=1;
		panel.setLayout(layout);
		
		Label l=new Label(panel, SWT.NONE);;
		l.setText("Choose Symbian SDK:");

		comboSdk=new SymbianSDKCombo(panel, SWT.NONE, allowNone);
		data=new GridData(GridData.FILL_HORIZONTAL);
		comboSdk.getComboBox().setLayoutData(data);		
		
		l=new Label(panel, SWT.NONE);
		l.setText("Choose Win32 compilation tool:");
		
		combo=new Win32ToolCombo(panel, SWT.NONE, allowNone);
		data=new GridData(GridData.FILL_HORIZONTAL);
		combo.getComboBox().setLayoutData(data);
		
		comboSdk.setAssociatedCombo(combo);
		
		if (win32ToolResult!=-1)
			combo.setResultId(win32ToolResult);
		 	else win32ToolResult=combo.getResultId();
		
		if (sdkResult!="(none)")
		{
		    comboSdk.setResultName(sdkResult);
		} else sdkResult=comboSdk.getResultName();
		
		return panel;
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
	 */
	protected void okPressed() {
		win32ToolResult=combo.getResultId();
		sdkResult=comboSdk.getResultName();
		super.okPressed();
	}
	public void setWin32ToolResult(int id)
	{
		win32ToolResult=id;
		if (combo!=null)
			combo.setResultId(id);
	}

	public int getWin32ToolResult()
	{
		return win32ToolResult;
	}

	public void setSDKResult(String name)
	{
		sdkResult=name;
		if (comboSdk!=null)
			comboSdk.setResultName(name);
	}	

	public String getSDKResult()
	{
		return sdkResult;
	}	
	
	protected void configureShell(Shell shell) {
	  	super.configureShell(shell);
 		shell.setText(SymbdevPlugin.MESSAGE_TITLE);
	}	
	
	boolean allowNone;
	Win32ToolCombo combo;
	SymbianSDKCombo comboSdk;
	int win32ToolResult=-1;
	String sdkResult="(none)";
}
