package net.sourceforge.phpdt.sql.wizards;
+import net.sourceforge.phpdt.sql.IConstants;
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
+import net.sourceforge.phpdt.sql.adapters.AdapterFactory;
+import net.sourceforge.phpdt.sql.adapters.DriverInfo;
+import net.sourceforge.phpdt.sql.view.BookmarkView;
+import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
+
+import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
-import net.sourceforge.phpdt.sql.adapters.AdapterFactory;
-import net.sourceforge.phpdt.sql.adapters.DriverInfo;
-import net.sourceforge.phpdt.sql.view.BookmarkView;
-import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
+public class BookmarkWizard extends Wizard implements IConstants {
+ BookmarkPage mainPage;
+
+ private BookmarkNode current;
+
+ public void init(BookmarkNode selection) {
+ if (DEBUG) {
+ System.out.println("Initing workbench");
+ }
+ this.current = selection;
+ setWindowTitle("New Bookmark");
+ }
+
+ public void init() {
+ if (DEBUG) {
+ System.out.println("Initing workbench");
+ }
+ current = null;
+ setWindowTitle("New Bookmark");
+ }
-public class BookmarkWizard extends Wizard {
- BookmarkPage mainPage;
-
- private BookmarkNode current;
-
- public void init(BookmarkNode selection) {
- System.out.println("Initing workbench");
- this.current = selection;
- setWindowTitle("New Bookmark");
- }
- public void init() {
- System.out.println("Initing workbench");
- current = null;
- setWindowTitle("New Bookmark");
- }
- public boolean performFinish() {
- System.out.println("perform finish workbench");
- mainPage.performFinish();
- return true;
- }
- public void addPages() {
- System.out.println("adding pages");
- if (current != null) {
- mainPage = new BookmarkPage("Testing...", current);
- } else {
- mainPage = new BookmarkPage("Testing...");
- }
- addPage(mainPage);
- System.out.println("adding pages");
- }
+ public boolean performFinish() {
+ if (DEBUG) {
+ System.out.println("perform finish workbench");
+ }
+ mainPage.performFinish();
+ return true;
+ }
+
+ public void addPages() {
+ if (DEBUG) {
+ System.out.println("adding pages");
+ }
+ if (current != null) {
+ mainPage = new BookmarkPage("Testing...", current);
+ } else {
+ mainPage = new BookmarkPage("Testing...");
+ }
+ addPage(mainPage);
+ if (DEBUG) {
+ System.out.println("adding pages");
+ }
+ }
}
-class BookmarkPage extends WizardPage {
- public static final String ADD = "ADD";
- String action = ADD;
- Text name;
- Text username;
- Text password;
- Text schema;
- Text connect;
- Text driver;
- //List driverList;
- Combo type;
- Text driverFile;
-
- BookmarkNode initialData = null;
-
- FileDialog dialog;
-
- DriverInfo[] drivers = AdapterFactory.getInstance().getDriverList();
- /**
- * Constructor for BookmarkPage.
- * @param pageName
- */
- public BookmarkPage(String pageName) {
- super(pageName);
- initialData = null;
- }
- /**
- * Constructor for BookmarkPage.
- * @param pageName
- */
- public BookmarkPage(String pageName, BookmarkNode bookmark) {
- super(pageName);
- this.initialData = bookmark;
- }
-
- public void createControl(Composite parent) {
- System.out.println("page create control");
- dialog = new FileDialog(getContainer().getShell(), SWT.OPEN);
- dialog.setFilterExtensions(new String[]{"*.jar", "*.zip","*.*"});
- dialog.setFilterNames(new String[]{"Jar Files (*.jar)","Zip Files (*.zip)", "All Files (*.*)"});
- Composite container = new Composite(parent, SWT.NULL);
- GridLayout layout = new GridLayout();
- container.setLayout(layout);
- layout.numColumns = 2;
- layout.verticalSpacing = 9;
-
-
- Label label = new Label(container, SWT.NULL);
- label.setText("*Bookmark Name");
- name = new Text(container, SWT.BORDER | SWT.SINGLE);
- GridData fullHorizontal = new GridData();
- fullHorizontal.horizontalAlignment = GridData.FILL;
- name.setLayoutData(fullHorizontal);
-
- label = new Label(container, SWT.NULL);
- label.setText("*Username");
- username = new Text(container, SWT.BORDER | SWT.SINGLE);
- fullHorizontal = new GridData();
- fullHorizontal.horizontalAlignment = GridData.FILL;
- username.setLayoutData(fullHorizontal);
-
- label = new Label(container, SWT.NULL);
- label.setText("*Password");
- password = new Text(container, SWT.BORDER | SWT.SINGLE);
- password.setEchoChar('*');
- fullHorizontal = new GridData();
- fullHorizontal.horizontalAlignment = GridData.FILL;
- password.setLayoutData(fullHorizontal);
-
- label = new Label(container, SWT.NULL);
- label.setText("Schema (optional)");
- schema = new Text(container, SWT.BORDER | SWT.SINGLE);
- fullHorizontal = new GridData();
- fullHorizontal.horizontalAlignment = GridData.FILL;
- schema.setLayoutData(fullHorizontal);
-
- label = new Label(container, SWT.NULL);
- label.setText("*Connect");
- connect = new Text(container, SWT.BORDER | SWT.SINGLE);
- fullHorizontal = new GridData();
- fullHorizontal.horizontalAlignment = GridData.FILL;
- connect.setLayoutData(fullHorizontal);
-
- label = new Label(container, SWT.NULL);
- label.setText("*Driver");
- driver = new Text(container, SWT.BORDER | SWT.SINGLE);
- fullHorizontal = new GridData();
- fullHorizontal.horizontalAlignment = GridData.FILL;
- driver.setLayoutData(fullHorizontal);
-
- //label = new Label(container, SWT.NULL);
- //fullHorizontal = new GridData();
- //fullHorizontal.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
- //fullHorizontal.verticalSpan = 3;
- //label.setLayoutData(fullHorizontal);
- //label.setText("(Drivers Found in File)");
- /*driverList = new List(container, SWT.SINGLE);
- fullHorizontal = new GridData();
- fullHorizontal.horizontalAlignment = GridData.FILL;
- fullHorizontal.verticalAlignment = GridData.FILL;
- fullHorizontal.verticalSpan = 3;
- driverList.setLayoutData(fullHorizontal);
- driverList.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- }
- public void widgetSelected(SelectionEvent e) {
- String[] selection = driverList.getSelection();
- if (selection != null && selection.length > 0) {
- driver.setText(selection[0]);
- }
- }
- });*/
-
- label = new Label(container, SWT.NULL);
- label.setText("*Type");
- type = new Combo(container, SWT.SIMPLE | SWT.DROP_DOWN | SWT.READ_ONLY);
- String driverNames[] = new String[drivers.length];
- for (int i = 0; i < drivers.length; i++) {
- driverNames[i] = drivers[i].getDisplayName();
- }
- type.setItems(driverNames);
- type.select(0);
- fullHorizontal = new GridData();
- fullHorizontal.horizontalAlignment = GridData.FILL;
- type.setLayoutData(fullHorizontal);
-
- label = new Label(container, SWT.NULL);
- label.setText("*Driver Filename");
- driverFile = new Text(container, SWT.BORDER | SWT.SINGLE);
- fullHorizontal = new GridData();
- fullHorizontal.horizontalAlignment = GridData.FILL;
- driverFile.setLayoutData(fullHorizontal);
-
- Button button = new Button(container, SWT.PUSH);
- button.setText("Browse...");
-
- button.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- }
- public void widgetSelected(SelectionEvent e) {
- String filename = dialog.open();
- if (filename != null) {
- driverFile.setText(filename);
- }
- }
- });
- if (initialData != null) {
- name.setText(initialData.getName());
- username.setText(initialData.getUsername());
- password.setText(initialData.getPassword());
- schema.setText(initialData.getSchema());
- connect.setText(initialData.getConnect());
- driver.setText(initialData.getDriver());
- String typeData = initialData.getType();
- int selectedIndex = 0;
- for (int i = 0; i < drivers.length; i++) {
- if (typeData.equals(drivers[i].getDriverType())) {
- selectedIndex = i;
- }
- }
- type.select(selectedIndex);
- driverFile.setText(initialData.getDriverFile());
- updateDriverList();
- }
- setControl(container);
-
- setPageComplete(true);
- }
- public void updateDriverList() {
- /*try {
- JarFile file = new JarFile(driverFile.getText());
- Enumeration enum = file.entries();
- while (enum.hasMoreElements()) {
- JarEntry entry = (JarEntry) enum.nextElement();
- String className = entry.getName().replace('/', '.');
- if (className.endsWith("Driver.class")) {
- className = className.substring(0, className.lastIndexOf('.'));
- //driverList.add(className);
- }
- }
- } catch (IOException ex) {
- //driverList.removeAll();
- }*/
- }
- public void performFinish() {
- if (initialData == null) {
- initialData = new BookmarkNode();
- }
- initialData.setName(name.getText());
- initialData.setUsername(username.getText());
- initialData.setPassword(password.getText());
- initialData.setSchema(schema.getText());
- initialData.setConnect(connect.getText());
- initialData.setDriver(driver.getText());
- int selection = type.getSelectionIndex();
- if (selection >= 0) {
- initialData.setType(drivers[selection].getDriverType());
- }
- initialData.setDriverFile(driverFile.getText());
- BookmarkView.getInstance().addNewBookmark(initialData);
- }
+class BookmarkPage extends WizardPage implements IConstants {
+ public static final String ADD = "ADD";
+ String action = ADD;
+ Text name;
+ Text username;
+ Text password;
+ Text schema;
+ Text connect;
+ Text driver;
+ //List driverList;
+ Combo type;
+ Text driverFile;
+
+ BookmarkNode initialData = null;
+
+ FileDialog dialog;
+
+ DriverInfo[] drivers = AdapterFactory.getInstance().getDriverList();
+ /**
+ * Constructor for BookmarkPage.
+ * @param pageName
+ */
+ public BookmarkPage(String pageName) {
+ super(pageName);
+ initialData = null;
+ }
+ /**
+ * Constructor for BookmarkPage.
+ * @param pageName
+ */
+ public BookmarkPage(String pageName, BookmarkNode bookmark) {
+ super(pageName);
+ this.initialData = bookmark;
+ }
+
+ public void createControl(Composite parent) {
+ if (DEBUG) {
+ System.out.println("page create control");
+ }
+ dialog = new FileDialog(getContainer().getShell(), SWT.OPEN);
+ dialog.setFilterExtensions(new String[] { "*.jar", "*.zip", "*.*" });
+ dialog.setFilterNames(
+ new String[] {
+ "Jar Files (*.jar)",
+ "Zip Files (*.zip)",
+ "All Files (*.*)" });
+ Composite container = new Composite(parent, SWT.NULL);
+ GridLayout layout = new GridLayout();
+ container.setLayout(layout);
+ layout.numColumns = 2;
+ layout.verticalSpacing = 9;
+
+ Label label = new Label(container, SWT.NULL);
+ label.setText("*Bookmark Name");
+ name = new Text(container, SWT.BORDER | SWT.SINGLE);
+ GridData fullHorizontal = new GridData();
+ fullHorizontal.horizontalAlignment = GridData.FILL;
+ name.setLayoutData(fullHorizontal);
+
+ label = new Label(container, SWT.NULL);
+ label.setText("*Username");
+ username = new Text(container, SWT.BORDER | SWT.SINGLE);
+ fullHorizontal = new GridData();
+ fullHorizontal.horizontalAlignment = GridData.FILL;
+ username.setLayoutData(fullHorizontal);
+
+ label = new Label(container, SWT.NULL);
+ label.setText("*Password");
+ password = new Text(container, SWT.BORDER | SWT.SINGLE);
+ password.setEchoChar('*');
+ fullHorizontal = new GridData();
+ fullHorizontal.horizontalAlignment = GridData.FILL;
+ password.setLayoutData(fullHorizontal);
+
+ label = new Label(container, SWT.NULL);
+ label.setText("Schema (optional)");
+ schema = new Text(container, SWT.BORDER | SWT.SINGLE);
+ fullHorizontal = new GridData();
+ fullHorizontal.horizontalAlignment = GridData.FILL;
+ schema.setLayoutData(fullHorizontal);
+
+ label = new Label(container, SWT.NULL);
+ label.setText("*Connect");
+ connect = new Text(container, SWT.BORDER | SWT.SINGLE);
+ fullHorizontal = new GridData();
+ fullHorizontal.horizontalAlignment = GridData.FILL;
+ connect.setLayoutData(fullHorizontal);
+
+ label = new Label(container, SWT.NULL);
+ label.setText("*Driver");
+ driver = new Text(container, SWT.BORDER | SWT.SINGLE);
+ fullHorizontal = new GridData();
+ fullHorizontal.horizontalAlignment = GridData.FILL;
+ driver.setLayoutData(fullHorizontal);
+
+ //label = new Label(container, SWT.NULL);
+ //fullHorizontal = new GridData();
+ //fullHorizontal.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
+ //fullHorizontal.verticalSpan = 3;
+ //label.setLayoutData(fullHorizontal);
+ //label.setText("(Drivers Found in File)");
+ /*driverList = new List(container, SWT.SINGLE);
+ fullHorizontal = new GridData();
+ fullHorizontal.horizontalAlignment = GridData.FILL;
+ fullHorizontal.verticalAlignment = GridData.FILL;
+ fullHorizontal.verticalSpan = 3;
+ driverList.setLayoutData(fullHorizontal);
+ driverList.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ String[] selection = driverList.getSelection();
+ if (selection != null && selection.length > 0) {
+ driver.setText(selection[0]);
+ }
+ }
+ });*/
+
+ label = new Label(container, SWT.NULL);
+ label.setText("*Type");
+ type = new Combo(container, SWT.SIMPLE | SWT.DROP_DOWN | SWT.READ_ONLY);
+ String driverNames[] = new String[drivers.length];
+ for (int i = 0; i < drivers.length; i++) {
+ driverNames[i] = drivers[i].getDisplayName();
+ }
+ type.setItems(driverNames);
+ type.select(0);
+ fullHorizontal = new GridData();
+ fullHorizontal.horizontalAlignment = GridData.FILL;
+ type.setLayoutData(fullHorizontal);
+
+ label = new Label(container, SWT.NULL);
+ label.setText("*Driver Filename");
+ driverFile = new Text(container, SWT.BORDER | SWT.SINGLE);
+ fullHorizontal = new GridData();
+ fullHorizontal.horizontalAlignment = GridData.FILL;
+ driverFile.setLayoutData(fullHorizontal);
+
+ Button button = new Button(container, SWT.PUSH);
+ button.setText("Browse...");
+
+ button.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ String filename = dialog.open();
+ if (filename != null) {
+ driverFile.setText(filename);
+ }
+ }
+ });
+ if (initialData != null) {
+ name.setText(initialData.getName());
+ username.setText(initialData.getUsername());
+ password.setText(initialData.getPassword());
+ schema.setText(initialData.getSchema());
+ connect.setText(initialData.getConnect());
+ driver.setText(initialData.getDriver());
+ String typeData = initialData.getType();
+ int selectedIndex = 0;
+ for (int i = 0; i < drivers.length; i++) {
+ if (typeData.equals(drivers[i].getDriverType())) {
+ selectedIndex = i;
+ }
+ }
+ type.select(selectedIndex);
+ driverFile.setText(initialData.getDriverFile());
+ updateDriverList();
+ } else {
+
+ IPreferenceStore fStore =
+ PHPEclipseSQLPlugin.getDefault().getPreferenceStore();
+ username.setText(fStore.getString("phpeclipse.sql.username.connect"));
+ connect.setText(fStore.getString("phpeclipse.sql.connect.connect"));
+ driver.setText(fStore.getString("phpeclipse.sql.driver.connect"));
+ String typeData = fStore.getString("phpeclipse.sql.type.connect");
+ int selectedIndex = 0;
+ for (int i = 0; i < drivers.length; i++) {
+ if (typeData.equals(drivers[i].getDisplayName())) {
+ selectedIndex = i;
+ }
+ }
+ type.select(selectedIndex);
+ driverFile.setText(fStore.getString("phpeclipse.sql.filename.connect"));
+ // updateDriverList();
+ }
+ setControl(container);
+
+ setPageComplete(true);
+ }
+ public void updateDriverList() {
+ /*try {
+ JarFile file = new JarFile(driverFile.getText());
+ Enumeration enum = file.entries();
+ while (enum.hasMoreElements()) {
+ JarEntry entry = (JarEntry) enum.nextElement();
+ String className = entry.getName().replace('/', '.');
+ if (className.endsWith("Driver.class")) {
+ className = className.substring(0, className.lastIndexOf('.'));
+ //driverList.add(className);
+ }
+ }
+ } catch (IOException ex) {
+ //driverList.removeAll();
+ }*/
+ }
+ public void performFinish() {
+ if (initialData == null) {
+ initialData = new BookmarkNode();
+ }
+ initialData.setName(name.getText());
+ initialData.setUsername(username.getText());
+ initialData.setPassword(password.getText());
+ initialData.setSchema(schema.getText());
+ initialData.setConnect(connect.getText());
+ initialData.setDriver(driver.getText());
+ int selection = type.getSelectionIndex();
+ if (selection >= 0) {
+ initialData.setType(drivers[selection].getDriverType());
+ }
+ initialData.setDriverFile(driverFile.getText());
+ BookmarkView.getInstance().addNewBookmark(initialData);
+ }
}
\ No newline at end of file