X-Git-Url: http://secure.phpeclipse.com

diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/BookmarkConnectionWizardPage.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/BookmarkConnectionWizardPage.java
index 25cbc3c..3acbcfe 100644
--- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/BookmarkConnectionWizardPage.java
+++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/wizards/BookmarkConnectionWizardPage.java
@@ -1,10 +1,17 @@
 package com.quantum.wizards;
 
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+import com.quantum.Messages;
+import com.quantum.model.JDBCDriver;
+
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.ModifyEvent;
 import org.eclipse.swt.events.ModifyListener;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
@@ -12,9 +19,6 @@ import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Text;
 
-import com.quantum.Messages;
-import com.quantum.model.JDBCDriver;
-
 
 class BookmarkConnectionWizardPage extends PropertyChangeWizardPage {
 	
@@ -25,6 +29,21 @@ class BookmarkConnectionWizardPage extends PropertyChangeWizardPage {
 	private String connectionURL;
     private boolean prompt;
     
+    private Label jdbcLabel;
+    private Text jdbcUrl;
+    private URLSetupControl urlSetupControl;
+    private Composite container;
+    private boolean requiresRebuild = false;
+    
+    private PropertyChangeListener listener = new PropertyChangeListener() {
+		public void propertyChange(PropertyChangeEvent event) {
+			if ("connectionURL".equals(event.getPropertyName())) {
+				BookmarkConnectionWizardPage.this.setConnectionURL((String) event.getNewValue());
+				BookmarkConnectionWizardPage.this.updateButtonState();
+			}
+		}
+    }; 
+    
     /**
 	 * Constructor for BookmarkPage.
 	 * @param pageName
@@ -40,7 +59,7 @@ class BookmarkConnectionWizardPage extends PropertyChangeWizardPage {
 		Composite container = new Composite(parent, SWT.NULL);
 		GridLayout layout = new GridLayout();
 		container.setLayout(layout);
-		layout.numColumns = 3;
+		layout.numColumns = 2;
 		layout.verticalSpacing = 9;
 
 		Label label = new Label(container, SWT.NULL);
@@ -49,7 +68,6 @@ class BookmarkConnectionWizardPage extends PropertyChangeWizardPage {
 		
 		
  		GridData fullHorizontal = new GridData(GridData.FILL_HORIZONTAL);
- 		fullHorizontal.horizontalSpan = 2;
 		username.setLayoutData(fullHorizontal);
 		username.addModifyListener(new ModifyListener() {
 			public void modifyText(ModifyEvent event) {
@@ -64,7 +82,6 @@ class BookmarkConnectionWizardPage extends PropertyChangeWizardPage {
 		final Text password = new Text(container, SWT.BORDER | SWT.SINGLE);
 		password.setEchoChar('*');
  		fullHorizontal = new GridData(GridData.FILL_HORIZONTAL);
- 		fullHorizontal.horizontalSpan = 2;
 		password.setLayoutData(fullHorizontal);
 		password.addModifyListener(new ModifyListener() {
 			public void modifyText(ModifyEvent event) {
@@ -77,23 +94,10 @@ class BookmarkConnectionWizardPage extends PropertyChangeWizardPage {
         Button prompt = new Button(container, SWT.CHECK);
 		prompt.setText(Messages.getString(getClass(), "prompt")); //$NON-NLS-1$
 		fullHorizontal = new GridData(GridData.FILL_HORIZONTAL);
- 		fullHorizontal.horizontalSpan = 3;
+ 		fullHorizontal.horizontalSpan = 2;
         prompt.setLayoutData(fullHorizontal);
  
-		label = new Label(container, SWT.NULL);
-		label.setText(Messages.getString(getClass(), "url")); //$NON-NLS-1$
-		
-		Text connect = new Text(container, SWT.BORDER | SWT.SINGLE);
-		fullHorizontal = new GridData(GridData.FILL_HORIZONTAL);
- 		fullHorizontal.horizontalSpan = 2;
-		connect.setLayoutData(fullHorizontal);
-		connect.addModifyListener(new ModifyListener() {
-			public void modifyText(ModifyEvent event) {
-				String connectionURL = ((Text) event.getSource()).getText();
-				setConnectionURL(connectionURL);
-				updateButtonState();
-			}
-		});
+		createStandardJDBCWidgets(container);
         prompt.addSelectionListener(new SelectionAdapter() {
             public void widgetSelected(SelectionEvent event) {
             	Button prompt = ((Button) event.getSource());
@@ -103,9 +107,37 @@ class BookmarkConnectionWizardPage extends PropertyChangeWizardPage {
             }
         });
 
+        this.container = container;
 		setControl(container);
 	}
 	
+	public void setVisible(boolean visible) {
+		if (visible && this.requiresRebuild) {
+			rebuildJDBCControls(this.driver);
+		}
+		super.setVisible(visible);
+	}
+	
+	/**
+	 * @param container
+	 */
+	private void createStandardJDBCWidgets(Composite container) {
+		setConnectionURL("");
+		
+		this.jdbcLabel = new Label(container, SWT.NULL);
+		this.jdbcLabel.setText(Messages.getString(getClass(), "url")); //$NON-NLS-1$
+		
+		this.jdbcUrl = new Text(container, SWT.BORDER | SWT.SINGLE);
+ 		this.jdbcUrl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ 		this.jdbcUrl.addModifyListener(new ModifyListener() {
+			public void modifyText(ModifyEvent event) {
+				setConnectionURL(((Text) event.getSource()).getText());
+				updateButtonState();
+			}
+		});
+ 		
+ 		updateButtonState();
+	}
 	/**
 	 * @return Returns the driver.
 	 */
@@ -116,7 +148,75 @@ class BookmarkConnectionWizardPage extends PropertyChangeWizardPage {
 	 * @param driver The driver to set.
 	 */
 	public void setDriver(JDBCDriver driver) {
+		String oldDriverClassName = this.driver == null ? null : this.driver.getClassName();
 		this.driver = driver;
+		
+		if (oldDriverClassName == null 
+				|| !oldDriverClassName.equals(this.driver.getClassName())) {
+			this.requiresRebuild = true;
+		}
+	}
+	/**
+	 * 
+	 */
+	private void rebuildJDBCControls(JDBCDriver driver) {
+        Point windowSize = getShell().getSize();
+        Point oldSize = getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT);
+		
+		if (URLSetupControlFactory.hasControl(driver)) {
+			disposeOfCurrentJDBCControls();
+			
+			this.urlSetupControl = URLSetupControlFactory.create(driver, this.container);
+			GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING);
+			data.horizontalSpan = 2;
+			this.urlSetupControl.setLayoutData(data);
+			
+			this.urlSetupControl.addPropertyChangeListener(this.listener);
+			
+			setConnectionURL(this.urlSetupControl.getConnectionURL());
+			updateButtonState();
+
+	        resizeWindow(windowSize, oldSize);
+			this.container.layout();
+			
+		} else if (this.jdbcLabel == null || this.jdbcUrl == null) {
+			
+			disposeOfCurrentJDBCControls();
+			createStandardJDBCWidgets(this.container);
+
+	        resizeWindow(windowSize, oldSize);
+	        
+			this.container.layout();
+		}
+		this.container.setVisible(true);
+		this.container.redraw();
+	}
+	
+	/**
+	 * @param windowSize
+	 * @param oldSize
+	 */
+	private void resizeWindow(Point windowSize, Point oldSize) {
+		Point newSize = getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT);
+		if (newSize.y > windowSize.y) {
+			getShell().setSize(
+			    new Point(windowSize.x, windowSize.y + (newSize.y - oldSize.y)));
+		}
+	}
+	private void disposeOfCurrentJDBCControls() {
+		if (this.jdbcUrl != null) {
+			this.jdbcUrl.dispose();
+			this.jdbcUrl = null;
+		}
+		if (this.jdbcLabel != null) {
+			this.jdbcLabel.dispose();
+			this.jdbcLabel = null;
+		}
+		if (this.urlSetupControl != null) {
+			this.urlSetupControl.removePropertyChangeListener(this.listener);
+			this.urlSetupControl.dispose();
+			this.urlSetupControl = null;
+		}
 	}
 	/**
 	 * 
@@ -125,8 +225,9 @@ class BookmarkConnectionWizardPage extends PropertyChangeWizardPage {
 		boolean complete = true;
 		complete &= (this.connectionURL != null 
 				&& this.connectionURL.trim().length() > 0);
-		complete &= (this.userid != null 
-				&& this.userid.trim().length() > 0);
+		// Some databases don't use user id
+		//complete &= (this.userid != null 
+		//		&& this.userid.trim().length() > 0);
 		setPageComplete(complete);
 	}
 	/**