package net.sourceforge.phpeclipse.preferences;

import net.sourceforge.phpeclipse.IPreferenceConstants;
import net.sourceforge.phpeclipse.PHPeclipsePlugin;

import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.preference.RadioGroupFieldEditor;
import org.eclipse.jface.preference.StringFieldEditor;
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.Group;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;

public class PHPEclipseParserPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {

//  private SelectionListener SelectionListener;
//  private ModifyListener ModifyListener;
//  private ModifyListener TextModifyListener;
//
//  private ArrayList CheckBoxes = new ArrayList();
//  private ArrayList ComboBoxes = new ArrayList();
//  private ArrayList TextBoxes = new ArrayList();
//  private ArrayList RadioButtons = new ArrayList();


//  RadioGroupFieldEditor chooseParser;
  StringFieldEditor externalParserSFE;
 // BooleanFieldEditor parseOnSave;

  public PHPEclipseParserPreferencePage() {
    super();
    setPreferenceStore(PHPeclipsePlugin.getDefault().getPreferenceStore());
    setDescription(PHPPreferencesMessages.getString("PHPBasePreferencePage.description")); //$NON-NLS-1$
  }
  
  public void init(IWorkbench workbench) {
  }
  protected void performDefaults() {
//    chooseParser.loadDefault();
    externalParserSFE.loadDefault();
//    parseOnSave.loadDefault();
    super.performDefaults();
  }

  public boolean performOk() {
//    chooseParser.store();
    externalParserSFE.store();
//    parseOnSave.store();
    return super.performOk();
  }

  protected Control createContents(Composite parent) {
    initializeDialogUnits(parent);
    final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
    Composite composite = new Composite(parent, SWT.LEFT);
    composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    composite.setLayout(new GridLayout());

    //Create parser settings composite
    Composite parserSettingsComposite = new Composite(composite, SWT.NONE);
    parserSettingsComposite.setLayout(new GridLayout());
    parserSettingsComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    Group parserSettingsGroup = new Group(parserSettingsComposite, SWT.NONE);
    parserSettingsGroup.setText(PHPPreferencesMessages.getString("PHPBasePreferencePage.parsers"));
    parserSettingsGroup.setLayout(new GridLayout());
    parserSettingsGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

//    chooseParser =
//      new RadioGroupFieldEditor(
//        IPreferenceConstants.PHP_PARSER_DEFAULT,
//        PHPPreferencesMessages.getString("PHPBasePreferencePage.parsers.choose"),
//        1,
//        new String[][] {
//          { PHPPreferencesMessages.getString("PHPBasePreferencePage.parsers.internal"), IPreferenceConstants.PHP_INTERNAL_PARSER },
//          {
//        PHPPreferencesMessages.getString("PHPBasePreferencePage.parsers.external"), IPreferenceConstants.PHP_EXTERNAL_PARSER }
//    }, parserSettingsGroup);
//    chooseParser.setPreferencePage(this);
//    chooseParser.setPreferenceStore(getPreferenceStore());
//    chooseParser.load();
    //create a copmposte just for the StringEditor - makes layout simpler
    Composite externalParserCompo = new Composite(parserSettingsGroup, SWT.NONE);
    externalParserSFE =
      new StringFieldEditor(
        IPreferenceConstants.EXTERNAL_PARSER_PREF,
        PHPPreferencesMessages.getString("PHPBasePreferencePage.parsers.extcommand"),
        externalParserCompo
    /*parserSettingsGroup*/
    );
    externalParserSFE.setPreferencePage(this);
    externalParserSFE.setPreferenceStore(getPreferenceStore());
    externalParserSFE.load();

//    parseOnSave =
//      new BooleanFieldEditor(
//        PHPeclipsePlugin.PHP_PARSE_ON_SAVE,
//        PHPPreferencesMessages.getString("PHPBasePreferencePage.parsers.pos"),
//        parserSettingsGroup);
//    parseOnSave.setPreferencePage(this);
//    parseOnSave.setPreferenceStore(getPreferenceStore());
//    parseOnSave.load();

    return composite;
  }
}