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

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.editor.FormPage;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.help.WorkbenchHelp;

import pl.zalewski.mikolaj.symbdev.ui.SymbdevImages;

/**
 * A superclass for all form pages in the MMP editor
 * 
 * @author mikolaj
 */
public class MMPFormPage extends FormPage {

    /**
     * @param editor
     * @param id
     * @param title
     */
    public MMPFormPage(FormEditor editor, String id, String title) {
        super(editor, id, title);
    }

    /**
     * This default implementation always returns <code>null</code>
     * @return The URL to the help page or <code>null</code> if none 
     */
    public String helpUrl()
    {
        return null;
    }
    
    protected void createFormContent(IManagedForm managedForm)
    {
        final ScrolledForm form=managedForm.getForm();
		final String href = helpUrl();
		if (href != null) {
			IToolBarManager manager = form.getToolBarManager();
			Action helpAction = new Action("help") { //$NON-NLS-1$
				public void run() {
					BusyIndicator.showWhile(form.getDisplay(), new Runnable() {
						public void run() {
							WorkbenchHelp.displayHelpResource(href);
						}
					});
				}
			};
			helpAction.setToolTipText("help");
			helpAction.setImageDescriptor(SymbdevImages.DESC_HELP);
			manager.add(helpAction);
			form.updateToolBar();
		}
		
		GridLayout layout = new GridLayout();
		layout.numColumns = 2;
		layout.marginWidth = 10;
		layout.horizontalSpacing = 15;
		layout.verticalSpacing = 10;
		layout.makeColumnsEqualWidth = true;
		form.getBody().setLayout(layout);		
    }
}
