[jbosstools-commits] JBoss Tools SVN: r42739 - in trunk/hibernatetools/plugins: org.hibernate.eclipse.console/src/org/hibernate/eclipse/console and 4 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Thu Jul 26 09:59:20 EDT 2012


Author: dgeraskov
Date: 2012-07-26 09:59:18 -0400 (Thu, 26 Jul 2012)
New Revision: 42739

Added:
   trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/wizards/Messages.java
   trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/wizards/SelectConnectionProfileDialog.java
   trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/wizards/messages.properties
Modified:
   trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.java
   trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties
   trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/wizards/NewConfigurationWizard.java
   trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/wizards/NewConfigurationWizardPage.java
   trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConnectionProfileCtrl.java
   trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConfigurationFactory.java
   trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConnectionProfileUtil.java
   trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/ConfigurationFactory.java
   trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/ConfigurationFactory.java
Log:
https://issues.jboss.org/browse/JBIDE-7996
Updated layout of new hibernate configuration file wizard

Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConfigurationFactory.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConfigurationFactory.java	2012-07-26 11:12:17 UTC (rev 42738)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConfigurationFactory.java	2012-07-26 13:59:18 UTC (rev 42739)
@@ -133,25 +133,10 @@
 	@SuppressWarnings("unused")
 	private void autoConfigureDialect(Configuration localCfg) {
 		if (localCfg.getProperty(Environment.DIALECT) == null) {
-			String url = localCfg.getProperty(Environment.URL);
-			String user = localCfg.getProperty(Environment.USER);
-			String pass = localCfg.getProperty(Environment.PASS);
-			Connection connection = null;
-			try {
-				connection = DriverManager.getConnection(url, user, pass);
-				// SQL Dialect:
-				Dialect dialect = DialectFactory.buildDialect(localCfg.getProperties(), connection);
-				localCfg.setProperty(Environment.DIALECT, dialect.toString());
-			} catch (SQLException e) {
-				// can't determine dialect
+			String dialect = ConnectionProfileUtil.autoDetectDialect(localCfg.getProperties());
+			if (dialect != null){
+				localCfg.setProperty(Environment.DIALECT, dialect);
 			}
-			if (connection != null) {
-				try {
-					connection.close();
-				} catch (SQLException e) {
-					// ignore
-				}
-			}
 		}
 	}
 

Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConnectionProfileUtil.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConnectionProfileUtil.java	2012-07-26 11:12:17 UTC (rev 42738)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConnectionProfileUtil.java	2012-07-26 13:59:18 UTC (rev 42739)
@@ -21,6 +21,9 @@
  */
 package org.hibernate.console;
 
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
 import java.util.Properties;
 
 import org.eclipse.datatools.connectivity.ConnectionProfileConstants;
@@ -29,6 +32,8 @@
 import org.eclipse.datatools.connectivity.drivers.DriverInstance;
 import org.eclipse.datatools.connectivity.drivers.jdbc.IJDBCDriverDefinitionConstants;
 import org.hibernate.cfg.Environment;
+import org.hibernate.dialect.Dialect;
+import org.hibernate.dialect.resolver.DialectFactory;
 
 /**
  * @author Vitali Yemialyanchyk
@@ -100,4 +105,32 @@
 		}
 		return props;
 	}
+	
+	public static String autoDetectDialect(Properties properties) {
+		if (properties.getProperty(Environment.DIALECT) == null) {
+			String url = properties.getProperty(Environment.URL);
+			String user = properties.getProperty(Environment.USER);
+			String pass = properties.getProperty(Environment.PASS);
+			Connection connection = null;
+			try {
+				connection = DriverManager.getConnection(url, user, pass);
+				// SQL Dialect:
+				Dialect dialect = DialectFactory.buildDialect(properties, connection);
+				return dialect.toString();
+			} catch (SQLException e) {
+				// can't determine dialect
+			} finally {
+				if (connection != null) {
+					try {
+						connection.close();
+					} catch (SQLException e) {
+						// ignore
+					}
+				}
+			}
+			return null;
+		} else {
+			return properties.getProperty(Environment.DIALECT);
+		}
+	}
 }

Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.java	2012-07-26 11:12:17 UTC (rev 42738)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.java	2012-07-26 13:59:18 UTC (rev 42739)
@@ -201,6 +201,8 @@
 	public static String NewConfigurationWizardPage_filefile_name;
 	public static String NewConfigurationWizardPage_fileoutside_classpath;
 	public static String NewConfigurationWizardPage_fileshould_pass_configuration;
+
+	public static String NewConfigurationWizardPage_getValuesFromConnection;
 	public static String NewConfigurationWizardPage_hibernate_config_file;
 	public static String NewConfigurationWizardPage_password;
 	public static String NewConfigurationWizardPage_project_must_be_writable;

Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties	2012-07-26 11:12:17 UTC (rev 42738)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties	2012-07-26 13:59:18 UTC (rev 42739)
@@ -196,6 +196,7 @@
 NewConfigurationWizardPage_filefile_name=hibernate.cfg.xml
 NewConfigurationWizardPage_fileoutside_classpath=Configuration placed outside CLASSPATH will not be available at run-time
 NewConfigurationWizardPage_fileshould_pass_configuration=To load Configuration from ''{0}'' you''ll have to pass file name to Configuration.configure() method
+NewConfigurationWizardPage_getValuesFromConnection=<a>Get values from Connection</a>
 NewConfigurationWizardPage_hibernate_config_file=Hibernate Configuration File (cfg.xml)
 NewConfigurationWizardPage_password=&Password:
 NewConfigurationWizardPage_project_must_be_writable=Project must be writable

Added: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/wizards/Messages.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/wizards/Messages.java	                        (rev 0)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/wizards/Messages.java	2012-07-26 13:59:18 UTC (rev 42739)
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ *     Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.hibernate.eclipse.console.wizards;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * @author Dmitry Geraskov (geraskov at gmail.com)
+ *
+ */
+public class Messages extends NLS {
+	private static final String BUNDLE_NAME = "org.hibernate.eclipse.console.wizards.messages"; //$NON-NLS-1$
+	public static String ConnectionProfile;
+	public static String SelectConnectionProfile;
+	static {
+		// initialize resource bundle
+		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+	}
+
+	private Messages() {
+	}
+}

Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/wizards/NewConfigurationWizard.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/wizards/NewConfigurationWizard.java	2012-07-26 11:12:17 UTC (rev 42738)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/wizards/NewConfigurationWizard.java	2012-07-26 13:59:18 UTC (rev 42739)
@@ -191,18 +191,11 @@
 		putIfNotNull(props, Environment.DIALECT, connectionInfoPage.getDialect() );
 		putIfNotNull(props, Environment.DEFAULT_CATALOG, connectionInfoPage.getDefaultCatalog() );
         putIfNotNull(props, Environment.DEFAULT_SCHEMA, connectionInfoPage.getDefaultSchema() );
-		if (connectionInfoPage.getConnectionProfileName() != null){
-			String cpName = connectionInfoPage.getConnectionProfileName();
-			IConnectionProfile profile = ProfileManager.getInstance().getProfileByName(cpName);
-			if (profile != null) {
-				props.putAll(ConnectionProfileUtil.getHibernateConnectionProperties(profile));
-			}
-		} else {
-	        putIfNotNull(props, Environment.DRIVER, connectionInfoPage.getDriver() );
-	        putIfNotNull(props, Environment.URL, connectionInfoPage.getConnectionURL() );
-	        putIfNotNull(props, Environment.USER, connectionInfoPage.getUsername() );
-	        putIfNotNull(props, Environment.PASS, connectionInfoPage.getPassword() );
-		}
+        putIfNotNull(props, Environment.DRIVER, connectionInfoPage.getDriver() );
+        putIfNotNull(props, Environment.URL, connectionInfoPage.getConnectionURL() );
+        putIfNotNull(props, Environment.USER, connectionInfoPage.getUsername() );
+        putIfNotNull(props, Environment.PASS, connectionInfoPage.getPassword() );
+
 		
         final IFile file = cPage.createNewFile();
 

Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/wizards/NewConfigurationWizardPage.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/wizards/NewConfigurationWizardPage.java	2012-07-26 11:12:17 UTC (rev 42738)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/wizards/NewConfigurationWizardPage.java	2012-07-26 13:59:18 UTC (rev 42739)
@@ -21,16 +21,22 @@
  */
 package org.hibernate.eclipse.console.wizards;
 
+import java.util.Properties;
+
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.Path;
+import org.eclipse.datatools.connectivity.IConnectionProfile;
+import org.eclipse.datatools.connectivity.ProfileManager;
 import org.eclipse.jface.dialogs.IDialogPage;
 import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.window.Window;
 import org.eclipse.jface.wizard.WizardPage;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.ScrolledComposite;
 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.events.SelectionListener;
 import org.eclipse.swt.layout.GridData;
@@ -38,14 +44,16 @@
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Combo;
 import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Group;
 import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Link;
+import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
+import org.hibernate.cfg.Environment;
+import org.hibernate.console.ConnectionProfileUtil;
 import org.hibernate.eclipse.console.HibernateConsoleMessages;
 import org.hibernate.eclipse.console.utils.DriverClassHelpers;
-import org.hibernate.eclipse.launch.ConnectionProfileCtrl;
 
 /**
  * Wizard for creating basic hibernate.cfg.xml
@@ -59,12 +67,6 @@
     private Label fileText;
 
     private Text sessionFactoryNameText;
-    
-    private Button useDTPConnection;
-    
-    private Label dtpConnection;
-    
-    private ConnectionProfileCtrl connectionProfileCtrl;
 
     private Combo dialectCombo;
 
@@ -87,7 +89,7 @@
 
     private boolean beenShown = false;
     
-    private Group driverManagerTabContainer;
+    private String defaultConnectionProfile = null;
 
     /**
      * Constructor for SampleNewWizardPage.
@@ -158,6 +160,24 @@
         sessionFactoryNameText.setLayoutData(gd);
         sessionFactoryNameText.addModifyListener(listener);
         
+        Link link = new Link(container, SWT.RIGHT);
+        link.setText(HibernateConsoleMessages.NewConfigurationWizardPage_getValuesFromConnection);
+        link.addSelectionListener(new SelectionAdapter() {
+			public void widgetSelected(SelectionEvent e) {
+				Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+				SelectConnectionProfileDialog dialog = new SelectConnectionProfileDialog(shell);
+				if (defaultConnectionProfile != null) dialog.setDefaultValue(defaultConnectionProfile);
+				if (dialog.open() == Window.OK){
+					defaultConnectionProfile = dialog.getConnectionProfileName();
+					fillPropertiesFromConnectionProfile(defaultConnectionProfile);
+				}
+			}
+		});
+        gd = new GridData(GridData.FILL_HORIZONTAL);
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalSpan = 2;
+        link.setLayoutData(gd);
+        
         label = new Label(container, SWT.NULL);
         label.setText(HibernateConsoleMessages.NewConfigurationWizardPage_database_dialect);
         dialectCombo = new Combo(container, SWT.NULL);
@@ -178,41 +198,8 @@
         gd.horizontalAlignment = SWT.TOP;
         gd.verticalAlignment = SWT.TOP;
         label.setLayoutData(gd);
-        
-        
-        
-        useDTPConnection = new Button(container, SWT.CHECK);
-        useDTPConnection.setText("Use DTP Connection");
-        useDTPConnection.addSelectionListener(selectionListener);
 
-        GridData gd2 = new GridData(SWT.NULL, SWT.NULL, false, false, 2, 1);
-        useDTPConnection.setLayoutData(gd2);
-        
-        dtpConnection = new Label(container, SWT.NULL);
-        dtpConnection.setText("DTP Connection");
-        dtpConnection.setLayoutData(gd);
-        dtpConnection.setEnabled(false);
-        
-        connectionProfileCtrl = new ConnectionProfileCtrl(container, 1, ""); //$NON-NLS-1$
-		connectionProfileCtrl.addModifyListener(new ModifyListener() {
-			@Override
-			public void modifyText(ModifyEvent e) {
-				if (connectionProfileCtrl.hasConnectionProfileSelected()){
-					setPageComplete(connectionProfileCtrl.hasConnectionProfileSelected());
-				}
-			}
-		});
-		connectionProfileCtrl.setEnabled(false);
-
- 
-		driverManagerTabContainer = new Group(container, SWT.NONE);
-		driverManagerTabContainer.setText("Custom");
-		driverManagerTabContainer.setLayout(layout);
-		gd = new GridData(GridData.FILL_HORIZONTAL);
-		gd.horizontalSpan = 2;
-		driverManagerTabContainer.setLayoutData(gd);
-		
-        //Composite driverManagerTabContainer = container;
+        Composite driverManagerTabContainer = container;
         label = new Label(driverManagerTabContainer, SWT.NULL);
         label.setText(HibernateConsoleMessages.NewConfigurationWizardPage_driver_class);
         driver_classCombo = new Combo(driverManagerTabContainer, SWT.NULL);
@@ -239,6 +226,20 @@
         urlCombo.addModifyListener(listener);
 
         label = new Label(driverManagerTabContainer, SWT.NULL);
+        label.setText(HibernateConsoleMessages.NewConfigurationWizardPage_default_schema);
+        defaultSchemaText = new Text(driverManagerTabContainer, SWT.BORDER | SWT.SINGLE);
+        gd = new GridData(GridData.FILL_HORIZONTAL);
+        defaultSchemaText.setLayoutData(gd);
+        defaultSchemaText.addModifyListener(listener);
+
+        label = new Label(driverManagerTabContainer, SWT.NULL);
+        label.setText(HibernateConsoleMessages.NewConfigurationWizardPage_default_catalog);
+        defaultCatalogText = new Text(driverManagerTabContainer, SWT.BORDER | SWT.SINGLE);
+        gd = new GridData(GridData.FILL_HORIZONTAL);
+        defaultCatalogText.setLayoutData(gd);
+        defaultCatalogText.addModifyListener(listener);
+
+        label = new Label(driverManagerTabContainer, SWT.NULL);
         label.setText(HibernateConsoleMessages.NewConfigurationWizardPage_user_name);
         usernameText = new Text(driverManagerTabContainer, SWT.BORDER | SWT.SINGLE);
         gd = new GridData(GridData.FILL_HORIZONTAL);
@@ -251,23 +252,10 @@
         gd = new GridData(GridData.FILL_HORIZONTAL);
         passwordText.setLayoutData(gd);
         passwordText.addModifyListener(listener);
-        
-        label = new Label(container, SWT.NULL);
-        label.setText(HibernateConsoleMessages.NewConfigurationWizardPage_default_schema);
-        defaultSchemaText = new Text(container, SWT.BORDER | SWT.SINGLE);
-        gd = new GridData(GridData.FILL_HORIZONTAL);
-        defaultSchemaText.setLayoutData(gd);
-        defaultSchemaText.addModifyListener(listener);
 
-        label = new Label(container, SWT.NULL);
-        label.setText(HibernateConsoleMessages.NewConfigurationWizardPage_default_catalog);
-        defaultCatalogText = new Text(container, SWT.BORDER | SWT.SINGLE);
-        gd = new GridData(GridData.FILL_HORIZONTAL);
-        defaultCatalogText.setLayoutData(gd);
-        defaultCatalogText.addModifyListener(listener);
-
         fillLabel(container);
         fillLabel(container);
+
         fillLabel(container);
 
         createConsoleConfiguration = new Button(container, SWT.CHECK);
@@ -284,6 +272,7 @@
         setControl(sc);
     }
 
+
     /**
      * @param urlCombo2
      */
@@ -336,19 +325,6 @@
      * Ensures that contents is ok.
      */
     private void dialogChanged() {
-    	dtpConnection.setEnabled(useDTPConnection.getSelection());
-		connectionProfileCtrl.setEnabled(useDTPConnection.getSelection());
-		if (useDTPConnection.getSelection()){
-			setPageComplete(connectionProfileCtrl.hasConnectionProfileSelected());
-		} else {
-			setPageComplete(true);
-		}
-		
-		driverManagerTabContainer.setEnabled(!useDTPConnection.getSelection());
-		for (Control control : driverManagerTabContainer.getChildren()) {
-			control.setEnabled(!useDTPConnection.getSelection());
-		}
-		
         IResource container = ResourcesPlugin.getWorkspace().getRoot()
                 .findMember(new Path(getContainerName() ) );
         String fileName = getFileName();
@@ -481,18 +457,31 @@
 	public String getDefaultSchema() {
 		return nullIfEmpty(defaultSchemaText.getText());
 	}
-	
-	public void setConnectionProfileName(String cpName){
-		if (cpName != null){
-			useDTPConnection.setSelection(true);
-			connectionProfileCtrl.selectValue(cpName);
-		}
+
+	public String getConnectionProfileName() {
+		return defaultConnectionProfile;
 	}
+
+	public void setConnectionProfileName(String selectedConnectionName) {
+		this.defaultConnectionProfile = selectedConnectionName;
+	}
 	
-	public String getConnectionProfileName(){
-		if (useDTPConnection.getSelection()){
-			return connectionProfileCtrl.getSelectedConnectionName();
+    
+    private void fillPropertiesFromConnectionProfile(String cpName){
+		IConnectionProfile profile = ProfileManager.getInstance().getProfileByName(cpName);
+		Properties p = ConnectionProfileUtil.getHibernateConnectionProperties(profile);
+		driver_classCombo.setText(p.getProperty(Environment.DRIVER));
+		urlCombo.setText(p.getProperty(Environment.URL));
+		if (p.containsKey(Environment.USER)){
+			 usernameText.setText(p.getProperty(Environment.USER));
 		}
-		return null;
-	}
+		if (p.containsKey(Environment.PASS)){
+			 passwordText.setText(p.getProperty(Environment.PASS));
+		}
+		/*this causes very long timeouts when db is not started
+		String dialect = ConnectionProfileUtil.autoDetectDialect(p);
+		if (dialect != null){
+			dialectCombo.setText(dialect);
+		}*/
+    }
 }
\ No newline at end of file

Added: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/wizards/SelectConnectionProfileDialog.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/wizards/SelectConnectionProfileDialog.java	                        (rev 0)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/wizards/SelectConnectionProfileDialog.java	2012-07-26 13:59:18 UTC (rev 42739)
@@ -0,0 +1,86 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ *     Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.hibernate.eclipse.console.wizards;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.hibernate.eclipse.launch.ConnectionProfileCtrl;
+
+/**
+ * 
+ * @author Dmitry Geraskov (geraskov at gmail.com)
+ *
+ */
+public class SelectConnectionProfileDialog extends Dialog {
+	
+	private ConnectionProfileCtrl connectionProfileCtrl;
+	private String selectedCP = null;
+
+	/**
+	 * @param shell
+	 */
+	protected SelectConnectionProfileDialog(Shell shell) {
+		super(shell);
+	}
+	
+	public void setDefaultValue(String str){
+		selectedCP = str;
+	}
+	
+	protected void configureShell(Shell shell) {
+		super.configureShell(shell);
+		shell.setText(Messages.SelectConnectionProfile); 
+	}
+	
+	@Override
+	protected Control createContents(Composite parent) {
+		Control c = super.createContents(parent);
+		getButton(IDialogConstants.OK_ID).setEnabled(selectedCP != null);
+		return c;
+	}
+	
+	@Override
+	protected Control createDialogArea(Composite container) {
+		Composite parent = (Composite) super.createDialogArea(container);
+		
+		
+		Label label = new Label(parent, SWT.NULL);
+		label.setText(Messages.ConnectionProfile);
+        connectionProfileCtrl = new ConnectionProfileCtrl(parent, 1, ""); //$NON-NLS-1$
+        if (selectedCP != null){
+			connectionProfileCtrl.selectValue(selectedCP);
+		}
+		connectionProfileCtrl.addModifyListener(new ModifyListener() {
+			@Override
+			public void modifyText(ModifyEvent e) {
+				getButton(IDialogConstants.OK_ID).setEnabled(connectionProfileCtrl.hasConnectionProfileSelected());
+				selectedCP = connectionProfileCtrl.getSelectedConnectionName();
+			}
+		});
+		
+		
+		return parent;
+	}
+	
+	
+	
+	public String getConnectionProfileName(){
+		return selectedCP;
+	}
+
+}

Added: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/wizards/messages.properties
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/wizards/messages.properties	                        (rev 0)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/wizards/messages.properties	2012-07-26 13:59:18 UTC (rev 42739)
@@ -0,0 +1,2 @@
+ConnectionProfile=Connection Profile
+SelectConnectionProfile=Select Connection Profile

Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConnectionProfileCtrl.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConnectionProfileCtrl.java	2012-07-26 11:12:17 UTC (rev 42738)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConnectionProfileCtrl.java	2012-07-26 13:59:18 UTC (rev 42739)
@@ -360,7 +360,7 @@
 		buttonEdit.setEnabled(enabled);
 	}
 
-	public void notifyModifyListeners() {
+	protected void notifyModifyListeners() {
 		for (int i = 0; i < modifyListeners.size(); i++) {
 			modifyListeners.get(i).modifyText(null);
 		}

Modified: trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/ConfigurationFactory.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/ConfigurationFactory.java	2012-07-26 11:12:17 UTC (rev 42738)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/ConfigurationFactory.java	2012-07-26 13:59:18 UTC (rev 42739)
@@ -16,7 +16,6 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.reflect.Method;
-import java.sql.Connection;
 import java.sql.Driver;
 import java.sql.DriverManager;
 import java.sql.SQLException;
@@ -46,8 +45,6 @@
 import org.hibernate.console.HibernateConsoleRuntimeException;
 import org.hibernate.console.preferences.ConsoleConfigurationPreferences;
 import org.hibernate.console.preferences.ConsoleConfigurationPreferences.ConfigurationMode;
-import org.hibernate.dialect.Dialect;
-import org.hibernate.dialect.resolver.DialectFactory;
 import org.hibernate.util.ConfigHelper;
 import org.hibernate.util.XMLHelper;
 import org.w3c.dom.Document;
@@ -135,25 +132,10 @@
 	@SuppressWarnings("unused")
 	private void autoConfigureDialect(Configuration localCfg) {
 		if (localCfg.getProperty(Environment.DIALECT) == null) {
-			String url = localCfg.getProperty(Environment.URL);
-			String user = localCfg.getProperty(Environment.USER);
-			String pass = localCfg.getProperty(Environment.PASS);
-			Connection connection = null;
-			try {
-				connection = DriverManager.getConnection(url, user, pass);
-				// SQL Dialect:
-				Dialect dialect = DialectFactory.buildDialect(localCfg.getProperties(), connection);
-				localCfg.setProperty(Environment.DIALECT, dialect.toString());
-			} catch (SQLException e) {
-				// can't determine dialect
+			String dialect = ConnectionProfileUtil.autoDetectDialect(localCfg.getProperties());
+			if (dialect != null){
+				localCfg.setProperty(Environment.DIALECT, dialect);
 			}
-			if (connection != null) {
-				try {
-					connection.close();
-				} catch (SQLException e) {
-					// ignore
-				}
-			}
 		}
 	}
 

Modified: trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/ConfigurationFactory.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/ConfigurationFactory.java	2012-07-26 11:12:17 UTC (rev 42738)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/ConfigurationFactory.java	2012-07-26 13:59:18 UTC (rev 42739)
@@ -135,26 +135,10 @@
 	@SuppressWarnings("unused")
 	private void autoConfigureDialect(Configuration localCfg, ServiceRegistry serviceRegistry) {
 		if (localCfg.getProperty(Environment.DIALECT) == null) {
-			String url = localCfg.getProperty(Environment.URL);
-			String user = localCfg.getProperty(Environment.USER);
-			String pass = localCfg.getProperty(Environment.PASS);
-			Connection connection = null;
-			try {
-				connection = DriverManager.getConnection(url, user, pass);
-				// SQL Dialect:
-				JdbcServices jdbcServices = serviceRegistry.getService(JdbcServices.class);
-				Dialect dialect = jdbcServices.getDialect();
-				localCfg.setProperty(Environment.DIALECT, dialect.toString());
-			} catch (SQLException e) {
-				// can't determine dialect
+			String dialect = ConnectionProfileUtil.autoDetectDialect(localCfg.getProperties());
+			if (dialect != null){
+				localCfg.setProperty(Environment.DIALECT, dialect);
 			}
-			if (connection != null) {
-				try {
-					connection.close();
-				} catch (SQLException e) {
-					// ignore
-				}
-			}
 		}
 	}
 



More information about the jbosstools-commits mailing list