Improved support for comment folding
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / properties / BookmarkPropertyPage.java
index b4d53ea..6559347 100644 (file)
@@ -1,8 +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.model.Bookmark;
+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;
@@ -15,15 +29,38 @@ import org.eclipse.swt.widgets.TabItem;
 import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.dialogs.PropertyPage;
 
-import com.quantum.IQuantumConstants;
-import com.quantum.adapters.AdapterFactory;
-import com.quantum.adapters.DatabaseAdapter;
-import com.quantum.model.Bookmark;
-import com.quantum.model.BookmarkCollection;
-import com.quantum.model.BookmarkHolder;
-import com.quantum.model.JDBCDriver;
-
 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;
@@ -32,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 DatabaseAdapter[] adapters = AdapterFactory.getInstance().getDriverList();
+       private JDBCDriver driver;
 
     protected Control createContents(Composite parent) {
 
@@ -64,7 +103,7 @@ public class BookmarkPropertyPage extends PropertyPage {
         data.horizontalSpan = 2;
         tabFolder.setLayoutData(data);
         
-        createUserTab(tabFolder);
+        createConnectionTab(tabFolder);
         createDriverTab(tabFolder);
         createOptionsTab(tabFolder);
         
@@ -86,46 +125,67 @@ 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("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 Location:");
+        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 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("Connection");
         
@@ -218,7 +278,6 @@ public class BookmarkPropertyPage extends PropertyPage {
                this.autoCommit.setLayoutData(data);
 
                optionsTab.setControl(composite);
-               
         }
 
 
@@ -235,12 +294,9 @@ public class BookmarkPropertyPage extends PropertyPage {
         } else {
             bookmark.setPassword(this.password.getText());
         }
-
-        int index = this.type.getSelectionIndex();
         bookmark.setConnect(this.jdbcURL.getText());
-               JDBCDriver jdbcDriver = BookmarkCollection.getInstance().findDriver(
-                               this.driverName.getText(), this.driverPath.getText(), this.adapters[index].getType());
-               bookmark.setJDBCDriver(jdbcDriver);
+
+               bookmark.setJDBCDriver(this.driver);
         if (this.autoCommit.getSelectionIndex() >= 0)
                bookmark.setAutoCommitPreference(this.autoCommit.getItem(this.autoCommit.getSelectionIndex()));
         return super.performOk();
@@ -257,19 +313,12 @@ public class BookmarkPropertyPage extends PropertyPage {
         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.getJDBCDriver().getType() != null && 
-                bookmark.getJDBCDriver().getType().equals(adapters[i].getType())) {
-                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.getJDBCDriver().getClassName());
-        this.jdbcURL.setText(bookmark.getConnect());
-        this.driverPath.setText(bookmark.getJDBCDriver().getJarFileName());
     }
+
+       /**
+        * 
+        */
+       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());
+       }
 }