Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
authorEd Swartz <ed.swartz@nokia.com>
Wed, 30 Dec 2009 11:43:43 -0600
changeset 730 8ecd45ef360e
parent 729 477762bc3b31
child 731 68bc07acac96
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/IClientServiceSiteUI2.java
connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ui/ClientServiceSiteUI2.java
connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ui/ConnectionStatusSelectorContribution.java
connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/messages.properties
debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/ui/AttachMainTab.java
debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/ui/RunModeMainTab.java
debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/ui/messages.properties
debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/wizard/TRKConnectionWizardPage.java
--- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/IClientServiceSiteUI2.java	Wed Dec 30 09:59:34 2009 -0600
+++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/IClientServiceSiteUI2.java	Wed Dec 30 11:43:43 2009 -0600
@@ -18,6 +18,7 @@
 
 package com.nokia.carbide.remoteconnections.interfaces;
 
+import org.eclipse.core.runtime.IStatus;
 import org.eclipse.swt.widgets.Composite;
 
 /**
@@ -81,4 +82,21 @@
 	 * @param listener IListener
 	 */
 	void removeListener(IListener listener);
+
+	/**
+	 * Validate the selected connection and return a status.
+	 * <p>
+	 * @return IStatus for the state of the selection:
+	 * <ol>
+	 * <li>If a connection is selected and it's compatible, return OK.
+	 * <li>If no connection is selected, return ERROR.
+	 * <li>If selected connection is a default, but the current default is incompatible,
+	 * return WARNING.
+	 * (Normally, the concrete connections are already filtered to show only
+	 * compatible ones, but the default may be anything.)  This is only a warning
+	 * because the default connection can be changed externally to this UI, thus
+	 * isn't a fatal error.
+	 * </ol>
+	 */
+	IStatus getSelectionStatus();
 }
--- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ui/ClientServiceSiteUI2.java	Wed Dec 30 09:59:34 2009 -0600
+++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ui/ClientServiceSiteUI2.java	Wed Dec 30 11:43:43 2009 -0600
@@ -28,6 +28,8 @@
 import com.nokia.cpp.internal.api.utils.core.Check;
 import com.nokia.cpp.internal.api.utils.core.ListenerList;
 
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
 import org.eclipse.jface.dialogs.Dialog;
 import org.eclipse.jface.dialogs.IDialogConstants;
 import org.eclipse.jface.resource.JFaceResources;
@@ -71,7 +73,7 @@
 	public void createComposite(Composite parent) {
 		initializeDialogUnits(parent);
 		Group group = new Group(parent, SWT.NONE);
-		group.setText(Messages.getString("ClientServiceSiteUI.UseConnectionGroupLabel")); //$NON-NLS-1$
+		group.setText(Messages.getString("ClientServiceSiteUI2.UseConnectionGroupLabel")); //$NON-NLS-1$
 		group.setLayout(new GridLayout());
 		group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
 		group.setData(UID, "useConnectionGroup"); //$NON-NLS-1$
@@ -114,7 +116,7 @@
 		composite.setFont(parent.getFont());
 		
 		newButton = new Button(composite, SWT.PUSH);
-		newButton.setText(Messages.getString("ClientServiceSiteUI.NewButtonLabel")); //$NON-NLS-1$
+		newButton.setText(Messages.getString("ClientServiceSiteUI2.NewButtonLabel")); //$NON-NLS-1$
 		newButton.setFont(JFaceResources.getDialogFont());
 		gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
 		int widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH);
@@ -136,7 +138,7 @@
 		});
 		
 		editButton = new Button(composite, SWT.PUSH);
-		editButton.setText(Messages.getString("ClientServiceSiteUI.EditButtonLabel")); //$NON-NLS-1$
+		editButton.setText(Messages.getString("ClientServiceSiteUI2.EditButtonLabel")); //$NON-NLS-1$
 		editButton.setFont(JFaceResources.getDialogFont());
 		gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
 		widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH);
