show HTML files as local resources (no 'http://' url prefix)
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / wizards / BookmarkWizard.java
index 201c58d..5ba3d54 100644 (file)
 package com.quantum.wizards;
 
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.preference.IPreferenceStore;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
 import org.eclipse.jface.wizard.Wizard;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.FileDialog;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Text;
 
 import com.quantum.Messages;
-import com.quantum.QuantumPlugin;
-import com.quantum.adapters.AdapterFactory;
-import com.quantum.adapters.DriverInfo;
 import com.quantum.model.Bookmark;
 import com.quantum.model.BookmarkCollection;
 import com.quantum.model.JDBCDriver;
+import com.quantum.model.Schema;
 
-public class BookmarkWizard extends Wizard {
-       BookmarkPage mainPage;
+public class BookmarkWizard extends Wizard implements PropertyChangeListener {
+       private JDBCDriverSelectionWizardPage page1;
+       private BookmarkConnectionWizardPage page2;
+       private BookmarkNameWizardPage page3;
+       private SchemaSelectionWizardPage page4;
 
+       private Bookmark bookmark;
+       
        public void init() {
-               System.out.println("Initing workbench"); //$NON-NLS-1$
                setWindowTitle(Messages.getString("BookmarkWizard.NewBookmark")); //$NON-NLS-1$
+               this.bookmark = new Bookmark();
        }
        public boolean performFinish() {
-               System.out.println("perform finish workbench"); //$NON-NLS-1$
-               String bookmarkName = mainPage.name.getText();
-               if ( BookmarkCollection.getInstance().find(bookmarkName) != null){
-                       MessageDialog.openInformation(
-                               this.getShell(),Messages.getString("BookmarkWizard.Error"),Messages.getString("BookmarkWizard.bookmarkAlreadyExists"));  //$NON-NLS-1$ //$NON-NLS-2$
-                               return false;
-               }
-
-               mainPage.performFinish();
+               BookmarkCollection.getInstance().addBookmark(this.bookmark);
+               
                return true;
        }
        public void addPages() {
-               System.out.println("adding pages"); //$NON-NLS-1$
-//             WizardPage page = new NewBookmarkPage1(Messages.getString("BookmarkWizard.Testing")); //$NON-NLS-1$
-//             addPage(page);
-               mainPage = new BookmarkPage(Messages.getString("BookmarkWizard.Testing")); //$NON-NLS-1$
-               addPage(mainPage);
-               System.out.println("adding pages"); //$NON-NLS-1$
-       }
-}
-
-class BookmarkPage extends WizardPage {
-       public static final String ADD = "ADD"; //$NON-NLS-1$
-       String action = ADD;
-       Text name;
-       Text username;
-       Text password;
-       Text schema;
-       Text connect;
-       Text driver;
-       //List driverList;
-       Combo type;
-       Text driverFile;
-    Button prompt;
-
-       FileDialog dialog;
-
-       DriverInfo[] drivers = AdapterFactory.getInstance().getDriverList();
-       /**
-        * Constructor for BookmarkPage.
-        * @param pageName
-        */
-       public BookmarkPage(String pageName) {
-               super(pageName);
+               this.page1 = new JDBCDriverSelectionWizardPage("page1"); //$NON-NLS-1$
+               this.page1.addPropertyChangeListener(this);
+               addPage(this.page1);
+               this.page2 = new BookmarkConnectionWizardPage("page2"); //$NON-NLS-1$
+               this.page2.addPropertyChangeListener(this);
+               addPage(this.page2);
+               this.page3 = new BookmarkNameWizardPage("page3"); //$NON-NLS-1$
+               this.page3.addPropertyChangeListener(this);
+               addPage(this.page3);
+               this.page4 = new SchemaSelectionWizardPage("page4", this.bookmark); //$NON-NLS-1$
+               this.page4.addPropertyChangeListener(this);
+               addPage(this.page4);
        }
-       public void createControl(Composite parent) {
-               System.out.println("page create control"); //$NON-NLS-1$
-               dialog = new FileDialog(getContainer().getShell(), SWT.OPEN);
-               dialog.setFilterExtensions(new String[]{"*.jar", "*.zip","*.*"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-               dialog.setFilterNames(new String[]{Messages.getString("BookmarkWizard.JarFiles"),Messages.getString("BookmarkWizard.ZipFiles"), Messages.getString("BookmarkWizard.AllFiles")}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-               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(Messages.getString("BookmarkWizard.BookmarkNameAst")); //$NON-NLS-1$
-               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(Messages.getString("BookmarkWizard.UsernameAst")); //$NON-NLS-1$
-               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(Messages.getString("BookmarkWizard.PasswordAst")); //$NON-NLS-1$
-               password = new Text(container, SWT.BORDER | SWT.SINGLE);
-               password.setEchoChar('*');
-               fullHorizontal = new GridData();
-               fullHorizontal.horizontalAlignment = GridData.FILL;
-               password.setLayoutData(fullHorizontal);
-        this.prompt = new Button(container, SWT.CHECK);
-        this.prompt.setText(Messages.getString("BookmarkWizard.Prompt")); //$NON-NLS-1$
-        fullHorizontal = new GridData();
-        fullHorizontal.horizontalAlignment = GridData.FILL;
-        fullHorizontal.horizontalSpan = 2;
-        this.prompt.setLayoutData(fullHorizontal);
-               label = new Label(container, SWT.NULL);
-               label.setText(Messages.getString("BookmarkWizard.Schema")); //$NON-NLS-1$
-               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(Messages.getString("BookmarkWizard.ConnectAst")); //$NON-NLS-1$
-               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(Messages.getString("BookmarkWizard.DriverAst")); //$NON-NLS-1$
-               driver = new Text(container, SWT.BORDER | SWT.SINGLE);
-               fullHorizontal = new GridData();
-               fullHorizontal.horizontalAlignment = GridData.FILL;
-               driver.setLayoutData(fullHorizontal);
-
-               label = new Label(container, SWT.NULL);
-               label.setText(Messages.getString("BookmarkWizard.TypeAst")); //$NON-NLS-1$
-               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(Messages.getString("BookmarkWizard.DriverFilenameAst")); //$NON-NLS-1$
-               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(Messages.getString("BookmarkWizard.Browse")); //$NON-NLS-1$
-               
-               button.addSelectionListener(new SelectionListener() {
-                       public void widgetDefaultSelected(SelectionEvent e) {
-                       }
-                       public void widgetSelected(SelectionEvent e) {
-                               // We retrieve the last saved path
-                               dialog.setFilterPath(QuantumPlugin.getDefault().getPreferenceStore().getString("quantum.dialogs.bookmarkwizard.path")); //$NON-NLS-1$
-                               String filename = dialog.open();
-                               if (filename != null) {
-                                       driverFile.setText(filename);
-                               //      We save the used path
-                                        QuantumPlugin.getDefault().getPreferenceStore().setValue("quantum.dialogs.bookmarkwizard.path", filename); //$NON-NLS-1$
+       public void propertyChange(PropertyChangeEvent event) {
                
-                               }
-                       }
-               });
-
-        prompt.addSelectionListener(new SelectionAdapter() {
-            public void widgetSelected(SelectionEvent event) {
-                BookmarkPage.this.password.setEditable(!prompt.getSelection());
-            }
-        });
-        //jsurfer start typical MySQL settings !?
-        IPreferenceStore fStore =      QuantumPlugin.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;
-                       }
+               if ("driver".equals(event.getPropertyName())) {
+                       JDBCDriver driver = (JDBCDriver) event.getNewValue();
+                       this.bookmark.setJDBCDriver(driver);
+                       this.page2.setDriver(driver);
+               } else if ("name".equals(event.getPropertyName())) {
+                       this.bookmark.setName((String) event.getNewValue());
+               } else if ("userid".equals(event.getPropertyName())) {
+                       this.bookmark.setUsername((String) event.getNewValue());
+               } else if ("password".equals(event.getPropertyName())) {
+                       this.bookmark.setPassword((String) event.getNewValue());
+               } else if ("connectionURL".equals(event.getPropertyName())) {
+                       this.bookmark.setConnect((String) event.getNewValue());
+               } else if ("prompt".equals(event.getPropertyName())) {
+                       this.bookmark.setPromptForPassword(Boolean.TRUE.equals(event.getNewValue()));
+               } else if ("schemaRule".equals(event.getPropertyName())) {
+                       this.bookmark.setSchemaRule(((Integer) event.getNewValue()).intValue());
+               } else if ("schemas".equals(event.getPropertyName())) {
+                       this.bookmark.setSchemaSelections((Schema[]) event.getNewValue());
                }
-               type.select(selectedIndex);
-               driverFile.setText(fStore.getString("phpeclipse.sql.filename.connect"));
-//             jsurfer end
                
-               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() {
-               Bookmark initialData = new Bookmark();
-               initialData.setName(name.getText());
-               initialData.setUsername(username.getText());
-        initialData.setPromptForPassword(this.prompt.getSelection());
-        if (initialData.getPromptForPassword()) {
-            initialData.setPassword(""); //$NON-NLS-1$
-        } else {
-               initialData.setPassword(password.getText());
-        }
-               initialData.addSchema(schema.getText());
-               initialData.setConnect(connect.getText());
-               JDBCDriver jdbcDriver = BookmarkCollection.getInstance().findDriver(
-                               driver.getText(), driverFile.getText());
-               initialData.setJDBCDriver(jdbcDriver);
-               int selection = type.getSelectionIndex();
-               if (selection >= 0) {
-                       initialData.setType(drivers[selection].getDriverType());
-               }
-        BookmarkCollection.getInstance().addBookmark(initialData);
+       public void dispose() {
+               this.page1.removePropertyChangeListener(this);
+               this.page2.removePropertyChangeListener(this);
+               this.page3.removePropertyChangeListener(this);
+               this.page4.removePropertyChangeListener(this);
+               super.dispose();
        }
-}
\ No newline at end of file
+}
+