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

import org.eclipse.jface.wizard.IWizard;
import org.eclipse.jface.wizard.WizardPage;
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.Label;

import pl.zalewski.mikolaj.symbdev.templates.IProjectTemplate;
import pl.zalewski.mikolaj.symbdev.templates.ISubstitutionOptionsWizardPage;

/**
 * @author mikolaj
 *
 * This implements the last page of the New Project wizard. The
 * main control is obtained from an IProjectTemplate object or
 * is the standard control if the IProjectTemplate returned null
 * @see IProjectTemplate#getWizardContents(IWizard, Composite)
 */
public class TemplateOptionsPage extends WizardPage {

    /**
     * @param pageName
     */
    public TemplateOptionsPage(String pageName) {
        super(pageName);
        setTitle("Template Options");
    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
     */
    public void createControl(Composite parent)
    {
        fMainContainer=new Composite(parent, SWT.NONE);
        GridData data=new GridData(GridData.FILL_BOTH);
        fMainContainer.setLayoutData(data);
        GridLayout layout=new GridLayout(1, false);
        fMainContainer.setLayout(layout);
        setControl(fMainContainer);
        
        fMainControl=null;
        if (fProvider!=null)
            fMainControl=fProvider.getWizardContents(this, fMainContainer);
        if (fMainControl==null)
            fMainControl=getDefaultMain(fMainContainer);
    }
    
    public void setWizardContentProvider(IWizardContentProvider provider) {
        fProvider=provider;
        if (fMainContainer!=null)
        {
            fMainControl.dispose();
            fMainControl=provider.getWizardContents(this, fMainContainer);
            if (fMainControl==null)
                fMainControl=getDefaultMain(fMainContainer);
            fMainContainer.layout();
        }        
    }
    
    public void setSubstitutionsPage(ISubstitutionOptionsWizardPage page) {
        
    }

    protected Composite getDefaultMain(Composite parent)
    {
        Composite panel=new Composite(parent, SWT.NONE);
        GridLayout layout=new GridLayout(1, false);
        panel.setLayout(layout);
        GridData data;
        Label l=new Label(panel, SWT.NONE);
        l.setText("Click Finish to create the project.");
        setPageComplete(true);
        setErrorMessage(null);        
        return panel;        
    }    
    
    Composite fMainContainer;
    Composite fMainControl;
    IWizardContentProvider fProvider;
}