@@ -183,6 +185,9 @@
 	 * @return {@link IConnection} or <code>null</code>
 	 */
 	protected IConnection getActualConnection(String id) {
+		if (id == null) {
+			return null;
+		}
 		if (id.equals(Registry.DEFAULT_CONNECTION_ID)) {
 			return RemoteConnectionsActivator.getConnectionsManager().getDefaultConnection();
 		}
@@ -225,12 +230,29 @@
 				selectConnection(connection.getIdentifier());
 		}
 		editButton.setEnabled(!viewer.getSelection().isEmpty());
+		
+		// fire listener in case we selected anew or the default connection changed
+		fireConnectionSelected();
 	}
 
 	private void refreshUI() {
 		Display.getDefault().syncExec(new Runnable() {
 			public void run() {
-				setViewerInput(null);
+				if (viewer != null && viewer.getContentProvider() != null) {
+					
+					// try to preserve the currently selected item, if it's a concrete
+					// connection; if it's default, allow for the new default to be chosen.
+					IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
+					Object value = selection.getFirstElement();
+					String current = null;
+					if (value instanceof String) {
+						current = (String) value;
+					}
+					if (Registry.DEFAULT_CONNECTION_ID.equals(current)) {
+						current = null;
+					}
+					setViewerInput(getActualConnection(current));
+				}
 			}
 		});
 	}
@@ -285,6 +307,56 @@
 		return connection;
 	}
 	
+	public IStatus getSelectionStatus() {
+		// no selection yet...?
+		if (connection == null) {
+			return new Status(IStatus.ERROR, RemoteConnectionsActivator.PLUGIN_ID,
+					Messages.getString("ClientServiceSiteUI2.NoConnectionError"));
+		}
+		
+		// check whether the default is compatible with the service and connection type
+		if (Registry.DEFAULT_CONNECTION_ID.equals(connection)) {
+			IConnection actual = getActualConnection(connection);
+			if (actual != null) {
+				// is the service supported?
+				boolean found = false;
+				for (IConnectedService aService : Registry.instance().getConnectedServices(actual)) {
+					if (service.getIdentifier().equals(aService.getService().getIdentifier())) {
+						found = true;
+						break;
+					}
+				}
+				if (!found) {
+					return new Status(IStatus.WARNING, RemoteConnectionsActivator.PLUGIN_ID,
+							MessageFormat.format(
+									Messages.getString("ClientServiceSiteUI2.IncompatibleDefaultConnectionService"),
+									actual.getDisplayName(),
+									service.getDisplayName()));
+				}
+				
+				// is the hardware type supported by the service?
+				if (!isCompatibleConnection(actual)) {
+					String requiredConnectionTypes  = "";
+					for (IConnectionType type : compatibleConnectionTypes) {
+						if (requiredConnectionTypes.length() > 0)
+							requiredConnectionTypes += ", ";
+						requiredConnectionTypes += type.getDisplayName();
+					}
+					return new Status(IStatus.WARNING, RemoteConnectionsActivator.PLUGIN_ID,
+							MessageFormat.format(
+									Messages.getString("ClientServiceSiteUI2.IncompatibleDefaultConnectionType"),
+									actual.getDisplayName(),
+									requiredConnectionTypes));
+			
+				}
+				
+			}
+		}
+		
+		// otherwise, it's okay!
+		return Status.OK_STATUS;
+	}
+	
 	/* (non-Javadoc)
 	 * @see com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI2#getConnectionDisplayName(java.lang.String)
 	 */
--- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ui/ConnectionStatusSelectorContribution.java	Wed Dec 30 09:59:34 2009 -0600
+++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ui/ConnectionStatusSelectorContribution.java	Wed Dec 30 11:43:43 2009 -0600
@@ -355,7 +355,7 @@
 		
 		item.setSelection(isDefault);
 		
