preparing new release
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / properties / BookmarkPropertyPage.java
index 42c4065..6559347 100644 (file)
@@ -1,14 +1,22 @@
 package com.quantum.properties;
 
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
 import com.quantum.IQuantumConstants;
 import com.quantum.adapters.AdapterFactory;
-import com.quantum.adapters.DriverInfo;
 import com.quantum.model.Bookmark;
-import com.quantum.view.bookmark.TreeNode;
+import com.quantum.model.BookmarkHolder;
+import com.quantum.model.JDBCDriver;
+import com.quantum.wizards.BookmarkWizard;
+import com.quantum.wizards.JDBCDriverSelectionWizardPage;
 
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.jface.wizard.WizardDialog;
 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;
@@ -22,6 +30,37 @@ import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.dialogs.PropertyPage;
 
 public class BookmarkPropertyPage extends PropertyPage {
+       
+       class ChooseDriverWizard extends Wizard {
+
+               private JDBCDriver selection;
+               private JDBCDriverSelectionWizardPage page;
+               private PropertyChangeListener listener = new PropertyChangeListener() {
+                       public void propertyChange(PropertyChangeEvent event) {
+                               if ("driver".equals(event.getPropertyName())) {
+                                       ChooseDriverWizard.this.selection = (JDBCDriver) event.getNewValue();
+                               }
+                       }
+               };
+               
+               public void addPages() {
+                       this.page = new JDBCDriverSelectionWizardPage("page1");
+                       this.page.addPropertyChangeListener(this.listener);
+                       addPage(this.page);
+               }
+               
+               public void dispose() {
+                       this.page.removePropertyChangeListener(this.listener);
+                       super.dispose();
+               }
+               public boolean performFinish() {
+                       BookmarkPropertyPage.this.driver = this.selection;
+                       BookmarkPropertyPage.this.setDriverDetails();
+                       return true;
+               }
+               
+       }
+       
     
     private Text password;
     private Text userid;
@@ -30,10 +69,12 @@ public class BookmarkPropertyPage extends PropertyPage {
     private Text jdbcURL;
     private Text driverName;
     private Text driverPath;
+    private Text driverClassName;
+    private Text driverVersion;
+    private Text type;
     
-    private Combo type;
        private Combo autoCommit;
-    private DriverInfo[] adapters = AdapterFactory.getInstance().getDriverList();
+       private JDBCDriver driver;
 
     protected Control createContents(Composite parent) {
 
@@ -41,9 +82,7 @@ public class BookmarkPropertyPage extends PropertyPage {
         GridLayout layout = new GridLayout();
         layout.numColumns = 2;
         composite.setLayout(layout);
-        GridData data = new GridData(GridData.FILL);
-        data.grabExcessHorizontalSpace = true;
-        composite.setLayoutData(data);
+        composite.setLayoutData(new GridData(GridData.FILL_BOTH));
 
                Label nameLabel = new Label(composite, SWT.NONE);
         nameLabel.setText("Name:");
@@ -53,19 +92,18 @@ public class BookmarkPropertyPage extends PropertyPage {
         Bookmark bookmark = getBookmark();
         String description = bookmark.getName();
         name.setText(description);
+        name.setLayoutData(
+                       new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING 
+                                       | GridData.VERTICAL_ALIGN_BEGINNING));
         
-        TabFolder tabFolder = new TabFolder(parent, SWT.NONE);
+        TabFolder tabFolder = new TabFolder(composite, SWT.NONE);
         layout = new GridLayout();
         tabFolder.setLayout(layout);
-        data = new GridData(GridData.FILL_BOTH);
-        data.grabExcessHorizontalSpace = true;
-        data.grabExcessVerticalSpace = true;
-        data.verticalAlignment = GridData.FILL;
+        GridData data = new GridData(GridData.FILL_BOTH);
         data.horizontalSpan = 2;
-        data.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
         tabFolder.setLayoutData(data);
         
-        createUserTab(tabFolder);
+        createConnectionTab(tabFolder);
         createDriverTab(tabFolder);
         createOptionsTab(tabFolder);
         
@@ -75,7 +113,7 @@ public class BookmarkPropertyPage extends PropertyPage {
 
        private Bookmark getBookmark() {
         Bookmark bookmark =
-            ((TreeNode) getElement()).getBookmark();
+            ((BookmarkHolder) getElement()).getBookmark();
         return bookmark;
     }
 
@@ -87,58 +125,69 @@ public class BookmarkPropertyPage extends PropertyPage {
         GridLayout layout = new GridLayout();
         layout.numColumns = 2;
         composite.setLayout(layout);
-        GridData data = new GridData(GridData.FILL);
-        data.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
-        data.grabExcessHorizontalSpace = true;
-        composite.setLayoutData(data);
+        composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
         
         Label label = new Label(composite, SWT.NONE);
-        label.setText("Connection URL:");
-
-        this.jdbcURL = new Text(composite, SWT.BORDER);
-        data = new GridData(GridData.FILL);
-        data.horizontalAlignment = GridData.FILL;
-        data.grabExcessHorizontalSpace = true;
-        data.grabExcessHorizontalSpace = true;
-        this.jdbcURL.setLayoutData(data);
-        
-        label = new Label(composite, SWT.NONE);
         label.setText("Driver Name:");
 
         this.driverName = new Text(composite, SWT.BORDER);
-        data = new GridData(GridData.FILL);
-        data.horizontalAlignment = GridData.FILL;
-        data.grabExcessHorizontalSpace = true;
-        this.driverName.setLayoutData(data);
+        this.driverName.setLayoutData(createFillHorizontalGridData());
+        this.driverName.setEditable(false);
+
+        label = new Label(composite, SWT.NONE);
+        label.setText("Driver Class Name:");
+
+        this.driverClassName = new Text(composite, SWT.BORDER);
+        this.driverClassName.setLayoutData(createFillHorizontalGridData());
+        this.driverClassName.setEditable(false);
+
+        label = new Label(composite, SWT.NONE);
+        label.setText("Driver Version:");
+
+        this.driverVersion = new Text(composite, SWT.BORDER);
+        this.driverVersion.setLayoutData(createFillHorizontalGridData());
+        this.driverVersion.setEditable(false);
 
         label = new Label(composite, SWT.NONE);
-        label.setText("Driver Location:");
+        label.setText("Driver Path:");
 
         this.driverPath = new Text(composite, SWT.BORDER);
-        data = new GridData(GridData.FILL);
-        data.horizontalAlignment = GridData.FILL;
-        data.grabExcessHorizontalSpace = true;
-        this.driverPath.setLayoutData(data);
+        this.driverPath.setLayoutData(createFillHorizontalGridData());
+        this.driverPath.setEditable(false);
 
         label = new Label(composite, SWT.NULL);
         label.setText("Type:");
-        this.type = new Combo(composite, SWT.SIMPLE | SWT.DROP_DOWN | SWT.READ_ONLY);
-        String adapterNames[] = new String[adapters.length];
-        for (int i = 0; i < adapters.length; i++) {
-            adapterNames[i] = adapters[i].getDisplayName();
-        }
-        this.type.setItems(adapterNames);
-        
-        data = new GridData();
-        data.horizontalAlignment = GridData.FILL;
-        this.type.setLayoutData(data);
+        this.type = new Text(composite, SWT.BORDER);
+        this.type.setLayoutData(createFillHorizontalGridData());
+        this.type.setEditable(false);
 
         driverTab.setControl(composite);
+        
+        Button button = new Button(composite, SWT.PUSH);
+        button.setText("Change");
+        GridData data = new GridData(GridData.HORIZONTAL_ALIGN_END);
+        data.horizontalSpan = 2;
+        button.setLayoutData(data);
+        button.addSelectionListener(new SelectionListener() {
+                       public void widgetSelected(SelectionEvent event) {
+                       WizardDialog dialog = 
+                               new WizardDialog(getShell(), new ChooseDriverWizard());
+                       dialog.open();
+                       }
+                       public void widgetDefaultSelected(SelectionEvent event) {
+                       }
+        });
+    }
+    
+    private GridData createFillHorizontalGridData() {
+       GridData data = new GridData(GridData.FILL_HORIZONTAL);
+       data.widthHint = 200;
+       return data;
     }
 
-    private void createUserTab(TabFolder tabFolder) {
+    private void createConnectionTab(TabFolder tabFolder) {
         TabItem userTab = new TabItem(tabFolder, SWT.NONE);
-        userTab.setText("User");
+        userTab.setText("Connection");
         
         Composite composite = new Composite(tabFolder, SWT.NONE);
         GridLayout layout = new GridLayout();
@@ -183,6 +232,16 @@ public class BookmarkPropertyPage extends PropertyPage {
             }
         });
         
+        Label label = new Label(composite, SWT.NONE);
+        label.setText("Connection URL:");
+
+        this.jdbcURL = new Text(composite, SWT.BORDER);
+        data = new GridData(GridData.FILL);
+        data.horizontalAlignment = GridData.FILL;
+        data.grabExcessHorizontalSpace = true;
+        data.grabExcessHorizontalSpace = true;
+        this.jdbcURL.setLayoutData(data);
+        
         userTab.setControl(composite);
     }
 
@@ -219,7 +278,6 @@ public class BookmarkPropertyPage extends PropertyPage {
                this.autoCommit.setLayoutData(data);
 
                optionsTab.setControl(composite);
-               
         }
 
 
@@ -236,12 +294,9 @@ public class BookmarkPropertyPage extends PropertyPage {
         } else {
             bookmark.setPassword(this.password.getText());
         }
-
-        int index = this.type.getSelectionIndex();
-        bookmark.setType(this.adapters[index].getDriverType());
         bookmark.setConnect(this.jdbcURL.getText());
-        bookmark.setDriver(this.driverName.getText());
-        bookmark.setDriverFile(this.driverPath.getText());
+
+               bookmark.setJDBCDriver(this.driver);
         if (this.autoCommit.getSelectionIndex() >= 0)
                bookmark.setAutoCommitPreference(this.autoCommit.getItem(this.autoCommit.getSelectionIndex()));
         return super.performOk();
@@ -255,21 +310,15 @@ public class BookmarkPropertyPage extends PropertyPage {
 
         this.prompt.setSelection(bookmark.getPromptForPassword());
         this.password.setEditable(!bookmark.getPromptForPassword());
-        this.password.setText(bookmark.getPassword());
+        String password = bookmark.getPassword();
+        this.password.setText(password == null ? "" : password);
         this.userid.setText(bookmark.getUsername());
+        this.jdbcURL.setText(bookmark.getConnect());
 
-        this.type.select(0);
-        boolean done = false;
-        for (int i = 0,
-            length = (adapters == null) ? 0 : adapters.length;
-            !done && i < length;
-            i++) {
-            if (bookmark.getType() != null && 
-                bookmark.getType().equals(adapters[i].getDriverType())) {
-                this.type.select(i);
-                done = true;
-            }
-        }
+        this.driver = bookmark.getJDBCDriver();
+        
+        setDriverDetails();
+        
         if (bookmark.getAutoCommitPreference().equals(IQuantumConstants.autoCommitTrue))
                this.autoCommit.select(0);
         else if (bookmark.getAutoCommitPreference().equals(IQuantumConstants.autoCommitFalse))
@@ -277,8 +326,18 @@ public class BookmarkPropertyPage extends PropertyPage {
                else if (bookmark.getAutoCommitPreference().equals(IQuantumConstants.autoCommitSaved))
                        this.autoCommit.select(2);
                        
-        this.driverName.setText(bookmark.getDriver());
-        this.jdbcURL.setText(bookmark.getConnect());
-        this.driverPath.setText(bookmark.getDriverFile());
     }
+
+       /**
+        * 
+        */
+       private void setDriverDetails() {
+               this.driverName.setText(this.driver.getName());
+        this.driverClassName.setText(this.driver.getClassName());
+        String path = this.driver.getJarFilePath();
+        this.driverPath.setText(path == null ? "" : path);
+        String version = this.driver.getVersion();
+        this.driverVersion.setText(version == null ? "" : version);
+        this.type.setText(AdapterFactory.getInstance().getAdapter(this.driver.getType()).getDisplayName());
+       }
 }