latest quantum sources 2.3.2
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / properties / BookmarkPropertyPage.java
index 2463376..b4d53ea 100644 (file)
@@ -1,13 +1,5 @@
 package com.quantum.properties;
 
-import com.quantum.IQuantumConstants;
-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.view.bookmark.TreeNode;
-
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
@@ -23,6 +15,14 @@ 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 {
     
     private Text password;
@@ -35,7 +35,7 @@ public class BookmarkPropertyPage extends PropertyPage {
     
     private Combo type;
        private Combo autoCommit;
-    private DriverInfo[] adapters = AdapterFactory.getInstance().getDriverList();
+    private DatabaseAdapter[] adapters = AdapterFactory.getInstance().getDriverList();
 
     protected Control createContents(Composite parent) {
 
@@ -43,9 +43,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:");
@@ -55,16 +53,15 @@ 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);
@@ -77,7 +74,7 @@ public class BookmarkPropertyPage extends PropertyPage {
 
        private Bookmark getBookmark() {
         Bookmark bookmark =
-            ((TreeNode) getElement()).getBookmark();
+            ((BookmarkHolder) getElement()).getBookmark();
         return bookmark;
     }
 
@@ -95,16 +92,6 @@ public class BookmarkPropertyPage extends PropertyPage {
         composite.setLayoutData(data);
         
         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);
@@ -140,7 +127,7 @@ public class BookmarkPropertyPage extends PropertyPage {
 
     private void createUserTab(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();
@@ -185,6 +172,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);
     }
 
@@ -240,10 +237,9 @@ public class BookmarkPropertyPage extends PropertyPage {
         }
 
         int index = this.type.getSelectionIndex();
-        bookmark.setType(this.adapters[index].getDriverType());
         bookmark.setConnect(this.jdbcURL.getText());
                JDBCDriver jdbcDriver = BookmarkCollection.getInstance().findDriver(
-                               this.driverName.getText(), this.driverPath.getText());
+                               this.driverName.getText(), this.driverPath.getText(), this.adapters[index].getType());
                bookmark.setJDBCDriver(jdbcDriver);
         if (this.autoCommit.getSelectionIndex() >= 0)
                bookmark.setAutoCommitPreference(this.autoCommit.getItem(this.autoCommit.getSelectionIndex()));
@@ -258,7 +254,8 @@ 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.type.select(0);
@@ -267,8 +264,8 @@ public class BookmarkPropertyPage extends PropertyPage {
             length = (adapters == null) ? 0 : adapters.length;
             !done && i < length;
             i++) {
-            if (bookmark.getType() != null && 
-                bookmark.getType().equals(adapters[i].getDriverType())) {
+            if (bookmark.getJDBCDriver().getType() != null && 
+                bookmark.getJDBCDriver().getType().equals(adapters[i].getType())) {
                 this.type.select(i);
                 done = true;
             }