-		item.setText("&" + number + " - " + connection.getDisplayName());
+		item.setText(MessageFormat.format("&{0} - {1}", number, connection.getDisplayName())); //$NON-NLS-1$
 		
 		item.addSelectionListener(new SelectionAdapter() {
 			@Override
@@ -466,7 +466,7 @@
 	 * @param status
 	 */
 	private void updateConnectionStatus(final IConnectionStatus status) {
-		Display.getDefault().syncExec(new Runnable() {
+		Display.getDefault().asyncExec(new Runnable() {
 			public void run() {
 				if (connectionIcon == null || connectionIcon.isDisposed())
 					return;
@@ -481,7 +481,7 @@
 				String tip = createConnectionStatusTooltip(defaultConnection, status);
 				connectionInfo.setToolTipText(tip);
 				
-				String preamble = "Click to open the Remote Connections View.\n\n";
+				String preamble = Messages.getString("ConnectionStatusSelectorContribution.IconTooltipPrefixMessage"); //$NON-NLS-1$
 				connectionIcon.setToolTipText(preamble + tip);		
 			}
 		});
--- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/messages.properties	Wed Dec 30 09:59:34 2009 -0600
+++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/messages.properties	Wed Dec 30 11:43:43 2009 -0600
@@ -7,6 +7,12 @@
 ClientServiceSiteUI.EditButtonLabel=Edit...
 ClientServiceSiteUI.NewButtonLabel=New...
 ClientServiceSiteUI.UseConnectionGroupLabel=Use connection
+ClientServiceSiteUI2.EditButtonLabel=Edit...
+ClientServiceSiteUI2.NewButtonLabel=New...
+ClientServiceSiteUI2.UseConnectionGroupLabel=Use connection
+ClientServiceSiteUI2.NoConnectionError=A valid remote connection must be selected.  If none exist, create a new one.
+ClientServiceSiteUI2.IncompatibleDefaultConnectionType=The default connection ''{0}'' does not support connection type: ''{1}''.\nEnsure you have selected a suitable default before launching.
+ClientServiceSiteUI2.IncompatibleDefaultConnectionService=The default connection ''{0}'' does not support the service: ''{1}''.\nEnsure you have selected a suitable default before launching.
 ConnectionSettingsPage.AgentTestTabLabel=Set Connection Settings
 ConnectionSettingsPage.ConnectionSettingsGroupLabel=Connection Settings
 ConnectionSettingsPage.DeviceOSComboToolTip=Used to determine which installer version to compare against the version reported by the remote agent
@@ -57,6 +63,7 @@
 ConnectionStatusSelectorContribution_NoDefaultConnectionMessage=No default connection
 ConnectionStatusSelectorContribution_SelectTheDefaultConnectionMessage=Select the default connection:
 ConnectionStatusSelectorContribution.ConnectionStatusFormat={0}: {1}
+ConnectionStatusSelectorContribution.IconTooltipPrefixMessage=Click to open the Remote Connections View.\n\n
 ConnectionStatusSelectorContribution.InUse=In use
 ConnectionStatusSelectorContribution.NoConnectionsDefinedOrDetected=No connections defined or detected
 ConnectionStatusSelectorContribution.NoDynamicOrManualConnectionsTooltip=No default connection selected.
--- a/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/ui/AttachMainTab.java	Wed Dec 30 09:59:34 2009 -0600
+++ b/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/ui/AttachMainTab.java	Wed Dec 30 11:43:43 2009 -0600
@@ -23,6 +23,7 @@
 import com.nokia.cdt.internal.debug.launch.LaunchPlugin;
 
 import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
 import org.eclipse.debug.core.ILaunchConfiguration;
 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
 import org.eclipse.swt.SWT;
@@ -109,10 +110,11 @@
 	public boolean isValid(ILaunchConfiguration config) {
 		boolean result = super.isValid(config);
 		if (result) {
-			connection = clientSiteUI.getSelectedConnection();
-			if (connection == null) {
-				setErrorMessage(Messages.getString("AttachMainTab.NoConnectionError")); //$NON-NLS-1$
-				result = false;
+			IStatus status = clientSiteUI.getSelectionStatus();
+			if (!status.isOK()) {
+				// unfortunately, no way to display a warning here...
+				setErrorMessage(status.getMessage());
+				result = status.getSeverity() != IStatus.ERROR;
 			}
 		}
 		return result;
--- a/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/ui/RunModeMainTab.java	Wed Dec 30 09:59:34 2009 -0600
+++ b/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/ui/RunModeMainTab.java	Wed Dec 30 11:43:43 2009 -0600
@@ -23,6 +23,7 @@
 import org.eclipse.core.resources.IResourceChangeListener;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.debug.core.ILaunchConfiguration;
 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
@@ -236,10 +237,11 @@
 			else {
 				if (clientSiteUI != null)
 				{
-					connection = clientSiteUI.getSelectedConnection();
-					if (connection == null) {
-						setErrorMessage(Messages.getString("RunModeMainTab.NoConnectionError")); //$NON-NLS-1$
-						result = false;
+					IStatus status = clientSiteUI.getSelectionStatus();
+					if (!status.isOK()) {
+						// unfortunately, no way to display a warning here...
+						setErrorMessage(status.getMessage());
+						result = status.getSeverity() != IStatus.ERROR;
 					}
 				}
 			}
--- a/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/ui/messages.properties	Wed Dec 30 09:59:34 2009 -0600
+++ b/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/ui/messages.properties	Wed Dec 30 11:43:43 2009 -0600
@@ -10,7 +10,6 @@
 AddEditFileToTransferDialog.7=File to transfer does not exist
 AddEditFileToTransferDialog.8=No file to transfer specified
 AddEditFileToTransferDialog.9=Invalid target path specified
-AttachMainTab.NoConnectionError=A valid remote connection must be selected
 ChooseProcessDialog.IDLabel=ID
 ChooseProcessDialog.Message=Choose a process to attach
 ChooseProcessDialog.NameLabel=Name
@@ -175,7 +174,6 @@
 RunModeMainTab.6=Remote process to launch not specified.
 RunModeMainTab.7=Remote process to launch must be an absolute path.
 RunModeMainTab.8=The project associated with this launch configuration.
-RunModeMainTab.NoConnectionError=A valid remote connection must be selected. If none exist, create a new one.
 SophiaTargetInterfaceTab.0=Sophia Target Interface (WTI.dll) location
 SophiaTargetInterfaceTab.1=Browse
 SophiaTargetInterfaceTab.10=The absolute path on your PC of the Carbide C++ interface to Sophia JTAG emulator (wti.dll)
--- a/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/wizard/TRKConnectionWizardPage.java	Wed Dec 30 09:59:34 2009 -0600
+++ b/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/wizard/TRKConnectionWizardPage.java	Wed Dec 30 11:43:43 2009 -0600
@@ -23,6 +23,7 @@
 import com.nokia.cdt.internal.debug.launch.LaunchPlugin;
 import com.nokia.cpp.internal.api.utils.core.Check;
 
+import org.eclipse.core.runtime.IStatus;
 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
 import org.eclipse.jface.dialogs.Dialog;
 import org.eclipse.jface.wizard.WizardPage;
@@ -87,11 +88,17 @@
     
     protected void validatePage() {
     	setErrorMessage(null);
+    	setMessage(null);
     	setPageComplete(true);
-		connection = clientSiteUI.getSelectedConnection();
-		if (connection == null) {
-			setErrorMessage(Messages.getString("TRKConnectionWizardPage.NoConnectionError")); //$NON-NLS-1$
-			setPageComplete(false);
+		IStatus status = clientSiteUI.getSelectionStatus();
+		if (!status.isOK()) {
+			if (status.getSeverity() == IStatus.ERROR) {
+				setErrorMessage(status.getMessage());
+				setPageComplete(false);
+			} else {
+				setMessage(status.getMessage(), 
+						status.getSeverity() == IStatus.WARNING ? WARNING : INFORMATION); 
+			}
 		}
     }