1 package net.sourceforge.phpdt.sql.wizards;
 
   3 import net.sourceforge.phpdt.sql.IConstants;
 
   4 import net.sourceforge.phpdt.sql.adapters.AdapterFactory;
 
   5 import net.sourceforge.phpdt.sql.adapters.DriverInfo;
 
   6 import net.sourceforge.phpdt.sql.view.BookmarkView;
 
   7 import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
 
   9 import org.eclipse.jface.wizard.Wizard;
 
  10 import org.eclipse.jface.wizard.WizardPage;
 
  11 import org.eclipse.swt.SWT;
 
  12 import org.eclipse.swt.events.SelectionEvent;
 
  13 import org.eclipse.swt.events.SelectionListener;
 
  14 import org.eclipse.swt.layout.GridData;
 
  15 import org.eclipse.swt.layout.GridLayout;
 
  16 import org.eclipse.swt.widgets.Button;
 
  17 import org.eclipse.swt.widgets.Combo;
 
  18 import org.eclipse.swt.widgets.Composite;
 
  19 import org.eclipse.swt.widgets.FileDialog;
 
  20 import org.eclipse.swt.widgets.Label;
 
  21 import org.eclipse.swt.widgets.Text;
 
  23 public class BookmarkWizard extends Wizard implements IConstants {
 
  24   BookmarkPage mainPage;
 
  26   private BookmarkNode current;
 
  28   public void init(BookmarkNode selection) {
 
  30       System.out.println("Initing workbench");
 
  32     this.current = selection;
 
  33     setWindowTitle("New Bookmark");
 
  37       System.out.println("Initing workbench");
 
  40     setWindowTitle("New Bookmark");
 
  42   public boolean performFinish() {
 
  44       System.out.println("perform finish workbench");
 
  46     mainPage.performFinish();
 
  49   public void addPages() {
 
  51       System.out.println("adding pages");
 
  53     if (current != null) {
 
  54       mainPage = new BookmarkPage("Testing...", current);
 
  56       mainPage = new BookmarkPage("Testing...");
 
  60       System.out.println("adding pages");
 
  65 class BookmarkPage extends WizardPage implements IConstants {
 
  66   public static final String ADD = "ADD";
 
  78   BookmarkNode initialData = null;
 
  82   DriverInfo[] drivers = AdapterFactory.getInstance().getDriverList();
 
  84    * Constructor for BookmarkPage.
 
  87   public BookmarkPage(String pageName) {
 
  92    * Constructor for BookmarkPage.
 
  95   public BookmarkPage(String pageName, BookmarkNode bookmark) {
 
  97     this.initialData = bookmark;
 
 100   public void createControl(Composite parent) {
 
 102       System.out.println("page create control");
 
 104     dialog = new FileDialog(getContainer().getShell(), SWT.OPEN);
 
 105     dialog.setFilterExtensions(new String[] { "*.jar", "*.zip", "*.*" });
 
 106     dialog.setFilterNames(
 
 110         "All Files (*.*)" });
 
 111     Composite container = new Composite(parent, SWT.NULL);
 
 112     GridLayout layout = new GridLayout();
 
 113     container.setLayout(layout);
 
 114     layout.numColumns = 2;
 
 115     layout.verticalSpacing = 9;
 
 117     Label label = new Label(container, SWT.NULL);
 
 118     label.setText("*Bookmark Name");
 
 119     name = new Text(container, SWT.BORDER | SWT.SINGLE);
 
 120     GridData fullHorizontal = new GridData();
 
 121     fullHorizontal.horizontalAlignment = GridData.FILL;
 
 122     name.setLayoutData(fullHorizontal);
 
 124     label = new Label(container, SWT.NULL);
 
 125     label.setText("*Username");
 
 126     username = new Text(container, SWT.BORDER | SWT.SINGLE);
 
 127     fullHorizontal = new GridData();
 
 128     fullHorizontal.horizontalAlignment = GridData.FILL;
 
 129     username.setLayoutData(fullHorizontal);
 
 131     label = new Label(container, SWT.NULL);
 
 132     label.setText("*Password");
 
 133     password = new Text(container, SWT.BORDER | SWT.SINGLE);
 
 134     password.setEchoChar('*');
 
 135     fullHorizontal = new GridData();
 
 136     fullHorizontal.horizontalAlignment = GridData.FILL;
 
 137     password.setLayoutData(fullHorizontal);
 
 139     label = new Label(container, SWT.NULL);
 
 140     label.setText("Schema (optional)");
 
 141     schema = new Text(container, SWT.BORDER | SWT.SINGLE);
 
 142     fullHorizontal = new GridData();
 
 143     fullHorizontal.horizontalAlignment = GridData.FILL;
 
 144     schema.setLayoutData(fullHorizontal);
 
 146     label = new Label(container, SWT.NULL);
 
 147     label.setText("*Connect");
 
 148     connect = new Text(container, SWT.BORDER | SWT.SINGLE);
 
 149     fullHorizontal = new GridData();
 
 150     fullHorizontal.horizontalAlignment = GridData.FILL;
 
 151     connect.setLayoutData(fullHorizontal);
 
 153     label = new Label(container, SWT.NULL);
 
 154     label.setText("*Driver");
 
 155     driver = new Text(container, SWT.BORDER | SWT.SINGLE);
 
 156     fullHorizontal = new GridData();
 
 157     fullHorizontal.horizontalAlignment = GridData.FILL;
 
 158     driver.setLayoutData(fullHorizontal);
 
 160     //label = new Label(container, SWT.NULL);
 
 161     //fullHorizontal = new GridData();
 
 162     //fullHorizontal.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
 
 163     //fullHorizontal.verticalSpan = 3;
 
 164     //label.setLayoutData(fullHorizontal);
 
 165     //label.setText("(Drivers Found in File)");
 
 166     /*driverList = new List(container, SWT.SINGLE);
 
 167         fullHorizontal = new GridData();
 
 168     fullHorizontal.horizontalAlignment = GridData.FILL;
 
 169     fullHorizontal.verticalAlignment = GridData.FILL;
 
 170     fullHorizontal.verticalSpan = 3;
 
 171     driverList.setLayoutData(fullHorizontal);
 
 172     driverList.addSelectionListener(new SelectionListener() {
 
 173         public void widgetDefaultSelected(SelectionEvent e) {
 
 175         public void widgetSelected(SelectionEvent e) {
 
 176                 String[] selection = driverList.getSelection();
 
 177                 if (selection != null && selection.length > 0) {
 
 178                         driver.setText(selection[0]);
 
 183     label = new Label(container, SWT.NULL);
 
 184     label.setText("*Type");
 
 185     type = new Combo(container, SWT.SIMPLE | SWT.DROP_DOWN | SWT.READ_ONLY);
 
 186     String driverNames[] = new String[drivers.length];
 
 187     for (int i = 0; i < drivers.length; i++) {
 
 188       driverNames[i] = drivers[i].getDisplayName();
 
 190     type.setItems(driverNames);
 
 192     fullHorizontal = new GridData();
 
 193     fullHorizontal.horizontalAlignment = GridData.FILL;
 
 194     type.setLayoutData(fullHorizontal);
 
 196     label = new Label(container, SWT.NULL);
 
 197     label.setText("*Driver Filename");
 
 198     driverFile = new Text(container, SWT.BORDER | SWT.SINGLE);
 
 199     fullHorizontal = new GridData();
 
 200     fullHorizontal.horizontalAlignment = GridData.FILL;
 
 201     driverFile.setLayoutData(fullHorizontal);
 
 203     Button button = new Button(container, SWT.PUSH);
 
 204     button.setText("Browse...");
 
 206     button.addSelectionListener(new SelectionListener() {
 
 207       public void widgetDefaultSelected(SelectionEvent e) {
 
 209       public void widgetSelected(SelectionEvent e) {
 
 210         String filename = dialog.open();
 
 211         if (filename != null) {
 
 212           driverFile.setText(filename);
 
 216     if (initialData != null) {
 
 217       name.setText(initialData.getName());
 
 218       username.setText(initialData.getUsername());
 
 219       password.setText(initialData.getPassword());
 
 220       schema.setText(initialData.getSchema());
 
 221       connect.setText(initialData.getConnect());
 
 222       driver.setText(initialData.getDriver());
 
 223       String typeData = initialData.getType();
 
 224       int selectedIndex = 0;
 
 225       for (int i = 0; i < drivers.length; i++) {
 
 226         if (typeData.equals(drivers[i].getDriverType())) {
 
 230       type.select(selectedIndex);
 
 231       driverFile.setText(initialData.getDriverFile());
 
 234     setControl(container);
 
 236     setPageComplete(true);
 
 238   public void updateDriverList() {
 
 240         JarFile file = new JarFile(driverFile.getText());
 
 241         Enumeration enum = file.entries();
 
 242         while (enum.hasMoreElements()) {
 
 243                 JarEntry entry = (JarEntry) enum.nextElement();
 
 244                 String className = entry.getName().replace('/', '.');
 
 245                 if (className.endsWith("Driver.class")) {
 
 246                         className = className.substring(0, className.lastIndexOf('.'));
 
 247                         //driverList.add(className);
 
 250     } catch (IOException ex) {
 
 251         //driverList.removeAll();
 
 254   public void performFinish() {
 
 255     if (initialData == null) {
 
 256       initialData = new BookmarkNode();
 
 258     initialData.setName(name.getText());
 
 259     initialData.setUsername(username.getText());
 
 260     initialData.setPassword(password.getText());
 
 261     initialData.setSchema(schema.getText());
 
 262     initialData.setConnect(connect.getText());
 
 263     initialData.setDriver(driver.getText());
 
 264     int selection = type.getSelectionIndex();
 
 265     if (selection >= 0) {
 
 266       initialData.setType(drivers[selection].getDriverType());
 
 268     initialData.setDriverFile(driverFile.getText());
 
 269     BookmarkView.getInstance().addNewBookmark(initialData);