package com.quantum.php.preferences;

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

import com.quantum.QuantumPlugin;

public class PHPSQLConnectionPreferencePage
  extends PreferencePage
  implements IWorkbenchPreferencePage {

  StringFieldEditor fUserNameSFE;
  StringFieldEditor fConnectSFE;
  StringFieldEditor fDriverSFE;
  StringFieldEditor fTypeSFE;
  StringFieldEditor fDriverFileFFE;

  public PHPSQLConnectionPreferencePage() {
	super();
	setPreferenceStore(QuantumPlugin.getDefault().getPreferenceStore());
  }
  public void init(IWorkbench workbench) {
	setPreferenceStore(QuantumPlugin.getDefault().getPreferenceStore());
  }
  protected void performDefaults() {
	fUserNameSFE.loadDefault();
	fConnectSFE.loadDefault();
	fDriverSFE.loadDefault();
	fTypeSFE.loadDefault();
	fDriverFileFFE.loadDefault();
	super.performDefaults();
  }

  public boolean performOk() {
	fUserNameSFE.store();
	fConnectSFE.store();
	fDriverSFE.store();
	fTypeSFE.store();
	fDriverFileFFE.store();
	return super.performOk();
  }

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

	fUserNameSFE =
	  new StringFieldEditor(
		"phpeclipse.sql.username.connect",
		"Default User name:",
		composite);
	fUserNameSFE.setPreferencePage(this);
	fUserNameSFE.setPreferenceStore(getPreferenceStore());
	fUserNameSFE.load();

	fConnectSFE =
	  new StringFieldEditor(
		"phpeclipse.sql.connect.connect",
		"Connect:",
		composite);
	fConnectSFE.setPreferencePage(this);
	fConnectSFE.setPreferenceStore(getPreferenceStore());
	fConnectSFE.load();

	fDriverSFE =
	  new StringFieldEditor(
		"phpeclipse.sql.driver.connect",
		"Driver:",
		composite);
	fDriverSFE.setPreferencePage(this);
	fDriverSFE.setPreferenceStore(getPreferenceStore());
	fDriverSFE.load();

	fTypeSFE =
	  new StringFieldEditor("phpeclipse.sql.type.connect", "Type:", composite);
	fTypeSFE.setPreferencePage(this);
	fTypeSFE.setPreferenceStore(getPreferenceStore());
	fTypeSFE.load();

	//    fDriverFileFFE =
	//      new FileFieldEditor(
	//        "phpeclipse.sql.filename.connect",
	//        "Driver filename:",
	//        composite);
	fDriverFileFFE =
	  new StringFieldEditor(
		"phpeclipse.sql.filename.connect",
		"Driver filename:",
		composite);
	fDriverFileFFE.setPreferencePage(this);
	fDriverFileFFE.setPreferenceStore(getPreferenceStore());
	fDriverFileFFE.load();

	return composite;
  }
}