10658 - fix up launch config when ensureConnection returns
authordadubrow
Fri, 05 Feb 2010 15:32:05 -0600
changeset 901 3a0c0b389d0d
parent 899 b5675f3e69ad
child 905 c9573e1f3013
10658 - fix up launch config when ensureConnection returns
connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/IConnectionsManager.java
connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/registry/Registry.java
--- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/IConnectionsManager.java	Fri Feb 05 10:29:19 2010 -0600
+++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/IConnectionsManager.java	Fri Feb 05 15:32:05 2010 -0600
@@ -42,6 +42,14 @@
 	}
 
 	/**
+	 * Return value for IConnectionsManager.ensureConnection
+	 */
+	public interface ISelectedConnectionInfo {
+		IConnection getConnection();
+		String getStorableId();
+	}
+
+	/**
 	 * Internal method for loading connections from persisted state
 	 * @deprecated
 	 */
@@ -183,15 +191,18 @@
 	 * Can be called by specific service implementors (e.g., debugger) to ensure some connection
 	 * exists and supports this service. If the connection does not exist or does not support
 	 * the service, a CoreException may be thrown after the framework attempts to allow the user
-	 * to correct the situation. If an IConnection is returned, it is assumed to be 
-	 * a valid connection in the system that supports the service.
+	 * to correct the situation by showing a connection selection dialog. 
+	 * If an ISelectedConnectionInfo is returned, {@link ISelectedConnectionInfo#getConnection()} 
+	 * is assumed to be a valid connection in the system that supports the service 
+	 * and {@link ISelectedConnectionInfo#getStorableId()} is the id that can
+ 	 * be stored by the caller that represents the user's selection.
 	 * @param connectionId String
 	 * @param service IService
-	 * @return IConnection
+	 * @return ISelectedConnectionInfo
 	 * @throws CoreException
 	 * @since 2.5
 	 */
-	IConnection ensureConnection(String connectionId, IService service) throws CoreException;
+	ISelectedConnectionInfo ensureConnection(String connectionId, IService service) throws CoreException;
 	
 	/**
 	 * Returns a connection from an id (including the current connection id) or null if none found.
--- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/registry/Registry.java	Fri Feb 05 10:29:19 2010 -0600
+++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/registry/Registry.java	Fri Feb 05 15:32:05 2010 -0600
@@ -515,21 +515,30 @@
 		}
 	}
 	
-	public IConnection ensureConnection(String id, IService service) throws CoreException {
+	public ISelectedConnectionInfo ensureConnection(String id, IService service) throws CoreException {
 		Check.checkArg(service);
-		IConnection connection = findConnection(id);
-		if (!isCompatibleConnection(connection, service)) {
-			connection = getCompatibleConnectionFromUser(service);
-			if (connection == null) {
+		final IConnection[] connectionHolder = { findConnection(id) };
+		final String[] storableIdHolder = { id };
+		if (!isCompatibleConnection(connectionHolder[0], service)) {
+			connectionHolder[0] = getCompatibleConnectionFromUser(service, storableIdHolder);
+			if (connectionHolder[0] == null) {
 				throw new CoreException(
 						Logging.newStatus(RemoteConnectionsActivator.getDefault(), IStatus.ERROR, 
 								Messages.getString("Registry.NoCompatibleConnectionMsg"))); //$NON-NLS-1$
 			}
 		}
-		return connection;
+		return new ISelectedConnectionInfo() {
+			public String getStorableId() {
+				return storableIdHolder[0];
+			}
+			
+			public IConnection getConnection() {
+				return connectionHolder[0];
+			}
+		};
 	}
 
-	private IConnection getCompatibleConnectionFromUser(final IService service) {
+	private IConnection getCompatibleConnectionFromUser(final IService service, final String[] storableIdHolder) {
 		final IConnection[] connectionHolder = { null };
 		if (!WorkbenchUtils.isJUnitRunning()) {
 			Display.getDefault().syncExec(new Runnable() {
@@ -589,8 +598,10 @@
 						}
 					};
 					dialog.setBlockOnOpen(true);
-					if (dialog.open() == Dialog.OK)
-						connectionHolder[0] = findConnection(ui.getSelectedConnection());
+					if (dialog.open() == Dialog.OK) {
+						storableIdHolder[0] = ui.getSelectedConnection();
+						connectionHolder[0] = findConnection(storableIdHolder[0]);
+					}
 				}
 			});
 		}