# HG changeset patch # User dadubrow # Date 1265052438 21600 # Node ID d66843399035daef210668be5d4d509364195525 # Parent 3f37e327885c19118bd4cd19a54afc5998038e9d backport hostside pnp diff -r 3f37e327885c -r d66843399035 connectivity/com.nokia.carbide.remoteConnections.tests/plugin.xml --- a/connectivity/com.nokia.carbide.remoteConnections.tests/plugin.xml Mon Feb 01 12:38:42 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections.tests/plugin.xml Mon Feb 01 13:27:18 2010 -0600 @@ -63,5 +63,11 @@ class="com.nokia.carbide.remoteconnections.tests.extensions.DefaultProvidingTCPIPService"> + + + + diff -r 3f37e327885c -r d66843399035 connectivity/com.nokia.carbide.remoteConnections.tests/src/com/nokia/carbide/remoteconnections/tests/RegistryTest.java --- a/connectivity/com.nokia.carbide.remoteConnections.tests/src/com/nokia/carbide/remoteconnections/tests/RegistryTest.java Mon Feb 01 12:38:42 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections.tests/src/com/nokia/carbide/remoteconnections/tests/RegistryTest.java Mon Feb 01 13:27:18 2010 -0600 @@ -67,7 +67,7 @@ public void testStoreAndLoadConnections() { Registry.instance().disposeConnections(); - Collection connections = RemoteConnectionsActivator.getConnectionsManager().getConnections(); + Collection connections = Registry.instance().getConnections(); assertTrue(connections.isEmpty()); IConnectionType ct = @@ -78,18 +78,18 @@ assertNotNull(cf); IConnection connection = cf.createConnection(cf.getSettingsFromUI()); connection.setIdentifier("test 1"); - RemoteConnectionsActivator.getConnectionsManager().addConnection(connection); + Registry.instance().addConnection(connection); - connections = RemoteConnectionsActivator.getConnectionsManager().getConnections(); + connections = Registry.instance().getConnections(); assertEquals(1, connections.size()); - RemoteConnectionsActivator.getConnectionsManager().storeConnections(); + Registry.instance().storeConnections(); - RemoteConnectionsActivator.getConnectionsManager().removeConnection(connection); - connections = RemoteConnectionsActivator.getConnectionsManager().getConnections(); + Registry.instance().removeConnection(connection); + connections = Registry.instance().getConnections(); assertTrue(connections.isEmpty()); - RemoteConnectionsActivator.getConnectionsManager().loadConnections(); - connections = RemoteConnectionsActivator.getConnectionsManager().getConnections(); + Registry.instance().loadConnections(); + connections = Registry.instance().getConnections(); assertEquals(1, connections.size()); connection = connections.iterator().next(); @@ -121,19 +121,19 @@ public void displayChanged() {} }; - RemoteConnectionsActivator.getConnectionsManager().addConnectionStoreChangedListener(listener); - RemoteConnectionsActivator.getConnectionsManager().addConnection(connection); + Registry.instance().addConnectionStoreChangedListener(listener); + Registry.instance().addConnection(connection); assertTrue(listenerCalled[0]); listenerCalled[0] = false; - RemoteConnectionsActivator.getConnectionsManager().removeConnection(connection); + Registry.instance().removeConnection(connection); assertTrue(listenerCalled[0]); - RemoteConnectionsActivator.getConnectionsManager().removeConnectionStoreChangedListener(listener); + Registry.instance().removeConnectionStoreChangedListener(listener); listenerCalled[0] = false; - RemoteConnectionsActivator.getConnectionsManager().addConnection(connection); + Registry.instance().addConnection(connection); assertFalse(listenerCalled[0]); - RemoteConnectionsActivator.getConnectionsManager().removeConnection(connection); + Registry.instance().removeConnection(connection); assertFalse(listenerCalled[0]); } @@ -147,12 +147,12 @@ assertNotNull(cf); IConnection connection = cf.createConnection(cf.getSettingsFromUI()); connection.setDisplayName("foo"); - RemoteConnectionsActivator.getConnectionsManager().addConnection(connection); + Registry.instance().addConnection(connection); String id = connection.getIdentifier(); connection = cf.createConnection(cf.getSettingsFromUI()); connection.setIdentifier(id); connection.setDisplayName("foo"); - RemoteConnectionsActivator.getConnectionsManager().addConnection(connection); + Registry.instance().addConnection(connection); assertFalse(id.equals(connection.getIdentifier())); } @@ -166,11 +166,11 @@ assertNotNull(cf); IConnection connection = cf.createConnection(cf.getSettingsFromUI()); connection.setDisplayName("foo"); - RemoteConnectionsActivator.getConnectionsManager().addConnection(connection); + Registry.instance().addConnection(connection); assertEquals("foo", connection.getDisplayName()); connection = cf.createConnection(cf.getSettingsFromUI()); connection.setDisplayName("foo"); - RemoteConnectionsActivator.getConnectionsManager().addConnection(connection); + Registry.instance().addConnection(connection); assertFalse("foo".equals(connection.getIdentifier())); } diff -r 3f37e327885c -r d66843399035 connectivity/com.nokia.carbide.remoteConnections.tests/src/com/nokia/carbide/remoteconnections/tests/extensions/AbstractServiceDialogAction.java --- a/connectivity/com.nokia.carbide.remoteConnections.tests/src/com/nokia/carbide/remoteconnections/tests/extensions/AbstractServiceDialogAction.java Mon Feb 01 12:38:42 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections.tests/src/com/nokia/carbide/remoteconnections/tests/extensions/AbstractServiceDialogAction.java Mon Feb 01 13:27:18 2010 -0600 @@ -49,30 +49,23 @@ public void run(IAction action) { IService service = findService(getServiceId()); - IConnection connection = getPersistedConnection(getServiceId()); + String connection = getPersistedConnection(getServiceId()); POUConnectionDialog dialog = new POUConnectionDialog(service, connection); dialog.open(); connection = dialog.getSelectedConnection(); persistConnection(getServiceId(), connection); } - protected void persistConnection(String key, IConnection connection) { + protected void persistConnection(String key, String connection) { if (connection != null) { - Activator.getDefault().getPreferenceStore().putValue(key, connection.getIdentifier()); + Activator.getDefault().getPreferenceStore().putValue(key, connection); Activator.getDefault().savePluginPreferences(); } } - protected IConnection getPersistedConnection(String key) { + protected String getPersistedConnection(String key) { String connectionId = Activator.getDefault().getPreferenceStore().getString(key); - if (connectionId != null) { - Collection connections = RemoteConnectionsActivator.getConnectionsManager().getConnections(); - for (IConnection connection : connections) { - if (connection.getIdentifier().equals(connectionId)) - return connection; - } - } - return null; + return connectionId; } protected IService findService(String serviceId) { diff -r 3f37e327885c -r d66843399035 connectivity/com.nokia.carbide.remoteConnections.tests/src/com/nokia/carbide/remoteconnections/tests/extensions/IntervalConnection.java --- a/connectivity/com.nokia.carbide.remoteConnections.tests/src/com/nokia/carbide/remoteconnections/tests/extensions/IntervalConnection.java Mon Feb 01 12:38:42 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections.tests/src/com/nokia/carbide/remoteconnections/tests/extensions/IntervalConnection.java Mon Feb 01 13:27:18 2010 -0600 @@ -18,75 +18,23 @@ package com.nokia.carbide.remoteconnections.tests.extensions; -import com.nokia.carbide.remoteconnections.interfaces.IConnection; +import java.util.HashMap; +import java.util.Map; + +import com.nokia.carbide.remoteconnections.interfaces.AbstractConnection; import com.nokia.carbide.remoteconnections.interfaces.IConnectionType; import com.nokia.cpp.internal.api.utils.core.Check; -import java.util.Collections; -import java.util.Map; - -public class IntervalConnection implements IConnection { +public class IntervalConnection extends AbstractConnection { private int msInterval; - private String id; - private String name; - private IConnectionType connectionType; public IntervalConnection(IConnectionType connectionType) { - this.connectionType = connectionType; - } - - /* (non-Javadoc) - * @see com.nokia.carbide.remoteconnections.extensions.IConnection#dispose() - */ - public void dispose() { - } - - /* (non-Javadoc) - * @see com.nokia.carbide.remoteconnections.extensions.IConnection#getConnectionType() - */ - public IConnectionType getConnectionType() { - return connectionType; + super(connectionType, new HashMap()); + msInterval = Integer.parseInt(IntervalConnectionType.VALUE); + getSettings().put(IntervalConnectionType.KEY, Integer.toString(msInterval)); } - /* (non-Javadoc) - * @see com.nokia.carbide.remoteconnections.extensions.IConnection#getIdentifier() - */ - public String getIdentifier() { - return id; - } - - /* (non-Javadoc) - * @see com.nokia.carbide.remoteconnections.interfaces.IConnection#getDisplayName() - */ - public String getDisplayName() { - return name; - } - - /* (non-Javadoc) - * @see com.nokia.carbide.remoteconnections.interfaces.IConnection#setDisplayName(java.lang.String) - */ - public void setDisplayName(String name) { - this.name = name; - } - - /* (non-Javadoc) - * @see com.nokia.carbide.remoteconnections.extensions.IConnection#getSettings() - */ - public Map getSettings() { - return Collections.singletonMap(IntervalConnectionType.KEY, Integer.toString(msInterval)); - } - - /* (non-Javadoc) - * @see com.nokia.carbide.remoteconnections.extensions.IConnection#setIdentifier(java.lang.String) - */ - public void setIdentifier(String id) { - this.id = id; - } - - /* (non-Javadoc) - * @see com.nokia.carbide.remoteconnections.extensions.IConnection#updateSettings(java.util.Map) - */ public void updateSettings(Map newSettings) { Check.checkContract(newSettings.containsKey(IntervalConnectionType.KEY)); String string = newSettings.get(IntervalConnectionType.KEY); @@ -103,9 +51,10 @@ @Override public String toString() { - return name; + return getDisplayName(); } public void useConnection(boolean use) { + // TODO Auto-generated method stub } } diff -r 3f37e327885c -r d66843399035 connectivity/com.nokia.carbide.remoteConnections.tests/src/com/nokia/carbide/remoteconnections/tests/extensions/POUConnectionDialog.java --- a/connectivity/com.nokia.carbide.remoteConnections.tests/src/com/nokia/carbide/remoteconnections/tests/extensions/POUConnectionDialog.java Mon Feb 01 12:38:42 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections.tests/src/com/nokia/carbide/remoteconnections/tests/extensions/POUConnectionDialog.java Mon Feb 01 13:27:18 2010 -0600 @@ -26,16 +26,16 @@ public class POUConnectionDialog extends TrayDialog { private final IService service; - private IClientServiceSiteUI clientSiteUI; - private IConnection connection; + private IClientServiceSiteUI2 clientSiteUI; + private String connection; /** * Create the dialog */ - public POUConnectionDialog(IService service, IConnection initialConnection) { + public POUConnectionDialog(IService service, String initialConnection) { super((Shell) null); this.service = service; this.connection = initialConnection; - clientSiteUI = RemoteConnectionsActivator.getConnectionsManager().getClientSiteUI(service); + clientSiteUI = RemoteConnectionsActivator.getConnectionsManager().getClientSiteUI2(service); setShellStyle(getShellStyle() | SWT.RESIZE); } @@ -58,7 +58,7 @@ return container; } - public IConnection getSelectedConnection() { + public String getSelectedConnection() { return clientSiteUI.getSelectedConnection(); } diff -r 3f37e327885c -r d66843399035 connectivity/com.nokia.carbide.remoteConnections.tests/src/com/nokia/carbide/remoteconnections/tests/extensions/RandomCycleConnectedService.java --- a/connectivity/com.nokia.carbide.remoteConnections.tests/src/com/nokia/carbide/remoteconnections/tests/extensions/RandomCycleConnectedService.java Mon Feb 01 12:38:42 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections.tests/src/com/nokia/carbide/remoteconnections/tests/extensions/RandomCycleConnectedService.java Mon Feb 01 13:27:18 2010 -0600 @@ -18,19 +18,27 @@ package com.nokia.carbide.remoteconnections.tests.extensions; -import com.nokia.carbide.remoteconnections.interfaces.*; -import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus.EStatus; -import com.nokia.cpp.internal.api.utils.core.Check; -import com.nokia.cpp.internal.api.utils.core.ListenerList; +import java.text.DateFormat; +import java.util.Date; +import java.util.Random; import org.eclipse.jface.action.IStatusLineManager; import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.*; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; import org.osgi.framework.Version; -import java.text.DateFormat; -import java.util.Date; -import java.util.Random; +import com.nokia.carbide.remoteconnections.interfaces.IConnectedService; +import com.nokia.carbide.remoteconnections.interfaces.IConnection; +import com.nokia.carbide.remoteconnections.interfaces.IService; +import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus.EStatus; +import com.nokia.cpp.internal.api.utils.core.ListenerList; public class RandomCycleConnectedService implements IConnectedService { diff -r 3f37e327885c -r d66843399035 connectivity/com.nokia.carbide.remoteConnections/META-INF/MANIFEST.MF --- a/connectivity/com.nokia.carbide.remoteConnections/META-INF/MANIFEST.MF Mon Feb 01 12:38:42 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/META-INF/MANIFEST.MF Mon Feb 01 13:27:18 2010 -0600 @@ -11,13 +11,15 @@ com.nokia.cpp.utils.core, org.eclipse.emf.ecore.xmi;bundle-version="2.4.0", org.eclipse.core.net;bundle-version="1.1.0", - org.eclipse.help;bundle-version="3.4.0" + org.eclipse.help;bundle-version="3.4.0", + com.nokia.cpp.utils.ui Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-ActivationPolicy: lazy Export-Package: com.nokia.carbide.installpackages, com.nokia.carbide.installpackages.gen.InstallPackages, com.nokia.carbide.remoteconnections, com.nokia.carbide.remoteconnections.interfaces, + com.nokia.carbide.remoteconnections.internal.api, com.nokia.carbide.remoteconnections.internal.registry;x-friends:="com.nokia.carbide.remoteConnections.tests,com.nokia.carbide.tests.debug", com.nokia.carbide.remoteconnections.settings.ui;x-friends:="com.nokia.carbide.tests.debug" Bundle-ClassPath: ., diff -r 3f37e327885c -r d66843399035 connectivity/com.nokia.carbide.remoteConnections/plugin.xml --- a/connectivity/com.nokia.carbide.remoteConnections/plugin.xml Mon Feb 01 12:38:42 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/plugin.xml Mon Feb 01 13:27:18 2010 -0600 @@ -5,6 +5,7 @@ + @@ -76,4 +77,47 @@ + + + + + + + + + + + + + + + + + + + + + + + diff -r 3f37e327885c -r d66843399035 connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/installpackages/InstallPackages.java --- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/installpackages/InstallPackages.java Mon Feb 01 12:38:42 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/installpackages/InstallPackages.java Mon Feb 01 13:27:18 2010 -0600 @@ -66,7 +66,7 @@ private final IServerData serverData; private List packageList; - private IPath serverPath; + private String serverPath; public InstallPackages(IServerData serverData, IRunnableContext runnableContext) { Check.checkArg(serverData); @@ -166,7 +166,7 @@ } out.close(); in.close(); - URL url = masterFile.toURL(); + URL url = masterFile.toURI().toURL(); return loadPackages(url); } @@ -214,11 +214,11 @@ } private String getRelativePath(String installFilePath) { - IPath path = getServerPath(); - return path.append(installFilePath).toString(); + String path = getServerPath(); + return path + "/" + installFilePath; //$NON-NLS-1$ } - private IPath getServerPath() { + private String getServerPath() { if (serverPath != null) return serverPath; // see if there's an alternate server, otherwise use IServerData @@ -235,10 +235,10 @@ String key = serverData.getRemoteAgentInstallerProvider().getService().getIdentifier(); String pathStr = (String) properties.get(key); if (pathStr != null) - return serverPath = new Path(pathStr); + return serverPath = pathStr; } catch (IOException e) { RemoteConnectionsActivator.logError(e); } - return new Path(""); //$NON-NLS-1$ + return ""; //$NON-NLS-1$ } } diff -r 3f37e327885c -r d66843399035 connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/RemoteConnectionsActivator.java --- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/RemoteConnectionsActivator.java Mon Feb 01 12:38:42 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/RemoteConnectionsActivator.java Mon Feb 01 13:27:18 2010 -0600 @@ -16,18 +16,34 @@ */ package com.nokia.carbide.remoteconnections; -import com.nokia.carbide.remoteconnections.interfaces.IConnectionTypeProvider; -import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager; -import com.nokia.carbide.remoteconnections.internal.registry.Registry; -import com.nokia.cpp.internal.api.utils.core.Logging; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; -import org.eclipse.core.net.proxy.IProxyService; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.IFilter; import org.eclipse.swt.widgets.Control; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; -import org.osgi.util.tracker.ServiceTracker; +import org.osgi.service.prefs.BackingStoreException; + +import com.nokia.carbide.remoteconnections.interfaces.IConnectionTypeProvider; +import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager; +import com.nokia.carbide.remoteconnections.internal.api.IDeviceDiscoveryAgent; +import com.nokia.carbide.remoteconnections.internal.api.IDeviceDiscoveryAgent.IPrerequisiteStatus; +import com.nokia.carbide.remoteconnections.internal.registry.Registry; +import com.nokia.carbide.remoteconnections.internal.ui.DeviceDiscoveryPrequisiteErrorDialog; +import com.nokia.cpp.internal.api.utils.core.Logging; +import com.nokia.cpp.internal.api.utils.ui.RunRunnableWhenWorkbenchVisibleJob; +import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils; /** * The activator class controls the plug-in life cycle @@ -37,51 +53,84 @@ // The plug-in ID public static final String PLUGIN_ID = "com.nokia.carbide.remoteConnections"; //$NON-NLS-1$ + private static final String DISCOVERY_AGENT_EXTENSION = PLUGIN_ID + ".deviceDiscoveryAgent"; //$NON-NLS-1$ + // The shared instance private static RemoteConnectionsActivator plugin; - - // A service tracker for the proxy service - private ServiceTracker proxyServiceTracker; - + + private Collection discoveryAgents; + private static final String IGNORE_AGENT_LOAD_ERRORS_KEY = "ignoreAgentLoadErrors"; //$NON-NLS-1$ + /** * The constructor */ public RemoteConnectionsActivator() { } - - /** - * Returns IProxyService. - * @deprecated - */ - public IProxyService getProxyService() { - return (IProxyService) proxyServiceTracker.getService(); - } - - /* - * (non-Javadoc) - * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) - */ public void start(BundleContext context) throws Exception { super.start(context); plugin = this; Registry instance = Registry.instance(); instance.loadExtensions(); instance.loadConnections(); - this.proxyServiceTracker = new ServiceTracker(context, IProxyService.class.getName(), null); - this.proxyServiceTracker.open(); + + RunRunnableWhenWorkbenchVisibleJob.start(new Runnable() { + public void run() { + if (!ignoreAgentLoadErrors()) + checkPrerequisites(); + + loadAndStartDeviceDiscoveryAgents(); + } + }); + } + + private boolean ignoreAgentLoadErrors() { + return getPreferenceStore().getBoolean(IGNORE_AGENT_LOAD_ERRORS_KEY); } - /* - * (non-Javadoc) - * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) - */ + private void checkPrerequisites() { + final Map agentToStatusMap = + new HashMap(); + + // load the extensions just to check statuses + Collection agents = new ArrayList(); + loadExtensions(DISCOVERY_AGENT_EXTENSION, null, agents, null); + + for (IDeviceDiscoveryAgent agent : agents) { + IPrerequisiteStatus status = agent.getPrerequisiteStatus(); + if (!status.isOK()) { + agentToStatusMap.put(agent, status); + } + } + + if (!agentToStatusMap.isEmpty()) { + DeviceDiscoveryPrequisiteErrorDialog dlg = new DeviceDiscoveryPrequisiteErrorDialog(WorkbenchUtils.getSafeShell()); + for (Entry entry : agentToStatusMap.entrySet()) { + IDeviceDiscoveryAgent agent = entry.getKey(); + IPrerequisiteStatus status = entry.getValue(); + dlg.addAgentData(agent.getDisplayName(), status.getErrorText(), status.getURL()); + } + dlg.open(); + if (dlg.isDontAskAgainChecked()) + storeIgnoreAgentLoadErrorsFlag(); + } + } + public void stop(BundleContext context) throws Exception { + stopDeviceDiscoveryAgents(); Registry.instance().storeConnections(); Registry.instance().disposeConnections(); plugin = null; super.stop(context); - this.proxyServiceTracker.close(); + } + + private void storeIgnoreAgentLoadErrorsFlag() { + getPreferenceStore().setValue(IGNORE_AGENT_LOAD_ERRORS_KEY, true); + try { + new InstanceScope().getNode(PLUGIN_ID).flush(); + } catch (BackingStoreException e) { + logError(e); + } } /** @@ -131,4 +180,63 @@ public static void setHelp(Control control, String id) { PlatformUI.getWorkbench().getHelpSystem().setHelp(control, PLUGIN_ID + id); //$NON-NLS-1$ } + + private void loadAndStartDeviceDiscoveryAgents() { + String loadError = Messages.getString("RemoteConnectionsActivator.DiscoveryAgentLoadError"); //$NON-NLS-1$ + discoveryAgents = new ArrayList(); + loadExtensions(DISCOVERY_AGENT_EXTENSION, loadError, discoveryAgents, new IFilter() { + public boolean select(Object toTest) { + if (toTest instanceof IDeviceDiscoveryAgent) { + try { + ((IDeviceDiscoveryAgent) toTest).start(); + return true; + } catch (Throwable e) { + // since we launch arbitrary code, catch any exception to prevent killing the view + logError(e); + } + } + return false; + } + }); + + } + + private void stopDeviceDiscoveryAgents() { + for (IDeviceDiscoveryAgent agent : discoveryAgents) { + try { + agent.stop(); + } catch (CoreException e) { + logError(e); + } + } + + } + + public static void log(String errorStr, Throwable t) { + RemoteConnectionsActivator p = RemoteConnectionsActivator.getDefault(); + String error = errorStr; + if (t != null) { + error += " : " + t.getLocalizedMessage(); //$NON-NLS-1$ + } + Logging.log(p, Logging.newStatus(p, IStatus.ERROR, error)); + if (t instanceof CoreException) + Logging.log(p, ((CoreException) t).getStatus()); + } + + @SuppressWarnings("unchecked") + public static void loadExtensions(String extensionId, String loadError, Collection extensionObjects, IFilter filter) { + IConfigurationElement[] elements = + Platform.getExtensionRegistry().getConfigurationElementsFor(extensionId); + for (IConfigurationElement element : elements) { + try { + T extObject = (T) element.createExecutableExtension("class"); //$NON-NLS-1$ + if (filter == null || filter.select(extObject)) + extensionObjects.add(extObject); + } + catch (CoreException e) { + if (loadError != null) + RemoteConnectionsActivator.log(loadError, e); + } + } + } } diff -r 3f37e327885c -r d66843399035 connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/AbstractConnectedService.java --- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/AbstractConnectedService.java Mon Feb 01 12:38:42 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/AbstractConnectedService.java Mon Feb 01 13:27:18 2010 -0600 @@ -18,6 +18,7 @@ import com.nokia.carbide.remoteconnections.Messages; import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus.EStatus; +import com.nokia.carbide.remoteconnections.internal.api.IConnectedService2; import com.nokia.cpp.internal.api.utils.core.Check; import com.nokia.cpp.internal.api.utils.core.ListenerList; import com.nokia.cpp.internal.api.utils.core.ObjectUtils; @@ -30,8 +31,10 @@ import org.eclipse.swt.widgets.Display; import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; +import java.util.Map; -public abstract class AbstractConnectedService implements IConnectedService { +public abstract class AbstractConnectedService implements IConnectedService2 { public final static int TIMEOUT = 2000; @@ -124,10 +127,12 @@ protected Status currentStatus; protected Tester tester; protected boolean manualTesting; + private Map properties; public AbstractConnectedService(IService service, AbstractSynchronizedConnection connection) { this.service = service; this.connection = connection; + properties = new HashMap(); } public void setRunnableContext(IRunnableContext runnableContext) { @@ -229,4 +234,8 @@ Messages.getString("AbstractConnectedService.UserDisabledMessage")); //$NON-NLS-1$ } } + + public Map getProperties() { + return properties; + } } \ No newline at end of file diff -r 3f37e327885c -r d66843399035 connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/AbstractConnection.java --- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/AbstractConnection.java Mon Feb 01 12:38:42 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/AbstractConnection.java Mon Feb 01 13:27:18 2010 -0600 @@ -18,25 +18,67 @@ package com.nokia.carbide.remoteconnections.interfaces; -import com.nokia.carbide.remoteconnections.interfaces.IConnection; -import com.nokia.carbide.remoteconnections.interfaces.IConnectionType; - import java.util.HashMap; import java.util.Map; +import org.eclipse.jface.resource.ImageDescriptor; + +import com.nokia.carbide.remoteconnections.internal.api.IConnection2; +import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus.EConnectionStatus; +import com.nokia.cpp.internal.api.utils.core.Check; +import com.nokia.cpp.internal.api.utils.core.ListenerList; + /** * A standard implementation of IConnection */ -public abstract class AbstractConnection implements IConnection { +public abstract class AbstractConnection implements IConnection2 { + + public static class ConnectionStatus implements IConnectionStatus { + private EConnectionStatus estatus; + private String shortDescription; + private String longDescription; + + public ConnectionStatus(EConnectionStatus estatus, String shortDescription, String longDescription) { + this.estatus = estatus; + this.shortDescription = shortDescription; + this.longDescription = longDescription; + } + + public EConnectionStatus getEConnectionStatus() { + return estatus; + } + + public String getShortDescription() { + return shortDescription; + } + + public String getLongDescription() { + return longDescription; + } + + public void setEStatus(EConnectionStatus estatus) { + this.estatus = estatus; + } + + public void setDescriptions(String shortDescription, String longDescription) { + this.shortDescription = shortDescription; + this.longDescription = longDescription; + } + } private final IConnectionType connectionType; private final Map settings; private String name; private String id; + private boolean dynamic; + private IConnectionStatus status; + private ImageDescriptor imageDescriptor; + private ListenerList listeners; public AbstractConnection(IConnectionType connectionType, Map settings) { this.connectionType = connectionType; this.settings = new HashMap(settings); + status = new ConnectionStatus(EConnectionStatus.NONE, "", ""); //$NON-NLS-1$ //$NON-NLS-2$ } public void dispose() { @@ -71,4 +113,50 @@ settings.putAll(newSettings); } + public boolean isDynamic() { + return dynamic; + } + + public void setDynamic(boolean dynamic) { + this.dynamic = dynamic; + } + + public IConnectionStatus getStatus() { + return status; + } + + public void setStatus(IConnectionStatus status) { + Check.checkArg(status); + this.status = status; + fireStatusChanged(); + } + + public void addStatusChangedListener(IConnectionStatusChangedListener listener) { + if (listeners == null) + listeners = new ListenerList(); + listeners.add(listener); + } + + public void removeStatusChangedListener(IConnectionStatusChangedListener listener) { + if (listeners != null) + listeners.remove(listener); + } + + public void fireStatusChanged() { + if (listeners == null) + return; + for (IConnectionStatusChangedListener listener : listeners) { + listener.statusChanged(status); + } + } + + public ImageDescriptor getImageDescriptor() { + return imageDescriptor; + } + + public void setImageDescriptor(ImageDescriptor imageDescriptor) { + this.imageDescriptor = imageDescriptor; + } + + } diff -r 3f37e327885c -r d66843399035 connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/IClientServiceSiteUI.java --- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/IClientServiceSiteUI.java Mon Feb 01 12:38:42 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/IClientServiceSiteUI.java Mon Feb 01 13:27:18 2010 -0600 @@ -22,6 +22,9 @@ /** * The user interface for picking a connection to use that can be added to client service user interfaces + * @noimplement + * @noextend + * @deprecated new code which wants to use default connections should use {@link IClientServiceSiteUI2} */ public interface IClientServiceSiteUI { @@ -61,5 +64,4 @@ * @param listener IListener */ void removeListener(IListener listener); - } diff -r 3f37e327885c -r d66843399035 connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/IConnectionFactory.java --- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/IConnectionFactory.java Mon Feb 01 12:38:42 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/IConnectionFactory.java Mon Feb 01 13:27:18 2010 -0600 @@ -33,7 +33,7 @@ /** * Creates a composite with UI for editing settings, optionally initialized with initialSettings.
- * Can provide optional errorReporter and optional listener. + * Can provide optional errorReporter and optional listener. Assumes parent has GridLayout * @param parent Composite * @param errorReporter IValidationErrorReporter * @param initialSettings Map may be null diff -r 3f37e327885c -r d66843399035 connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/IConnectionTypeProvider.java --- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/IConnectionTypeProvider.java Mon Feb 01 12:38:42 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/IConnectionTypeProvider.java Mon Feb 01 13:27:18 2010 -0600 @@ -27,13 +27,37 @@ */ public interface IConnectionTypeProvider { - IConnectionType getConnectionType(String identifier); + /** + * Returns IConnectionType corresponding to the id or null + * @param id String + * @return IConnectionType + */ + IConnectionType getConnectionType(String id); + /** + * Returns all the known connection types + * @return Collection + */ Collection getConnectionTypes(); + /** + * Returns a collection of IService that are supported over a connection type + * @param connectionType IConnectionType + * @return Collection + */ Collection getCompatibleServices(IConnectionType connectionType); + /** + * Returns IService corresponding to the id or null + * @param id String + * @return IService + */ IService findServiceByID(String id); + /** + * Returns a collection of connection type ids that support a service + * @param service IService + * @return Collection + */ Collection getCompatibleConnectionTypeIds(IService service); } \ No newline at end of file diff -r 3f37e327885c -r d66843399035 connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/IConnectionsManager.java --- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/IConnectionsManager.java Mon Feb 01 12:38:42 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/IConnectionsManager.java Mon Feb 01 13:27:18 2010 -0600 @@ -1,5 +1,5 @@ /* -* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). * All rights reserved. * This component and the accompanying materials are made available * under the terms of the License "Eclipse Public License v1.0" @@ -21,39 +21,204 @@ import java.util.Collection; +import org.eclipse.core.runtime.CoreException; + +import com.nokia.carbide.remoteconnections.internal.api.IConnection2; + /** * An interface encapsulating the manager of connection objects + * @noimplement */ public interface IConnectionsManager { + /** + * Listener interface for connection manager events + * (These tend to be used internally by remote connections UI) + * @deprecated + */ public interface IConnectionsManagerListener { void connectionStoreChanged(); void displayChanged(); } + /** + * Internal method for loading connections from persisted state + * @deprecated + */ void loadConnections(); + /** + * Internal method for persisting connections + * @deprecated + */ void storeConnections(); + + /** + * Listener interface for connections which are added, removed and set as current + * @since 3.0 + */ + public interface IConnectionListener { + void connectionAdded(IConnection connection); + void connectionRemoved(IConnection connection); + void currentConnectionSet(IConnection connection); + } + + /** + * Add a listener for internal connection manager events + * @param listener IConnectionsManagerListener + * @deprecated + */ void addConnectionStoreChangedListener(IConnectionsManagerListener listener); + /** + * Remove a listener for internal connection manager events + * @param listener IConnectionsManagerListener + * @deprecated + */ void removeConnectionStoreChangedListener(IConnectionsManagerListener listener); + /** + * Add a connection to the system + * @param connection IConnection + */ void addConnection(IConnection connection); + /** + * Remove a connection from the system + * @param connection IConnection + */ void removeConnection(IConnection connection); + /** + * Return all connections in the system + * @return Collection + */ Collection getConnections(); + /** + * Return all the connected services for a connection + * @param connection IConnection + * @return Collection + */ Collection getConnectedServices(IConnection connection); + /** + * Returns a unique id to be used for a new connection + * @return String + */ String getUniqueConnectionId(); + /** + * Returns whether some display name is in use for any existing connections + * @param name String + * @return boolean + */ boolean connectionNameInUse(String name); + /** + * Fires internal display changed event + * @deprecated + */ void updateDisplays(); + /** + * Returns the IClientServiceSiteUI for a service. Filters connection types to those that + * are supported by the service. Connection list UI as well as new and edit wizards are filtered. + * @param service IService + * @return IClientServiceSiteUI + * @deprecated use {@link #getClientSiteUI2(IService)} + */ IClientServiceSiteUI getClientSiteUI(IService service); + /** + * Internal method to create the connected service over a connection (for service testing) + * @param service IService + * @param connection IConnection + * @return IConnectedService + * @deprecated + */ IConnectedService createConnectedService(IService service, IConnection connection); + + /** + * Add new IConnectionListener + * @param listener IConnectionListener + * @since 3.0 + */ + void addConnectionListener(IConnectionListener listener); + + /** + * Remove IConnectionListener + * @param listener IConnectionListener + * @since 3.0 + */ + void removeConnectionListener(IConnectionListener listener); + + /** + * Sets the current connection. + * @param connection IConnection + * @since 3.0 + */ + void setCurrentConnection(IConnection connection); + + /** + * Returns the current connection. + * @return IConnection + * @since 3.0 + */ + IConnection getCurrentConnection(); + + /** + * Returns the IClientServiceSiteUI2 for a service. Filters connection types to those that + * are supported by the service. Connection list UI as well as new and edit wizards are filtered. + * Allows selecting a "current" connection which maps to #getCurrentConnection() + * when you use #ensureConenction(). + * @param service IService + * @return IClientServiceSiteUI2 + * @since 3.0 + */ + IClientServiceSiteUI2 getClientSiteUI2(IService service); + + /** + * 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. + * @param connectionId String + * @param service IService + * @return IConnection + * @throws CoreException + * @since 3.0 + */ + IConnection ensureConnection(String connectionId, IService service) throws CoreException; + + /** + * Returns a connection from an id (including the current connection id) or null if none found. + * @param connectionId String + * @param service IService + * @return IConnection + * @throws CoreException + * @since 3.0 + */ + IConnection findConnection(String connectionId); + + /** + * Sets a dynamic connection as disconnected. Is no-op on user generated connections. + * If a dynamic connection is disconnected, it is transitioned to a disconnected state while it + * is in use by some client service, and is eventually removed from the system once it is + * no longer in use. + * @param connection IConnection2 + * @since 3.0 + */ + void disconnect(IConnection2 connection); + + /** + * Attempts to set a disconnected dynamic connection back to its in-use state. + * If the connection has not been removed from the system, and is still in-use, + * it will be restored. Returns true if successful in restoring the connection. + * @param connection IConnection2 + * @since 3.0 + */ + boolean reconnect(IConnection2 connection); } \ No newline at end of file diff -r 3f37e327885c -r d66843399035 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/internal/registry/Registry.java Mon Feb 01 12:38:42 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/registry/Registry.java Mon Feb 01 13:27:18 2010 -0600 @@ -18,26 +18,68 @@ package com.nokia.carbide.remoteconnections.internal.registry; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.OutputStream; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; +import java.util.UUID; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.IMessageProvider; +import org.eclipse.jface.dialogs.TitleAreaDialog; +import org.eclipse.jface.viewers.IFilter; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + import com.nokia.carbide.remoteconnections.Messages; import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; -import com.nokia.carbide.remoteconnections.interfaces.*; +import com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI; +import com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI2; +import com.nokia.carbide.remoteconnections.interfaces.IConnectedService; +import com.nokia.carbide.remoteconnections.interfaces.IConnectedServiceFactory; +import com.nokia.carbide.remoteconnections.interfaces.IConnection; +import com.nokia.carbide.remoteconnections.interfaces.IConnectionType; +import com.nokia.carbide.remoteconnections.interfaces.IConnectionTypeProvider; +import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager; +import com.nokia.carbide.remoteconnections.interfaces.IExtensionFilter; +import com.nokia.carbide.remoteconnections.interfaces.IService; +import com.nokia.carbide.remoteconnections.interfaces.AbstractConnection.ConnectionStatus; +import com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI2.IListener; +import com.nokia.carbide.remoteconnections.internal.api.IConnection2; +import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus; +import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatusChangedListener; +import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus.EConnectionStatus; +import com.nokia.carbide.remoteconnections.internal.ui.ClientServiceSiteUI2; +import com.nokia.carbide.remoteconnections.internal.ui.ConnectionUIUtils; import com.nokia.carbide.remoteconnections.ui.ClientServiceSiteUI; import com.nokia.cpp.internal.api.utils.core.Check; import com.nokia.cpp.internal.api.utils.core.ListenerList; import com.nokia.cpp.internal.api.utils.core.Logging; - -import org.eclipse.core.runtime.*; -import org.eclipse.jface.viewers.IFilter; - -import java.io.*; -import java.text.MessageFormat; -import java.util.*; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils; /** * A registry of connection type and service extensions */ +@SuppressWarnings("deprecation") public class Registry implements IConnectionTypeProvider, IConnectionsManager { private static final String FILTER_EXTENSION = RemoteConnectionsActivator.PLUGIN_ID + ".extensionFilter"; //$NON-NLS-1$ @@ -47,7 +89,11 @@ private static final String CONNECTION_DATA_XML = "connectionData.xml"; //$NON-NLS-1$ private static final String NAME_SUFFIX_PATTERN = "(.+) \\((\\d+)\\)"; //$NON-NLS-1$ private static final String NAME_FMT = "{0} ({1})"; //$NON-NLS-1$ - private static Registry instance; + + // this is exposed to other clients inside this plugin but it is not public knowledge + public static final String CURRENT_CONNECTION_ID = RemoteConnectionsActivator.PLUGIN_ID + ".currentConnection"; //$NON-NLS-1$ + + private static Registry instance = new Registry(); private List extensionFilters; private Map connectionTypeIdMap; @@ -56,18 +102,18 @@ private Map> connectionToConnectedServices; private ListenerList listeners; private List connectedServiceFactories; + private ListenerList connectionListeners; + private IConnection currentConnection; + private Map connectionListenerMap; public static Registry instance() { - if (instance == null) { - instance = new Registry(); - } - return instance; } private Registry() { // private because is singleton connectionToConnectedServices = new HashMap>(); + connectionListenerMap = new HashMap(); } public void loadExtensions() { @@ -81,19 +127,21 @@ private void loadConnectedServiceFactoryExtensions() { connectedServiceFactories = new ArrayList(); String loadError = Messages.getString("Registry.ConnectedServiceFactoryExtensionLoadError"); //$NON-NLS-1$ - loadExtensions(CONNECTED_SERVICE_FACTORY_EXTENSION, loadError, connectedServiceFactories, null); + RemoteConnectionsActivator.loadExtensions(CONNECTED_SERVICE_FACTORY_EXTENSION, loadError, + connectedServiceFactories, null); } private void loadExtensionFilters() { extensionFilters = new ArrayList(); String loadError = Messages.getString("Registry.FilterExtensionLoadError"); //$NON-NLS-1$ - loadExtensions(FILTER_EXTENSION, loadError, extensionFilters, null); + RemoteConnectionsActivator.loadExtensions(FILTER_EXTENSION, loadError, extensionFilters, null); } private void loadConnectionTypeExtensions() { List connectionTypeExtensions = new ArrayList(); String loadError = Messages.getString("Registry.ConnectionTypeExtensionLoadError"); //$NON-NLS-1$ - loadExtensions(CONNECTION_TYPE_EXTENSION, loadError, connectionTypeExtensions, new IFilter() { + RemoteConnectionsActivator.loadExtensions(CONNECTION_TYPE_EXTENSION, loadError, + connectionTypeExtensions, new IFilter() { public boolean select(Object toTest) { return acceptConnectionType(((IConnectionType) toTest).getIdentifier()); } @@ -116,7 +164,7 @@ private void loadServiceExtensions() { services = new ArrayList(); String loadError = Messages.getString("Registry.ServiceExtensionLoadError"); //$NON-NLS-1$ - loadExtensions(SERVICE_EXTENSION, loadError, services, new IFilter() { + RemoteConnectionsActivator.loadExtensions(SERVICE_EXTENSION, loadError, services, new IFilter() { public boolean select(Object toTest) { return acceptService(((IService) toTest).getIdentifier()); } @@ -131,28 +179,6 @@ return true; } - private void loadExtensions(String extensionId, String loadError, Collection extensionObjects, IFilter filter) { - IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry(); - IExtensionPoint extensionPoint = extensionRegistry.getExtensionPoint(extensionId); - IExtension[] extensions = extensionPoint.getExtensions(); - - for (int i = 0; i < extensions.length; i++) { - IExtension extension = extensions[i]; - IConfigurationElement[] elements = extension.getConfigurationElements(); - Check.checkContract(elements.length == 1); - IConfigurationElement element = elements[0]; - try { - T extObject = (T) element.createExecutableExtension("class"); //$NON-NLS-1$ - if (filter == null || filter.select(extObject)) - extensionObjects.add(extObject); - } - catch (CoreException e) { - if (loadError != null) - log(loadError, e); - } - } - } - private void mapConnectionTypeToServices() { connectionTypeToServices = new HashMap>(); Set connectionTypeIds = connectionTypeIdMap.keySet(); @@ -198,17 +224,6 @@ return accept; } - private void log(String errorStr, Throwable t) { - RemoteConnectionsActivator p = RemoteConnectionsActivator.getDefault(); - String error = errorStr; - if (t != null) { - error += " : " + t.getLocalizedMessage(); //$NON-NLS-1$ - } - Logging.log(p, Logging.newStatus(p, IStatus.ERROR, error)); - if (t instanceof CoreException) - Logging.log(p, ((CoreException) t).getStatus()); - } - /* (non-Javadoc) * @see com.nokia.carbide.remoteconnections.registry.IConnectionStore#loadConnections() */ @@ -226,7 +241,7 @@ fireConnectionStoreChanged(); } catch (Exception e) { - log(Messages.getString("Registry.ConnectionLoadError"), e); //$NON-NLS-1$ + RemoteConnectionsActivator.log(Messages.getString("Registry.ConnectionLoadError"), e); //$NON-NLS-1$ } } @@ -235,7 +250,8 @@ List connectedServices = new ArrayList(); for (IService service : getCompatibleServices(connection.getConnectionType())) { IConnectedService connectedService = createConnectedService(service, connection); - connectedServices.add(connectedService); + if (connectedService != null) + connectedServices.add(connectedService); } return connectedServices; } @@ -247,28 +263,32 @@ if (connectedService != null) return connectedService; } - log(MessageFormat.format( + RemoteConnectionsActivator.log(MessageFormat.format( Messages.getString("Registry.ConnectedServiceFactoryError"), //$NON-NLS-1$ service.getDisplayName(), connection.getConnectionType().getDisplayName()), null); return null; } - /* (non-Javadoc) - * @see com.nokia.carbide.remoteconnections.registry.IConnectionStore#storeConnections() - */ public void storeConnections() { try { OutputStream os = new FileOutputStream(getConnectionStorageFile()); - Writer.writeToXML(os, connectionToConnectedServices.keySet()); + Writer.writeToXML(os, getNonDynamicConnections()); } catch (Exception e) { - log(Messages.getString("Registry.ConnectionStoreError"), e); //$NON-NLS-1$ + RemoteConnectionsActivator.log(Messages.getString("Registry.ConnectionStoreError"), e); //$NON-NLS-1$ } } - /* (non-Javadoc) - * @see com.nokia.carbide.remoteconnections.registry.IConnectionStore#addConnectionStoreChangedListener(com.nokia.carbide.remoteconnections.registry.Registry.IConnectionStoreChangedListener) - */ + private Collection getNonDynamicConnections() { + List nonDynamicConnections = new ArrayList(); + for (IConnection connection : connectionToConnectedServices.keySet()) { + if (!(connection instanceof IConnection2) || + !((IConnection2) connection).isDynamic()) + nonDynamicConnections.add(connection); + } + return nonDynamicConnections; + } + public void addConnectionStoreChangedListener(IConnectionsManagerListener listener) { if (listeners == null) listeners = new ListenerList(); @@ -287,10 +307,7 @@ listener.connectionStoreChanged(); } } - - /* (non-Javadoc) - * @see com.nokia.carbide.remoteconnections.registry.IConnectionTypeProvider#getConnectionType(java.lang.String) - */ + public IConnectionType getConnectionType(String identifier) { Check.checkContract(connectionTypeIdMap != null); return connectionTypeIdMap.get(identifier); @@ -305,7 +322,7 @@ Collection services = connectionTypeToServices.get(connectionType); if (services != null) return new ArrayList(services); - return Collections.EMPTY_LIST; + return Collections.emptyList(); } /* (non-Javadoc) @@ -317,11 +334,12 @@ List connectedServices = createConnectedServicesForConnection(connection); connectionToConnectedServices.put(connection, connectedServices); fireConnectionStoreChanged(); + fireConnectionAdded(connection); } private void ensureUniqueId(IConnection connection) { String id = connection.getIdentifier(); - if (id == null || id.length() == 0 || connectionIdInUse(id)) + if (id == null || id.length() == 0 || findConnection(id) != null) connection.setIdentifier(getUniqueConnectionId()); } @@ -329,15 +347,16 @@ return UUID.randomUUID().toString(); } - private boolean connectionIdInUse(String id) { - boolean used = false; - for (IConnection c : connectionToConnectedServices.keySet()) { - if (c.getIdentifier().equals(id)) { - used = true; - break; + public IConnection findConnection(String connectionId) { + if (CURRENT_CONNECTION_ID.equals(connectionId)) + return getCurrentConnection(); + + for (IConnection connection : connectionToConnectedServices.keySet()) { + if (connection.getIdentifier().equals(connectionId)) { + return connection; } } - return used; + return null; } private void ensureUniqueName(IConnection connection) { @@ -382,19 +401,22 @@ return used; } - /* (non-Javadoc) - * @see com.nokia.carbide.remoteconnections.registry.IConnectionStore#removeConnection(com.nokia.carbide.remoteconnections.extensions.IConnection) - */ public void removeConnection(IConnection connection) { disposeConnection(connection); connectionToConnectedServices.remove(connection); + if (connection == currentConnection) { + currentConnection = null; + } fireConnectionStoreChanged(); + fireConnectionRemoved(connection); } private void disposeConnection(IConnection connection) { List connectedServices = connectionToConnectedServices.get(connection); - for (IConnectedService connectedService : connectedServices) { - connectedService.dispose(); + if (connectedServices != null) { + for (IConnectedService connectedService : connectedServices) { + connectedService.dispose(); + } } connection.dispose(); } @@ -442,6 +464,10 @@ return new ClientServiceSiteUI(service); } + public IClientServiceSiteUI2 getClientSiteUI2(IService service) { + return new ClientServiceSiteUI2(service); + } + public Collection getServices() { return new ArrayList(services); } @@ -453,4 +479,202 @@ } return null; } + + public void addConnectionListener(IConnectionListener listener) { + if (connectionListeners == null) + connectionListeners = new ListenerList(); + connectionListeners.add(listener); + } + + public void removeConnectionListener(IConnectionListener listener) { + if (connectionListeners != null) + connectionListeners.remove(listener); + } + + private void fireConnectionAdded(IConnection connection) { + if (connectionListeners == null) + return; + for (IConnectionListener listener : connectionListeners) { + listener.connectionAdded(connection); + } + } + + private void fireConnectionRemoved(IConnection connection) { + if (connectionListeners == null) + return; + for (IConnectionListener listener : connectionListeners) { + listener.connectionRemoved(connection); + } + } + + private void fireCurrentConnectionSet(IConnection connection) { + if (connectionListeners == null) + return; + for (IConnectionListener listener : connectionListeners) { + listener.currentConnectionSet(connection); + } + } + + public IConnection ensureConnection(String id, IService service) throws CoreException { + Check.checkArg(service); + IConnection connection = findConnection(id); + if (!isCompatibleConnection(connection, service)) { + connection = getCompatibleConnectionFromUser(service); + if (connection == null) { + throw new CoreException( + Logging.newStatus(RemoteConnectionsActivator.getDefault(), IStatus.ERROR, + Messages.getString("Registry.NoCompatibleConnectionMsg"))); //$NON-NLS-1$ + } + } + return connection; + } + + private IConnection getCompatibleConnectionFromUser(final IService service) { + final IConnection[] connectionHolder = { null }; + if (!WorkbenchUtils.isJUnitRunning()) { + Display.getDefault().syncExec(new Runnable() { + public void run() { + final IClientServiceSiteUI2 ui = getClientSiteUI2(service); + final TitleAreaDialog dialog = new TitleAreaDialog(WorkbenchUtils.getSafeShell()) { + @Override + protected Control createDialogArea(Composite parent) { + final Composite c = (Composite) super.createDialogArea(parent); + ui.createComposite(c); + ui.addListener(new IListener() { + public void connectionSelected() { + updateStatus(ui.getSelectionStatus()); + } + + }); + + return c; + } + + private void updateStatus(IStatus selectionStatus) { + setTitle(Messages.getString("Registry.EnsureConnection.TitleLabel")); //$NON-NLS-1$ + setMessage(Messages.getString("Registry.EnsureConnection.Description")); //$NON-NLS-1$ + switch (selectionStatus.getSeverity()) { + case IStatus.ERROR: + setMessage(selectionStatus.getMessage(), IMessageProvider.ERROR); + getButton(IDialogConstants.OK_ID).setEnabled(false); + break; + case IStatus.WARNING: + setMessage(selectionStatus.getMessage(), IMessageProvider.WARNING); + getButton(IDialogConstants.OK_ID).setEnabled(true); + break; + case IStatus.INFO: + setMessage(selectionStatus.getMessage(), IMessageProvider.INFORMATION); + getButton(IDialogConstants.OK_ID).setEnabled(true); + break; + default: + getButton(IDialogConstants.OK_ID).setEnabled(true); + } + } + + @Override + public void create() { + super.create(); + updateStatus(ui.getSelectionStatus()); + } + + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText(Messages.getString("Registry.EnsureConnection.DialogTitle")); //$NON-NLS-1$ + } + + @Override + protected boolean isResizable() { + return true; + } + }; + dialog.setBlockOnOpen(true); + if (dialog.open() == Dialog.OK) + connectionHolder[0] = findConnection(ui.getSelectedConnection()); + } + }); + } + return connectionHolder[0]; + } + + private boolean isCompatibleConnection(IConnection connection, IService service) { + if (connection == null) + return false; + return getCompatibleServices(connection.getConnectionType()).contains(service); + } + + public void setCurrentConnection(IConnection connection) { + if (connection == null) { + currentConnection = null; // special case + fireCurrentConnectionSet(null); + } + else if (connectionToConnectedServices.keySet().contains(connection)) { + currentConnection = connection; + fireCurrentConnectionSet(connection); + } + } + + public IConnection getCurrentConnection() { + return currentConnection; + } + + public void disconnect(final IConnection2 connection) { + if (!connection.isDynamic()) + return; + + // transition to disconnected state and wait: + // when not in-use, remove and stop waiting + if (connection.getStatus().getEConnectionStatus().equals(EConnectionStatus.IN_USE)) { + IConnectionStatus status = new ConnectionStatus(EConnectionStatus.IN_USE_DISCONNECTED, + Messages.getString("ConnectionsView.DisconnectedLabel"), //$NON-NLS-1$ + Messages.getString("ConnectionsView.DisconnectedDesc")); //$NON-NLS-1$ + connection.setStatus(status); + IConnectionStatusChangedListener listener = new IConnectionStatusChangedListener() { + public void statusChanged(IConnectionStatus status) { + if (notInUse(status)) { + IConnectionStatusChangedListener listener = + connectionListenerMap.remove(connection); + connection.removeStatusChangedListener(listener); + removeConnection(connection); + } + } + + private boolean notInUse(IConnectionStatus status) { + EConnectionStatus eStatus = status.getEConnectionStatus(); + return !eStatus.equals(EConnectionStatus.IN_USE) && + !eStatus.equals(EConnectionStatus.IN_USE_DISCONNECTED); + } + }; + connectionListenerMap.put(connection, listener); + connection.addStatusChangedListener(listener); + } + else { + removeConnection(connection); + } + } + + public boolean reconnect(IConnection2 connection) { + if (!connection.isDynamic()) + return false; + + // if not removed, transition out of disconnected state + // return not removed + IConnectionStatusChangedListener listener = connectionListenerMap.remove(connection); + if (listener != null) + connection.removeStatusChangedListener(listener); + if (connectionToConnectedServices.containsKey(connection)) { + IConnectionStatus status; + if (ConnectionUIUtils.isSomeServiceInUse(connection)) { + status = new ConnectionStatus(EConnectionStatus.IN_USE, + Messages.getString("ConnectionsView.InUseLabel"), //$NON-NLS-1$ + Messages.getString("ConnectionsView.InUseDesc")); //$NON-NLS-1$ + } + else { + status = new ConnectionStatus(EConnectionStatus.NOT_READY, "", ""); //$NON-NLS-1$ //$NON-NLS-2$ + } + connection.setStatus(status); + return true; + } + return false; + } } \ No newline at end of file diff -r 3f37e327885c -r d66843399035 connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/messages.properties --- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/messages.properties Mon Feb 01 12:38:42 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/messages.properties Mon Feb 01 13:27:18 2010 -0600 @@ -7,8 +7,21 @@ ClientServiceSiteUI.EditButtonLabel=Edit... ClientServiceSiteUI.NewButtonLabel=New... ClientServiceSiteUI.UseConnectionGroupLabel=Use connection +ClientServiceSiteUI2.CurrentConnection_NoneDetected=none detected or defined +ClientServiceSiteUI2.CurrentConnectionFormat=Current connection ({0}) +ClientServiceSiteUI2.DeletedConnectionDisplayName=<> +ClientServiceSiteUI2.EditButtonLabel=Edit... +ClientServiceSiteUI2.NewButtonLabel=New... +ClientServiceSiteUI2.UseConnectionGroupLabel=Use connection +ClientServiceSiteUI2.NoConnectionError=A valid remote connection must be selected. If none exist, connect a device or create a connection one supporting {0} via {1}. +ClientServiceSiteUI2.NoCurrentConnection=No current connection is available. Connect a device or create a connection supporting {0} via {1}. +ClientServiceSiteUI2.IncompatibleCurrentConnectionType=The current connection ''{0}'' does not support connection type: ''{1}''. +ClientServiceSiteUI2.IncompatibleCurrentConnectionService=The current connection ''{0}'' does not support the service: ''{1}''. +ClientServiceSiteUI2.IncompatibleCurrentConnectionFixupAdvice=Either connect an appropriate device or select a compatible connection. +ClientServiceSiteUI2.Or=or ConnectionSettingsPage.AgentTestTabLabel=Set Connection Settings ConnectionSettingsPage.ConnectionSettingsGroupLabel=Connection Settings +ConnectionSettingsPage.ConnectionTestingLabel=Connection Testing ConnectionSettingsPage.DeviceOSComboToolTip=Used to determine which installer version to compare against the version reported by the remote agent ConnectionSettingsPage.DeviceOSLabel=Device OS (used for service test results): ConnectionSettingsPage.GettingDataMessage=Getting data from server... @@ -17,6 +30,7 @@ ConnectionSettingsPage.InstallTabLabel=Install remote agents ConnectionSettingsPage.NoInstallerDataInfoString=No installer data available. ConnectionSettingsPage.NoInstallerDataInfoString2=Server may be down. +ConnectionSettingsPage.NoInstallerSupport=Installers are currently not supported on this operating system. ConnectionSettingsPage.NoSettingsString={0} has no connection settings ConnectionSettingsPage.NotTestedStatusString=Status not tested ConnectionSettingsPage.PageTitleFmt={0} Settings @@ -30,19 +44,27 @@ ConnectionSettingsPage.ServiceTestButtonToolTip=Test the remote agent's status and check its version against the most current installer ConnectionSettingsPage.StatusLabel=Status ConnectionSettingsPage.UnlabeledPackageLabel=Unlabeled package -ConnectionsView.DeleteActionLabel=Delete Connection +ConnectionStatusSelectorContribution.AddedConnectionFormat=Added new connection {0} +ConnectionStatusSelectorContribution.OpenRemoteConnectionsView=&Open Remote Connections view +ConnectionStatusSelectorContribution.RemovedConnectionFormat=Removed connection {0} +ConnectionsView.DeleteActionLabel=Delete ConnectionsView.DescriptionColumnHeader=Description -ConnectionsView.EditActionLabel=Edit Connection Settings -ConnectionsView.HelpActionLabel=Connection Documentation +ConnectionsView.EditActionLabel=Edit Settings... +ConnectionsView.NoHelpActionLabel=Help Unavailable... +ConnectionsView.HelpActionLabel=Help for {0} Connection... +ConnectionsView.SetCurrentActionLabel=Make Current ConnectionsView.NameColumnHeader=Connection/Services -ConnectionsView.NewActionLabel=New Connection +ConnectionsView.NewActionLabel=New Connection... ConnectionsView.RefreshActionLabel=Refresh Status -ConnectionsView.RenameMenuLabel=Rename connection +ConnectionsView.RenameMenuLabel=Rename ConnectionsView.StatusColumnHeader=Status ConnectionsView.EnableTestActionLabel=Enable Service Testing ConnectionsView.DisableTestActionLabel=Disable Service Testing ConnectionsView.TypeColumnHeader=Type +ConnectionsView.InUseLabel=In use ConnectionsView.InUseDesc=At least one service is using this connection +ConnectionsView.DisconnectedLabel=Disconnected +ConnectionsView.DisconnectedDesc=Connection has been disconnected while in use, please reconnect ConnectionTypePage.ConnectionNameInUseError=The connection name ''{0}'' is in use ConnectionTypePage.Description=Select a name and the connection type for the connection ConnectionTypePage.NameLabel=Connection name: @@ -50,6 +72,22 @@ ConnectionTypePage.SupportedServicesLabel=Supported Services: {0} ConnectionTypePage.Title=Edit connection name and type ConnectionTypePage.ViewerLabel=Connection Type: +ConnectionStatusSelectorContribution_NoCurrentConnectionMessage=No current connection +ConnectionStatusSelectorContribution_SelectTheCurrentConnectionMessage=Switch the current 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 current connection selected. +ConnectionStatusSelectorContribution.NotInUse=Not in use +ConnectionStatusSelectorContribution.StatusFormat=Connection is {0}: {1} +DeviceDiscoveryPrequisiteErrorDialog_Description=At least one device discovery agent had load errors that prevent it from discovering connections to devices. Select one to get more information about its error. +DeviceDiscoveryPrequisiteErrorDialog_DontAskAgainLabel=Don't ask again +DeviceDiscoveryPrequisiteErrorDialog_DontAskAgainToolTipText=Check this to ignore further discovery agent load errors +DeviceDiscoveryPrequisiteErrorDialog_ErrorFormatWithURL={0} - For more information go to: {2} +DeviceDiscoveryPrequisiteErrorDialog_ErrorTextToolTipText=Error message for the selected agent above +DeviceDiscoveryPrequisiteErrorDialog_Title=Device Discovery Load Errors +DeviceDiscoveryPrequisiteErrorDialog_ToolTipText=Select an agent for more information about load errors. ExportPage.BrowseGroupLabel=Connections file: ExportPage.Description=Select connections to export ExportPage.FileDialogTitle=Save As @@ -72,6 +110,7 @@ ImportWizard.Title=Import InstallPackages.GettingPackagesJobLabel=Getting available packages from server InstallPackages.TimeoutMissingProxyMessage=Attempted connection to server will timeout when correct proxy server information is not set in the preferences +OpenConnectionViewCommandHandler_FailedToOpenMsg=Failed to open view Reader.MissingConnectionTypeError=Could not load connection ''{0}'' because no connection type ''{1}'' exists. Reader.UnknownVersionError=Could not read version {0} of element Registry.ConnectedServiceFactoryError=No factory found for service {0} and connection type {1} @@ -80,7 +119,12 @@ Registry.ConnectionStoreError=Could not store connections Registry.FilterExtensionLoadError=Could not load filter extensions Registry.ConnectionTypeExtensionLoadError=Could not load connection type extensions +Registry.EnsureConnection.DialogTitle=Invalid Connection Stored +Registry.EnsureConnection.TitleLabel=Select a connection to use +Registry.EnsureConnection.Description=Select a connection, create a new one or attach a device +Registry.NoCompatibleConnectionMsg=No compatible connection found for this id Registry.ServiceExtensionLoadError=Could not load service extensions Registry.ServiceListUnknownConnectionTypeError=Service ''{0}'' lists unknown connection type ''{1}'' as compatible SettingsWizard.WindowTitle.Edit=Edit {0} Settings -SettingsWizard.WindowTitle.New=New Connection \ No newline at end of file +SettingsWizard.WindowTitle.New=New Connection +RemoteConnectionsActivator.DiscoveryAgentLoadError=Could not load device discovery agent diff -r 3f37e327885c -r d66843399035 connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/settings/ui/ConnectionSettingsPage.java --- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/settings/ui/ConnectionSettingsPage.java Mon Feb 01 12:38:42 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/settings/ui/ConnectionSettingsPage.java Mon Feb 01 13:27:18 2010 -0600 @@ -18,42 +18,87 @@ package com.nokia.carbide.remoteconnections.settings.ui; +import java.io.File; +import java.io.InputStream; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.ComboViewer; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.ListViewer; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TreeNode; +import org.eclipse.jface.viewers.TreeNodeContentProvider; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.wizard.IWizardContainer2; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.custom.SashForm; +import org.eclipse.swt.events.FocusAdapter; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.program.Program; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.TabFolder; +import org.eclipse.swt.widgets.TabItem; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.PlatformUI; +import org.osgi.framework.Version; + import com.nokia.carbide.remoteconnections.Messages; import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; -import com.nokia.carbide.remoteconnections.interfaces.*; +import com.nokia.carbide.remoteconnections.interfaces.AbstractConnectedService; +import com.nokia.carbide.remoteconnections.interfaces.IConnectedService; +import com.nokia.carbide.remoteconnections.interfaces.IConnection; +import com.nokia.carbide.remoteconnections.interfaces.IConnectionFactory; +import com.nokia.carbide.remoteconnections.interfaces.IConnectionType; +import com.nokia.carbide.remoteconnections.interfaces.IConnectionTypeProvider; +import com.nokia.carbide.remoteconnections.interfaces.IRemoteAgentInstallerProvider; +import com.nokia.carbide.remoteconnections.interfaces.IService; +import com.nokia.carbide.remoteconnections.interfaces.IService2; import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus; import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatusChangedListener; import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus.EStatus; import com.nokia.carbide.remoteconnections.interfaces.IConnectionFactory.IValidationErrorReporter; import com.nokia.carbide.remoteconnections.interfaces.IRemoteAgentInstallerProvider.IRemoteAgentInstaller; import com.nokia.carbide.remoteconnections.interfaces.IRemoteAgentInstallerProvider.IRemoteAgentInstaller.IPackageContents; -import com.nokia.cpp.internal.api.utils.core.*; - -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.viewers.*; -import org.eclipse.jface.wizard.IWizardContainer2; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CLabel; -import org.eclipse.swt.custom.SashForm; -import org.eclipse.swt.events.*; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.program.Program; -import org.eclipse.swt.widgets.*; -import org.eclipse.ui.ISharedImages; -import org.eclipse.ui.PlatformUI; -import org.osgi.framework.Version; - -import java.io.File; -import java.io.InputStream; -import java.text.MessageFormat; -import java.util.*; -import java.util.List; +import com.nokia.carbide.remoteconnections.internal.registry.Registry; +import com.nokia.cpp.internal.api.utils.core.Check; +import com.nokia.cpp.internal.api.utils.core.FileUtils; +import com.nokia.cpp.internal.api.utils.core.HostOS; +import com.nokia.cpp.internal.api.utils.core.Pair; +import com.nokia.cpp.internal.api.utils.ui.BrowseDialogUtils; public class ConnectionSettingsPage extends WizardPage { @@ -141,9 +186,14 @@ createSettingsGroup(agentTestTabComposite); - createDeviceOSCombo(agentTestTabComposite); + Group group = new Group(agentTestTabComposite, SWT.NONE); + group.setText(Messages.getString("ConnectionSettingsPage.ConnectionTestingLabel")); //$NON-NLS-1$ + GridLayoutFactory.fillDefaults().numColumns(2).applyTo(group); + GridDataFactory.fillDefaults().span(2, 1).grab(true, true).applyTo(group); + + createDeviceOSCombo(group); - createServiceTestComposite(agentTestTabComposite); + createServiceTestComposite(group); } private void createDeviceOSCombo(Composite parent) { @@ -165,6 +215,7 @@ gd_sdkcombo.widthHint = 150; deviceOSComboViewer.getCombo().setLayoutData(gd_sdkcombo); deviceOSComboViewer.addSelectionChangedListener(new ISelectionChangedListener() { + @SuppressWarnings("unchecked") public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) deviceOSComboViewer.getSelection(); Pair pair = (Pair) selection.getFirstElement(); @@ -175,10 +226,11 @@ }); deviceOSComboViewer.setContentProvider(new ArrayContentProvider()); deviceOSComboViewer.setLabelProvider(new LabelProvider() { + @SuppressWarnings("unchecked") @Override public String getText(Object element) { Check.checkState(element instanceof Pair); - Pair pair = (Pair) element; + Pair pair = (Pair) element; return MessageFormat.format("{0} {1}", pair.first, pair.second); //$NON-NLS-1$ } }); @@ -453,10 +505,13 @@ GridData gd = new GridData(SWT.LEFT, SWT.TOP, true, true); label.setLayoutData(gd); } + else if (settingsWizard.isConnectionToEditDynamic()) { + disableControls(settingsUI); + } // update services list Collection compatibleServices = - RemoteConnectionsActivator.getConnectionTypeProvider().getCompatibleServices(connectionType); + Registry.instance().getCompatibleServices(connectionType); servicesListViewer.setInput(compatibleServices); if (!compatibleServices.isEmpty()) { servicesListViewer.getList().select(0); @@ -484,6 +539,14 @@ ((IWizardContainer2) getWizard().getContainer()).updateSize(); } + private void disableControls(Control[] controls) { + for (Control control : controls) { + if (control instanceof Composite) + disableControls(((Composite) control).getChildren()); + control.setEnabled(false); + } + } + private synchronized void initializeInstallerData() { Display.getDefault().asyncExec(new Runnable() { public void run() { @@ -518,8 +581,14 @@ installerTreeViewer.expandAll(); if (treeNodes.length == 0) { - String errorText = Messages.getString("ConnectionSettingsPage.NoInstallerDataInfoString"); //$NON-NLS-1$ - errorText += "\n" + Messages.getString("ConnectionSettingsPage.NoInstallerDataInfoString2"); //$NON-NLS-1$ //$NON-NLS-2$ + String errorText; + // TODO: the actual error condition needs to be recorded... + if (HostOS.IS_UNIX) { + errorText = Messages.getString("ConnectionSettingsPage.NoInstallerSupport"); //$NON-NLS-1$ + } else { + errorText = Messages.getString("ConnectionSettingsPage.NoInstallerDataInfoString"); //$NON-NLS-1$ + errorText += "\n" + Messages.getString("ConnectionSettingsPage.NoInstallerDataInfoString2"); //$NON-NLS-1$ //$NON-NLS-2$ + } installerInfoText.setText(errorText); } @@ -556,6 +625,7 @@ } } + @SuppressWarnings("unchecked") private TreeNode findTreeNodeForPair(TreeNode[] treeNodes, Pair pair) { for (TreeNode treeNode : treeNodes) { Object value = treeNode.getValue(); @@ -575,6 +645,7 @@ return null; } + @SuppressWarnings("unchecked") protected void testService() { Map settings = connectionFactory.getSettingsFromUI(); boolean newConnection = connection == null || !connectionType.equals(connection.getConnectionType()); @@ -590,7 +661,7 @@ if (newConnection || connectedService == null || !connectedService.getService().equals(service)) { disposeConnectedService(); connectedService = - RemoteConnectionsActivator.getConnectionsManager().createConnectedService(service, connection); + Registry.instance().createConnectedService(service, connection); IStructuredSelection selection = (IStructuredSelection) deviceOSComboViewer.getSelection(); Pair pair = (Pair) selection.getFirstElement(); if (pair != null) @@ -652,8 +723,7 @@ dialog.setText(Messages.getString("ConnectionSettingsPage.SaveAsDialogTitle")); //$NON-NLS-1$ if (saveAsParent == null) saveAsParent = System.getProperty("user.home"); //$NON-NLS-1$ - dialog.setFilterPath(saveAsParent); - dialog.setFileName(packageContents.getDefaultNameFileName()); + BrowseDialogUtils.initializeFrom(dialog, new Path(saveAsParent).append(packageContents.getDefaultNameFileName())); dialog.setOverwrite(true); // prompt for overwrite String path = dialog.open(); if (path != null) { @@ -758,7 +828,7 @@ for (String familyName : familyNames) { List versions = installerProvider.getVersions(familyName); for (Version version : versions) { - Pair pair = new Pair(familyName, version); + Pair pair = new Pair(familyName, version); if (!deviceOSPairs.contains(pair)) deviceOSPairs.add(pair); } diff -r 3f37e327885c -r d66843399035 connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/settings/ui/ConnectionTypePage.java --- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/settings/ui/ConnectionTypePage.java Mon Feb 01 12:38:42 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/settings/ui/ConnectionTypePage.java Mon Feb 01 13:27:18 2010 -0600 @@ -21,6 +21,7 @@ import com.nokia.carbide.remoteconnections.Messages; import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; import com.nokia.carbide.remoteconnections.interfaces.*; +import com.nokia.carbide.remoteconnections.internal.registry.Registry; import com.nokia.cpp.internal.api.utils.core.Check; import org.eclipse.jface.viewers.*; @@ -74,6 +75,8 @@ setPageComplete(validatePage()); } }); + boolean canEditConnection = !settingsWizard.isConnectionToEditDynamic(); + nameText.setEnabled(canEditConnection); Label label = new Label(container, SWT.NONE); label.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false)); @@ -119,6 +122,7 @@ } }); viewer.getList().select(getCurrentTypeIndex()); + viewer.getList().setEnabled(canEditConnection); connectionTypeDescLabel = new Label(container, SWT.WRAP); connectionTypeDescLabel.setText(getConnectionTypeDescription()); @@ -141,7 +145,7 @@ private String getServicesString() { StringBuilder servicesString = new StringBuilder(); Collection services = - RemoteConnectionsActivator.getConnectionTypeProvider().getCompatibleServices(getConnectionType()); + Registry.instance().getCompatibleServices(getConnectionType()); if (services == null || services.isEmpty()) return ""; //$NON-NLS-1$ for (Iterator iterator = services.iterator(); iterator.hasNext();) { @@ -157,12 +161,13 @@ return getConnectionType().getDescription(); } + @SuppressWarnings("unchecked") private int getCurrentTypeIndex() { IConnection connectionToEdit = settingsWizard.getConnectionToEdit(); if (connectionToEdit != null) { Object input = viewer.getInput(); if (input != null) { - Collection connectionTypes = (Collection) input; + Collection connectionTypes = (Collection) input; for (int i = 0; i < connectionTypes.size(); i++) { IConnectionType connectionType = (IConnectionType) viewer.getElementAt(i); if (connectionToEdit.getConnectionType().equals(connectionType)) @@ -179,10 +184,10 @@ if (serviceToRestrict != null) { List restrictedConnectionTypes = new ArrayList(); Collection compatibleConnectionTypeIds = - RemoteConnectionsActivator.getConnectionTypeProvider().getCompatibleConnectionTypeIds(serviceToRestrict); + Registry.instance().getCompatibleConnectionTypeIds(serviceToRestrict); for (String connectionTypeId : compatibleConnectionTypeIds) { IConnectionType connectionType = - RemoteConnectionsActivator.getConnectionTypeProvider().getConnectionType(connectionTypeId); + Registry.instance().getConnectionType(connectionTypeId); if (connectionTypes.contains(connectionType)) restrictedConnectionTypes.add(connectionType); } @@ -197,10 +202,10 @@ IConnection connectionToEdit = settingsWizard.getConnectionToEdit(); IConnectionType connectionTypeToEdit = connectionToEdit != null ? connectionToEdit.getConnectionType() : null; Collection allConnectionTypes = - RemoteConnectionsActivator.getConnectionTypeProvider().getConnectionTypes(); + Registry.instance().getConnectionTypes(); Collection connectionTypes = new ArrayList(); for (IConnectionType connectionType : allConnectionTypes) { - if (!RemoteConnectionsActivator.getConnectionTypeProvider().getCompatibleServices(connectionType).isEmpty() || + if (!Registry.instance().getCompatibleServices(connectionType).isEmpty() || connectionType.equals(connectionTypeToEdit)) connectionTypes.add(connectionType); } @@ -219,7 +224,7 @@ } private boolean isNameUnique(String name) { - boolean inUse = RemoteConnectionsActivator.getConnectionsManager().connectionNameInUse(name); + boolean inUse = Registry.instance().connectionNameInUse(name); IConnection connectionToEdit = settingsWizard.getConnectionToEdit(); if (connectionToEdit != null && inUse) inUse = !name.equals(connectionToEdit.getDisplayName()); diff -r 3f37e327885c -r d66843399035 connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/settings/ui/OnDeviceConnectionAction.java --- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/settings/ui/OnDeviceConnectionAction.java Mon Feb 01 12:38:42 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/settings/ui/OnDeviceConnectionAction.java Mon Feb 01 13:27:18 2010 -0600 @@ -19,6 +19,8 @@ package com.nokia.carbide.remoteconnections.settings.ui; import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; +import com.nokia.carbide.remoteconnections.view.ConnectionsView; +import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; @@ -37,14 +39,11 @@ public void run(IAction action) { // Ensure the remote connections view is visible - IWorkbenchPage page = window.getActivePage(); - if (page != null) { - try { - page.showView("com.nokia.carbide.remoteconnections.view.ConnectionsView"); //$NON-NLS-1$ - } - catch (PartInitException e) { - RemoteConnectionsActivator.logError(e); - } + try { + WorkbenchUtils.getView(ConnectionsView.VIEW_ID); + } + catch (PartInitException e) { + RemoteConnectionsActivator.logError(e); } // Launch the new connection wizard diff -r 3f37e327885c -r d66843399035 connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/settings/ui/SettingsWizard.java --- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/settings/ui/SettingsWizard.java Mon Feb 01 12:38:42 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/settings/ui/SettingsWizard.java Mon Feb 01 13:27:18 2010 -0600 @@ -18,15 +18,23 @@ package com.nokia.carbide.remoteconnections.settings.ui; -import com.nokia.carbide.remoteconnections.Messages; -import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; -import com.nokia.carbide.remoteconnections.interfaces.*; +import java.text.MessageFormat; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; -import org.eclipse.jface.wizard.*; +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.swt.widgets.Shell; -import java.text.MessageFormat; -import java.util.*; +import com.nokia.carbide.remoteconnections.Messages; +import com.nokia.carbide.remoteconnections.interfaces.IConnectedService; +import com.nokia.carbide.remoteconnections.interfaces.IConnection; +import com.nokia.carbide.remoteconnections.interfaces.IConnectionType; +import com.nokia.carbide.remoteconnections.interfaces.IService; +import com.nokia.carbide.remoteconnections.internal.api.IConnection2; +import com.nokia.carbide.remoteconnections.internal.registry.Registry; /** * Main wizard class for hosting new and edit connection settings UI @@ -78,6 +86,11 @@ public IConnection getConnectionToEdit() { return connectionToEdit; } + + public boolean isConnectionToEditDynamic() { + return connectionToEdit instanceof IConnection2 && + ((IConnection2) connectionToEdit).isDynamic(); + } public IService getServiceToRestrict() { return serviceToRestrict; @@ -96,23 +109,25 @@ String id = null; if (connectionToEdit != null) { id = connectionToEdit.getIdentifier(); - RemoteConnectionsActivator.getConnectionsManager().removeConnection(connectionToEdit); + Registry.instance().removeConnection(connectionToEdit); } connectionToEdit = newConnectionType.getConnectionFactory().createConnection(newSettings); if (id != null) connectionToEdit.setIdentifier(id); - RemoteConnectionsActivator.getConnectionsManager().addConnection(connectionToEdit); + + connectionToEdit.setDisplayName(newName); + Registry.instance().addConnection(connectionToEdit); } else if (newSettings != null) { connectionToEdit.updateSettings(newSettings); } if (!newName.equals(connectionToEdit.getDisplayName())) { connectionToEdit.setDisplayName(newName); - RemoteConnectionsActivator.getConnectionsManager().updateDisplays(); + Registry.instance().updateDisplays(); } enableConnectedServices(true); - RemoteConnectionsActivator.getConnectionsManager().storeConnections(); + Registry.instance().storeConnections(); return true; } @@ -123,7 +138,7 @@ } private void saveConnectedServicesEnabledState() { - Collection connectedServices = RemoteConnectionsActivator.getConnectionsManager().getConnectedServices(connectionToEdit); + Collection connectedServices = Registry.instance().getConnectedServices(connectionToEdit); if (connectedServices == null) return; if (savedEnabledStates == null) @@ -134,7 +149,7 @@ } private void enableConnectedServices(boolean enabled) { - Collection connectedServices = RemoteConnectionsActivator.getConnectionsManager().getConnectedServices(connectionToEdit); + Collection connectedServices = Registry.instance().getConnectedServices(connectionToEdit); if (connectedServices == null || savedEnabledStates == null) return; for (IConnectedService connectedService : connectedServices) { diff -r 3f37e327885c -r d66843399035 connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/ui/ClientServiceSiteUI.java --- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/ui/ClientServiceSiteUI.java Mon Feb 01 12:38:42 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/ui/ClientServiceSiteUI.java Mon Feb 01 13:27:18 2010 -0600 @@ -19,8 +19,8 @@ package com.nokia.carbide.remoteconnections.ui; import com.nokia.carbide.remoteconnections.Messages; -import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; import com.nokia.carbide.remoteconnections.interfaces.*; +import com.nokia.carbide.remoteconnections.internal.registry.Registry; import com.nokia.carbide.remoteconnections.settings.ui.SettingsWizard; import com.nokia.cpp.internal.api.utils.core.Check; import com.nokia.cpp.internal.api.utils.core.ListenerList; @@ -42,6 +42,7 @@ /** * Implementation of IClientServiceSiteUI + * @deprecated */ public class ClientServiceSiteUI implements IClientServiceSiteUI { @@ -176,7 +177,7 @@ getCompatibleConnectionTypes(); List compatibleConnections = new ArrayList(); - for (IConnection connection : RemoteConnectionsActivator.getConnectionsManager().getConnections()) { + for (IConnection connection : Registry.instance().getConnections()) { if (isCompatibleConnection(connection)) compatibleConnections.add(connection); } @@ -190,10 +191,10 @@ private void getCompatibleConnectionTypes() { compatibleConnectionTypes = new HashSet(); Collection compatibleTypeIds = - RemoteConnectionsActivator.getConnectionTypeProvider().getCompatibleConnectionTypeIds(service); + Registry.instance().getCompatibleConnectionTypeIds(service); for (String typeId : compatibleTypeIds) { compatibleConnectionTypes.add( - RemoteConnectionsActivator.getConnectionTypeProvider().getConnectionType(typeId)); + Registry.instance().getConnectionType(typeId)); } } @@ -204,14 +205,16 @@ viewer.setSelection(new StructuredSelection(connection)); } + @SuppressWarnings("unchecked") private boolean viewerInputContainsConnection(IConnection connection) { Object input = viewer.getInput(); - if (input instanceof List) { - return ((List) input).contains(connection); + if (input instanceof Collection) { + return ((Collection) input).contains(connection); } return false; } + @SuppressWarnings("unchecked") private void addConnectionToViewerInput(IConnection connection) { Object input = viewer.getInput(); if (input instanceof Collection) { diff -r 3f37e327885c -r d66843399035 connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/view/ConnectionsView.java --- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/view/ConnectionsView.java Mon Feb 01 12:38:42 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/view/ConnectionsView.java Mon Feb 01 13:27:18 2010 -0600 @@ -18,72 +18,103 @@ package com.nokia.carbide.remoteconnections.view; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.LegacyActionTools; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.viewers.CellEditor; +import org.eclipse.jface.viewers.ColumnLabelProvider; +import org.eclipse.jface.viewers.ColumnViewer; +import org.eclipse.jface.viewers.ColumnViewerEditor; +import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent; +import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.EditingSupport; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TextCellEditor; +import org.eclipse.jface.viewers.TreeColumnViewerLabelProvider; +import org.eclipse.jface.viewers.TreeNode; +import org.eclipse.jface.viewers.TreeNodeContentProvider; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.TreeViewerColumn; +import org.eclipse.jface.viewers.TreeViewerEditor; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerSorter; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.TreeColumn; +import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.part.ViewPart; + import com.nokia.carbide.remoteconnections.Messages; import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; -import com.nokia.carbide.remoteconnections.interfaces.*; +import com.nokia.carbide.remoteconnections.interfaces.IConnectedService; +import com.nokia.carbide.remoteconnections.interfaces.IConnection; +import com.nokia.carbide.remoteconnections.interfaces.IConnectionType; +import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager; import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus; import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatusChangedListener; import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus.EStatus; +import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener; import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionsManagerListener; +import com.nokia.carbide.remoteconnections.internal.api.IConnection2; +import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus; +import com.nokia.carbide.remoteconnections.internal.registry.Registry; +import com.nokia.carbide.remoteconnections.internal.ui.ConnectionUIUtils; import com.nokia.carbide.remoteconnections.settings.ui.SettingsWizard; +import com.nokia.cpp.internal.api.utils.core.ObjectUtils; import com.nokia.cpp.internal.api.utils.core.TextUtils; -import org.eclipse.jface.action.*; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.jface.viewers.*; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.*; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.*; -import org.eclipse.ui.*; -import org.eclipse.ui.part.ViewPart; - -import java.util.*; -import java.util.List; - /** * The view part for Remote connections */ +@SuppressWarnings("deprecation") public class ConnectionsView extends ViewPart { + public static final String VIEW_ID = "com.nokia.carbide.remoteconnections.view.ConnectionsView"; //$NON-NLS-1$ private TreeViewer viewer; private IConnectionsManagerListener connectionStoreChangedListener; + private IConnectionListener connectionListener; private Map serviceToListenerMap; private List actions; private List connectionSelectedActions; private List serviceSelectedActions; private static final String UID = ".uid"; //$NON-NLS-1$ - private static final ImageDescriptor STATUS_AVAIL_IMGDESC = - RemoteConnectionsActivator.getImageDescriptor("icons/statusAvailable.png"); //$NON-NLS-1$ - private static final ImageDescriptor STATUS_UNAVAIL_IMGDESC = - RemoteConnectionsActivator.getImageDescriptor("icons/statusUnavailable.png"); //$NON-NLS-1$ - private static final ImageDescriptor STATUS_UNK_IMGDESC = - RemoteConnectionsActivator.getImageDescriptor("icons/statusUnknown.png"); //$NON-NLS-1$ - private static final ImageDescriptor CONNECTION_IMGDESC = - RemoteConnectionsActivator.getImageDescriptor("icons/connection.png"); //$NON-NLS-1$ - private static final ImageDescriptor CONNECTION_NEW_IMGDESC = - RemoteConnectionsActivator.getImageDescriptor("icons/connectionNew.png"); //$NON-NLS-1$ - private static final ImageDescriptor CONNECTION_EDIT_IMGDESC = - RemoteConnectionsActivator.getImageDescriptor("icons/connectionEdit.png"); //$NON-NLS-1$ - private static final ImageDescriptor SERVICE_TEST_IMGDESC = - RemoteConnectionsActivator.getImageDescriptor("icons/serviceTest.png"); //$NON-NLS-1$ - private static final ImageDescriptor STATUS_INUSE_IMGDESC = - RemoteConnectionsActivator.getImageDescriptor("icons/statusInUse.png"); //$NON-NLS-1$ - private static final ImageDescriptor CONNECTION_REFRESH_IMGDESC = - RemoteConnectionsActivator.getImageDescriptor("icons/connectionRefresh.png"); //$NON-NLS-1$ - private static final Image STATUS_AVAIL_IMG = STATUS_AVAIL_IMGDESC.createImage(); - private static final Image STATUS_UNAVAIL_IMG = STATUS_UNAVAIL_IMGDESC.createImage(); - private static final Image STATUS_INUSE_IMG = STATUS_INUSE_IMGDESC.createImage(); - private static final Image STATUS_UNK_IMG = STATUS_UNK_IMGDESC.createImage(); - private static final Image CONNECTION_IMG = CONNECTION_IMGDESC.createImage(); - private static final Color COLOR_RED = new Color(Display.getDefault(), 192, 0, 0); - private static final Color COLOR_GREEN = new Color(Display.getDefault(), 0, 128, 0); - private static final Color COLOR_ELECTRIC = new Color(Display.getDefault(), 0, 0, 255); - private static final Color COLOR_GREY = new Color(Display.getDefault(), 96, 96, 96); + private static final ImageDescriptor CONNECTION_NEW_IMGDESC = RemoteConnectionsActivator.getImageDescriptor("icons/connectionNew.png"); //$NON-NLS-1$ + private static final ImageDescriptor CONNECTION_EDIT_IMGDESC = RemoteConnectionsActivator.getImageDescriptor("icons/connectionEdit.png"); //$NON-NLS-1$ + private static final ImageDescriptor SERVICE_TEST_IMGDESC = RemoteConnectionsActivator.getImageDescriptor("icons/serviceTest.png"); //$NON-NLS-1$ + private static final ImageDescriptor CONNECTION_REFRESH_IMGDESC = RemoteConnectionsActivator.getImageDescriptor("icons/connectionRefresh.png"); //$NON-NLS-1$ + private static final String NEW_ACTION = "ConnectionsView.new"; //$NON-NLS-1$ private static final String EDIT_ACTION = "ConnectionsView.edit"; //$NON-NLS-1$ private static final String RENAME_ACTION = "ConnectionsView.rename"; //$NON-NLS-1$ @@ -91,8 +122,12 @@ private static final String REFRESH_ACTION = "ConnectionsView.refresh"; //$NON-NLS-1$ private static final String DELETE_ACTION = "ConnectionsView.delete"; //$NON-NLS-1$ private static final String HELP_ACTION = "ConnectionsView.help"; //$NON-NLS-1$ + private static final String SET_CURRENT_ACTION = "ConnectionsView.makeCurrent"; //$NON-NLS-1$ private KeyAdapter keyListener; private boolean isDisposed; + + // handle, do not dispose + private Font boldViewerFont; private TreeNode[] loadConnections() { if (serviceToListenerMap == null) @@ -100,14 +135,14 @@ removeServiceListeners(); List connectionNodes = new ArrayList(); Collection connections = - RemoteConnectionsActivator.getConnectionsManager().getConnections(); + Registry.instance().getConnections(); for (IConnection connection : connections) { // create a node for the connection TreeNode connectionNode = new TreeNode(connection); // create subnodes for the connected services List serviceNodes = new ArrayList(); Collection connectedServicesForConnection = - RemoteConnectionsActivator.getConnectionsManager().getConnectedServices(connection); + Registry.instance().getConnectedServices(connection); for (IConnectedService connectedService : connectedServicesForConnection) { final TreeNode treeNode = new TreeNode(connectedService); IStatusChangedListener statusChangedListener = new IStatusChangedListener() { @@ -144,10 +179,11 @@ super(viewer); editor = new TextCellEditor((Composite) viewer.getControl(), SWT.BORDER); } - + @Override protected boolean canEdit(Object element) { - if (((TreeNode) element).getValue() instanceof IConnection) + Object object = ((TreeNode) element).getValue(); + if (object instanceof IConnection && !isDynamicConnection(object)) return true; return false; } @@ -167,9 +203,10 @@ protected void setValue(Object element, Object value) { IConnection connection = (IConnection) ((TreeNode) element).getValue(); connection.setDisplayName(value.toString()); - viewer.refresh(true); - packColumns(); - RemoteConnectionsActivator.getConnectionsManager().storeConnections(); + //viewer.refresh(true); + //packColumns(); + Registry.instance().updateDisplays(); + Registry.instance().storeConnections(); } } @@ -178,31 +215,32 @@ public String getText(Object obj) { return getNodeDisplayName(obj); } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ColumnLabelProvider#getFont(java.lang.Object) + */ + @Override + public Font getFont(Object element) { + if (element instanceof TreeNode) { + if (((TreeNode)element).getValue().equals(Registry.instance().getCurrentConnection())) { + return boldViewerFont; + } + } + return super.getFont(element); + } public Image getImage(Object obj) { TreeNode node = (TreeNode) obj; Object value = node.getValue(); if (value instanceof IConnection) { - if (isConnectionInUse((IConnection) value)) { - return STATUS_INUSE_IMG; - } - return CONNECTION_IMG; + return ConnectionUIUtils.getConnectionImage((IConnection) value); } else if (value instanceof IConnectedService) { EStatus status = ((IConnectedService) value).getStatus().getEStatus(); IConnection connection = findConnection((IConnectedService) value); - if (connection != null && isConnectionInUse(connection)) + if (connection != null && ConnectionUIUtils.isSomeServiceInUse(connection)) status = EStatus.IN_USE; - switch (status) { - case DOWN: - return STATUS_UNAVAIL_IMG; - case UP: - return STATUS_AVAIL_IMG; - case IN_USE: - return CONNECTION_IMG; - case UNKNOWN: - return STATUS_UNK_IMG; - } + return ConnectionUIUtils.getConnectedServiceStatusImage(status); } return null; } @@ -216,16 +254,23 @@ IStatus status = null; IConnection connection = findConnection((IConnectedService) value); if (connection != null) - status = getFirstInUseStatus(connection); + status = ConnectionUIUtils.getFirstInUseServiceStatus(connection); if (status == null) { status = ((IConnectedService) value).getStatus(); return status.getShortDescription(); } } else if (value instanceof IConnection) { - IStatus status = getFirstInUseStatus((IConnection) value); - if (status != null) - return status.getShortDescription(); + if (isDynamicConnection(value)) { + IConnectionStatus status = ((IConnection2) value).getStatus(); + if (status != null) + return status.getShortDescription(); + } + else { + IStatus status = ConnectionUIUtils.getFirstInUseServiceStatus((IConnection) value); + if (status != null) + return status.getShortDescription(); + } } return null; @@ -239,18 +284,27 @@ EStatus status = ((IConnectedService) value).getStatus().getEStatus(); switch (status) { case DOWN: - return COLOR_RED; + return ConnectionUIUtils.COLOR_RED; case UP: - return COLOR_GREEN; + return ConnectionUIUtils.COLOR_GREEN; case UNKNOWN: - return COLOR_GREY; + return ConnectionUIUtils.COLOR_GREY; } } else if (value instanceof IConnection) // only showing in-use for connections - return COLOR_ELECTRIC; + return ConnectionUIUtils.COLOR_ELECTRIC; return null; } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ColumnLabelProvider#getFont(java.lang.Object) + */ + @Override + public Font getFont(Object element) { + // we need this to avoid letting the bold name column influence the others + return JFaceResources.getDefaultFont(); + } } public class DescriptionLabelProvider extends ColumnLabelProvider { @@ -263,7 +317,7 @@ IStatus status = ((IConnectedService) value).getStatus(); IConnection connection = findConnection((IConnectedService) value); if (!status.getEStatus().equals(EStatus.IN_USE) || - !(connection != null && isConnectionInUse(connection))) { // if in-use, we show it in the connection row + !(connection != null && ConnectionUIUtils.isSomeServiceInUse(connection))) { // if in-use, we show it in the connection row String longDescription = status.getLongDescription(); if (longDescription != null) longDescription = TextUtils.canonicalizeNewlines(longDescription, " "); //$NON-NLS-1$ @@ -271,13 +325,27 @@ } } else if (value instanceof IConnection) { - if (isConnectionInUse((IConnection) value)) { - return Messages.getString("ConnectionsView.InUseDesc"); + if (isDynamicConnection(value)) { + IConnectionStatus status = ((IConnection2) value).getStatus(); + if (status != null) + return status.getLongDescription(); + } + else if (ConnectionUIUtils.isSomeServiceInUse((IConnection) value)) { + return Messages.getString("ConnectionsView.InUseDesc"); //$NON-NLS-1$ } } return null; } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ColumnLabelProvider#getFont(java.lang.Object) + */ + @Override + public Font getFont(Object element) { + // we need this to avoid letting the bold name column influence the others + return JFaceResources.getDefaultFont(); + } } private class TypeLabelProvider extends ColumnLabelProvider { @@ -290,6 +358,15 @@ } return null; } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ColumnLabelProvider#getFont(java.lang.Object) + */ + @Override + public Font getFont(Object element) { + // we need this to avoid letting the bold name column influence the others + return JFaceResources.getDefaultFont(); + } } private class EnableConnectedServiceAction extends Action { @@ -358,6 +435,8 @@ } }; TreeViewerEditor.create(viewer, activationStrategy, ColumnViewerEditor.DEFAULT); + + boldViewerFont = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT); TreeViewerColumn typeColumn = new TreeViewerColumn(viewer, SWT.LEFT); typeColumn.setLabelProvider(new TypeLabelProvider()); @@ -455,7 +534,28 @@ }); } }; - RemoteConnectionsActivator.getConnectionsManager().addConnectionStoreChangedListener(connectionStoreChangedListener); + Registry.instance().addConnectionStoreChangedListener(connectionStoreChangedListener); + + connectionListener = new IConnectionListener() { + + public void currentConnectionSet(IConnection connection) { + Display.getDefault().asyncExec(new Runnable() { + public void run() { + viewer.refresh(true); + packColumns(); + } + }); + } + + public void connectionRemoved(IConnection connection) { + // presumably the viewer itself handles this... + } + + public void connectionAdded(IConnection connection) { + // presumably the viewer itself handles this... + } + }; + Registry.instance().addConnectionListener(connectionListener); RemoteConnectionsActivator.setHelp(parent, ".connections_view"); //$NON-NLS-1$ } @@ -507,13 +607,21 @@ return; TreeNode node = (TreeNode) ((IStructuredSelection) selection).getFirstElement(); Object value = node.getValue(); - if (value instanceof IConnectedService) + if (value instanceof IConnectedService) { + manager.add(new Separator()); manager.add(getAction(ENABLE_SERVICE_ACTION)); - else { + } + else if (value instanceof IConnection) { + manager.add(new Separator()); manager.add(getAction(RENAME_ACTION)); manager.add(getAction(EDIT_ACTION)); manager.add(getAction(DELETE_ACTION)); - manager.add(getAction(HELP_ACTION)); + IAction helpAction = getAction(HELP_ACTION); + if (helpAction.isEnabled()) { + helpAction.setText(helpAction.getText()); + manager.add(helpAction); + } + manager.add(getAction(SET_CURRENT_ACTION)); } } @@ -538,9 +646,10 @@ }; action.setId(NEW_ACTION); actions.add(action); - action.setEnabled(!RemoteConnectionsActivator.getConnectionTypeProvider().getConnectionTypes().isEmpty()); + action.setEnabled(!Registry.instance().getConnectionTypes().isEmpty()); - action = new Action(Messages.getString("ConnectionsView.EditActionLabel"), CONNECTION_EDIT_IMGDESC) { //$NON-NLS-1$ + String editLabel = Messages.getString("ConnectionsView.EditActionLabel"); //$NON-NLS-1$ + action = new Action(editLabel, CONNECTION_EDIT_IMGDESC) { //$NON-NLS-1$ @Override public void run() { ISelection selection = viewer.getSelection(); @@ -570,6 +679,11 @@ viewer.editElement(node, 0); } } + + @Override + public boolean isEnabled() { + return selectionCanBeEdited(); + } }; action.setId(RENAME_ACTION); action.setAccelerator(SWT.F2); @@ -587,7 +701,7 @@ action = new Action(Messages.getString("ConnectionsView.RefreshActionLabel"), CONNECTION_REFRESH_IMGDESC) { //$NON-NLS-1$ @Override public void run() { - IConnectionsManager connectionsManager = RemoteConnectionsActivator.getConnectionsManager(); + IConnectionsManager connectionsManager = Registry.instance(); for (IConnection connection : connectionsManager.getConnections()) { Collection connectedServices = connectionsManager.getConnectedServices(connection); for (IConnectedService connectedService : connectedServices) { @@ -607,15 +721,20 @@ @Override public void run() { ISelection selection = viewer.getSelection(); - if (selection.isEmpty()) + if (selection.isEmpty() || !canBeEdited(selection)) return; TreeNode node = (TreeNode) ((IStructuredSelection) selection).getFirstElement(); Object value = node.getValue(); if (value instanceof IConnection) { - RemoteConnectionsActivator.getConnectionsManager().removeConnection((IConnection) value); - RemoteConnectionsActivator.getConnectionsManager().storeConnections(); + Registry.instance().removeConnection((IConnection) value); + Registry.instance().storeConnections(); } } + + @Override + public boolean isEnabled() { + return selectionCanBeEdited(); + } }; action.setAccelerator(SWT.DEL); action.setId(DELETE_ACTION); @@ -624,21 +743,29 @@ Image image = JFaceResources.getImage(org.eclipse.jface.dialogs.Dialog.DLG_IMG_HELP); ImageDescriptor desc = ImageDescriptor.createFromImage(image); - action = new Action(Messages.getString("ConnectionsView.HelpActionLabel"), desc) { //$NON-NLS-1$ + action = new Action(Messages.getString("ConnectionsView.NoHelpActionLabel"), desc) { //$NON-NLS-1$ private String getHelpContextFromSelection() { - ISelection selection = viewer.getSelection(); - if (!selection.isEmpty()) { - TreeNode treeNode = (TreeNode) ((IStructuredSelection) selection).getFirstElement(); - Object value = treeNode.getValue(); - if (value instanceof IConnection) { - return ((IConnection) value).getConnectionType().getHelpContext(); - } + IConnection connection = getSelectedConnection(); + if (connection != null) { + return connection.getConnectionType().getHelpContext(); } return null; } @Override + public String getText() { + if (isEnabled()) { + IConnection connection = getSelectedConnection(); + IConnectionType connectionType = connection.getConnectionType(); + String displayName = connectionType.getDisplayName(); + String pattern = Messages.getString("ConnectionsView.HelpActionLabel"); //$NON-NLS-1$ + return MessageFormat.format(pattern, displayName); + } + return super.getText(); + } + + @Override public boolean isEnabled() { return getHelpContextFromSelection() != null; } @@ -651,6 +778,25 @@ action.setId(HELP_ACTION); actions.add(action); connectionSelectedActions.add(action); + + desc = ConnectionUIUtils.CONNECTION_IMGDESC; + action = new Action(Messages.getString("ConnectionsView.SetCurrentActionLabel"), desc) { //$NON-NLS-1$ + + @Override + public boolean isEnabled() { + return !ObjectUtils.equals(Registry.instance().getCurrentConnection(), getSelectedConnection()); + } + + @Override + public void run() { + Registry.instance().setCurrentConnection(getSelectedConnection()); + setEnabled(false); + } + }; + action.setId(SET_CURRENT_ACTION); + actions.add(action); + connectionSelectedActions.add(action); + enableConnectionSelectedActions(false); enableServiceSelectedActions(false); } @@ -707,10 +853,10 @@ private void disableAllConnectedServices() { Collection connections = - RemoteConnectionsActivator.getConnectionsManager().getConnections(); + Registry.instance().getConnections(); for (IConnection connection : connections) { Collection connectedServicesForConnection = - RemoteConnectionsActivator.getConnectionsManager().getConnectedServices(connection); + Registry.instance().getConnectedServices(connection); for (IConnectedService connectedService : connectedServicesForConnection) { connectedService.setEnabled(false); } @@ -720,15 +866,16 @@ @Override public void dispose() { removeServiceListeners(); - RemoteConnectionsActivator.getConnectionsManager().removeConnectionStoreChangedListener(connectionStoreChangedListener); + Registry.instance().removeConnectionStoreChangedListener(connectionStoreChangedListener); + Registry.instance().removeConnectionListener(connectionListener); disableAllConnectedServices(); isDisposed = true; super.dispose(); } private static IConnection findConnection(IConnectedService cs) { - for (IConnection connection : RemoteConnectionsActivator.getConnectionsManager().getConnections()) { - for (IConnectedService connectedService : RemoteConnectionsActivator.getConnectionsManager().getConnectedServices(connection)) { + for (IConnection connection : Registry.instance().getConnections()) { + for (IConnectedService connectedService : Registry.instance().getConnectedServices(connection)) { if (cs.equals(connectedService)) return connection; } @@ -736,22 +883,43 @@ return null; } - private static IStatus getFirstInUseStatus(IConnection connection) { - Collection connectedServices = - RemoteConnectionsActivator.getConnectionsManager().getConnectedServices(connection); - // if any service is in-use, then connection is in-use - for (IConnectedService connectedService : connectedServices) { - IStatus status = connectedService.getStatus(); - if (status.getEStatus().equals(EStatus.IN_USE)) - return status; + private static boolean isDynamicConnection(Object object) { + return object instanceof IConnection2 && ((IConnection2) object).isDynamic(); + } + + private boolean selectionCanBeEdited() { + ISelection selection = viewer.getSelection(); + return canBeEdited(selection); + } + + private static boolean canBeEdited(ISelection selection) { + if (selection.isEmpty()) + return false; + TreeNode node = (TreeNode) ((IStructuredSelection) selection).getFirstElement(); + return !isDynamicConnection(node.getValue()); + } + + private IConnection getSelectedConnection() { + ISelection selection = viewer.getSelection(); + if (!selection.isEmpty()) { + TreeNode treeNode = (TreeNode) ((IStructuredSelection) selection).getFirstElement(); + Object value = treeNode.getValue(); + if (value instanceof IConnection) { + return (IConnection) value; + } } - return null; } - private boolean isConnectionInUse(IConnection connection) { - return getFirstInUseStatus(connection) != null; + public void setSelectedConnection(IConnection connection) { + if (viewer != null && !viewer.getControl().isDisposed()) { + if (connection != null) { + TreeNode node = new TreeNode(connection); + viewer.setSelection(new StructuredSelection(node)); + } else { + viewer.setSelection(null); + } + } } - } diff -r 3f37e327885c -r d66843399035 connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/wizard/ExportPage.java --- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/wizard/ExportPage.java Mon Feb 01 12:38:42 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/wizard/ExportPage.java Mon Feb 01 13:27:18 2010 -0600 @@ -21,6 +21,8 @@ import com.nokia.carbide.remoteconnections.Messages; import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; import com.nokia.carbide.remoteconnections.interfaces.IConnection; +import com.nokia.carbide.remoteconnections.internal.registry.Registry; +import com.nokia.cpp.internal.api.utils.ui.BrowseDialogUtils; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; @@ -66,13 +68,13 @@ } } }); - viewer.setInput(RemoteConnectionsActivator.getConnectionsManager().getConnections()); + viewer.setInput(Registry.instance().getConnections()); TableColumn[] columns = viewer.getTable().getColumns(); for (TableColumn tableColumn : columns) { tableColumn.pack(); } viewer.setAllChecked(true); - connections = new ArrayList(RemoteConnectionsActivator.getConnectionsManager().getConnections()); + connections = new ArrayList(Registry.instance().getConnections()); createBrowseGroup(composite, Messages.getString("ExportPage.BrowseGroupLabel")); //$NON-NLS-1$ browseButton.addSelectionListener(new SelectionAdapter() { @@ -82,8 +84,7 @@ dialog.setText(Messages.getString("ExportPage.FileDialogTitle")); //$NON-NLS-1$ if (saveAsParent == null) saveAsParent = System.getProperty("user.home"); //$NON-NLS-1$ - dialog.setFilterPath(saveAsParent); - dialog.setFileName("exportedConnections.xml"); //$NON-NLS-1$ + BrowseDialogUtils.initializeFrom(dialog, new Path(saveAsParent).append("exportedConnections.xml")); //$NON-NLS-1$ dialog.setOverwrite(true); // prompt for overwrite String path = dialog.open(); if (path != null) { diff -r 3f37e327885c -r d66843399035 connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/wizard/ImportPage.java --- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/wizard/ImportPage.java Mon Feb 01 12:38:42 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/wizard/ImportPage.java Mon Feb 01 13:27:18 2010 -0600 @@ -22,6 +22,7 @@ import com.nokia.carbide.remoteconnections.Messages; import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; import com.nokia.carbide.remoteconnections.internal.registry.Reader; +import com.nokia.cpp.internal.api.utils.ui.BrowseDialogUtils; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; @@ -68,6 +69,7 @@ fileDialog.setText(Messages.getString("ImportPage.FileDialogTitle")); //$NON-NLS-1$ fileDialog.setFilterExtensions(FILTER_EXTS); fileDialog.setFilterNames(FILTER_EXT_NAMES); + BrowseDialogUtils.initializeFrom(fileDialog, pathText); String pathstr = fileDialog.open(); if (pathstr != null) { pathText.setText(pathstr); diff -r 3f37e327885c -r d66843399035 connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/wizard/ImportWizard.java --- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/wizard/ImportWizard.java Mon Feb 01 12:38:42 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/wizard/ImportWizard.java Mon Feb 01 13:27:18 2010 -0600 @@ -21,6 +21,7 @@ import com.nokia.carbide.remoteconnections.Messages; import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; import com.nokia.carbide.remoteconnections.interfaces.IConnection; +import com.nokia.carbide.remoteconnections.internal.registry.Registry; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.Wizard; @@ -46,9 +47,9 @@ public boolean performFinish() { List connections = importPage.getSelectedConnections(); for (IConnection connection : connections) { - RemoteConnectionsActivator.getConnectionsManager().addConnection(connection); + Registry.instance().addConnection(connection); } - RemoteConnectionsActivator.getConnectionsManager().storeConnections(); + Registry.instance().storeConnections(); return true; } diff -r 3f37e327885c -r d66843399035 debuggercdi/com.nokia.carbide.trk.support/META-INF/MANIFEST.MF --- a/debuggercdi/com.nokia.carbide.trk.support/META-INF/MANIFEST.MF Mon Feb 01 12:38:42 2010 -0600 +++ b/debuggercdi/com.nokia.carbide.trk.support/META-INF/MANIFEST.MF Mon Feb 01 13:27:18 2010 -0600 @@ -7,13 +7,13 @@ Bundle-Localization: plugin Require-Bundle: org.eclipse.core.runtime, org.eclipse.core.resources, - com.nokia.carbide.cpp.project.core, org.eclipse.emf.ecore, org.eclipse.emf.ecore.xmi, org.eclipse.help.ui, - com.nokia.cpp.utils.core, + com.freescale.cdt.debug.cw.core, com.nokia.carbide.remoteConnections, - com.freescale.cdt.debug.cw.core, + com.nokia.cpp.utils.core, + com.nokia.cpp.utils.ui;bundle-version="1.0.0", com.nokia.tcf, com.nokia.carbide.cpp.featureTracker;bundle-version="1.0.0" Bundle-ActivationPolicy: lazy diff -r 3f37e327885c -r d66843399035 debuggercdi/com.nokia.carbide.trk.support/src/com/nokia/carbide/trk/support/Activator.java --- a/debuggercdi/com.nokia.carbide.trk.support/src/com/nokia/carbide/trk/support/Activator.java Mon Feb 01 12:38:42 2010 -0600 +++ b/debuggercdi/com.nokia.carbide.trk.support/src/com/nokia/carbide/trk/support/Activator.java Mon Feb 01 13:27:18 2010 -0600 @@ -18,23 +18,16 @@ package com.nokia.carbide.trk.support; -import com.nokia.carbide.cpp.internal.featureTracker.FeatureUseTrackerConsts; -import com.nokia.carbide.cpp.internal.featureTracker.FeatureUseTrackerPlugin; -import com.nokia.cpp.internal.api.utils.core.Logging; - -import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; -public class Activator extends AbstractUIPlugin { +import com.nokia.carbide.cpp.internal.featureTracker.FeatureUseTrackerConsts; +import com.nokia.carbide.cpp.internal.featureTracker.FeatureUseTrackerPlugin; +import com.nokia.carbide.trk.support.status.ConnectionStatusReconciler; +import com.nokia.cpp.internal.api.utils.core.Logging; - private static final String INTERNAL_ONLY_FEATURE = "Carbide_InternalOnly"; //$NON-NLS-1$ - private static final String INTERNAL_ONLY_DESC = "Internal Only Feature"; //$NON-NLS-1$ - private static final String INTERNAL_ONLY_VERSION = "2.0"; //$NON-NLS-1$ - private static final String TRACE_FEATURE = "Carbide_OST_Trace"; //$NON-NLS-1$ - private static final String TRACE_DESC = "Carbide Trace Feature"; //$NON-NLS-1$ - private static final String TRACE_VERSION = "2.0"; //$NON-NLS-1$ +public class Activator extends AbstractUIPlugin { // The plug-in ID public static final String PLUGIN_ID = "com.nokia.carbide.trk.support"; //$NON-NLS-1$ @@ -55,6 +48,7 @@ public void start(BundleContext context) throws Exception { super.start(context); plugin = this; + ConnectionStatusReconciler.getInstance(); } /* @@ -62,6 +56,7 @@ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) */ public void stop(BundleContext context) throws Exception { + ConnectionStatusReconciler.getInstance().dispose(); plugin = null; super.stop(context); } diff -r 3f37e327885c -r d66843399035 debuggercdi/com.nokia.carbide.trk.support/src/com/nokia/carbide/trk/support/messages.properties --- a/debuggercdi/com.nokia.carbide.trk.support/src/com/nokia/carbide/trk/support/messages.properties Mon Feb 01 12:38:42 2010 -0600 +++ b/debuggercdi/com.nokia.carbide.trk.support/src/com/nokia/carbide/trk/support/messages.properties Mon Feb 01 13:27:18 2010 -0600 @@ -1,3 +1,13 @@ +ConnectionStatusReconciler_availableLabel=available +ConnectionStatusReconciler_DisconnectedLabel=Disconnected +ConnectionStatusReconciler_InUseLabel=In Use +ConnectionStatusReconciler_inUseLabel_lower=in use +ConnectionStatusReconciler_NotReadyLabel=Not Ready +ConnectionStatusReconciler_ReadyLabel=Ready +ConnectionStatusReconciler_TracingServicePrefix=, Tracing service +ConnectionStatusReconciler_TRKServicePrefix=TRK service +ConnectionStatusReconciler_unavailableLabel=unavailable +TRKConnectedService.AppTRKName=Application TRK TRKConnectedService.DownLabel=Not Accessible TRKConnectedService.ErrorStatus=Error: TRKConnectedService.InUseLabel=In Use @@ -12,6 +22,7 @@ TRKConnectedService.BadVersionResponseError=TRK version response was corrupted TRKConnectedService.NoPingErrorNoVersionError=Attempt to get TRK version timed out TRKConnectedService.RunningLabel=Available +TRKConnectedService.SysTRKName=System TRK TRKConnectedService.UnknownLabel=Unknown TRKService.Label=TRK TRKService.ServiceInfo=Ensure TRK is running on the device diff -r 3f37e327885c -r d66843399035 debuggercdi/com.nokia.carbide.trk.support/src/com/nokia/carbide/trk/support/service/ConnectedServiceFactory.java --- a/debuggercdi/com.nokia.carbide.trk.support/src/com/nokia/carbide/trk/support/service/ConnectedServiceFactory.java Mon Feb 01 12:38:42 2010 -0600 +++ b/debuggercdi/com.nokia.carbide.trk.support/src/com/nokia/carbide/trk/support/service/ConnectedServiceFactory.java Mon Feb 01 13:27:18 2010 -0600 @@ -20,6 +20,7 @@ import com.nokia.carbide.remoteconnections.interfaces.*; import com.nokia.carbide.trk.support.connection.*; +import com.nokia.cpp.internal.api.utils.core.HostOS; import java.util.*; @@ -34,10 +35,14 @@ public IConnectedService createConnectedService(IService service, IConnection connection) { if (service instanceof TracingService && isCompatibleConnection(getCompatibleTracingConnectionTypeIds(), connection)) { + if (HostOS.IS_UNIX) + return new RemoteConnectedService(service); // TODO: not ported return new TracingConnectedService(service, (AbstractSynchronizedConnection) connection); } else if (service instanceof TRKService && isCompatibleConnection(getCompatibleTRKConnectionTypeIds(), connection)) { + if (HostOS.IS_UNIX) + return new RemoteConnectedService(service); // TODO: not ported return new TRKConnectedService(service, (AbstractSynchronizedConnection) connection); } @@ -75,7 +80,7 @@ return getCompatibleTRKConnectionTypeIds(); else if (service instanceof TracingService) return getCompatibleTracingConnectionTypeIds(); - return Collections.EMPTY_LIST; + return Collections.emptyList(); } } diff -r 3f37e327885c -r d66843399035 debuggercdi/com.nokia.carbide.trk.support/src/com/nokia/carbide/trk/support/service/TRKConnectedService.java --- a/debuggercdi/com.nokia.carbide.trk.support/src/com/nokia/carbide/trk/support/service/TRKConnectedService.java Mon Feb 01 12:38:42 2010 -0600 +++ b/debuggercdi/com.nokia.carbide.trk.support/src/com/nokia/carbide/trk/support/service/TRKConnectedService.java Mon Feb 01 13:27:18 2010 -0600 @@ -18,30 +18,50 @@ package com.nokia.carbide.trk.support.service; -import com.freescale.cdt.debug.cw.core.SerialConnectionSettings; -import com.nokia.carbide.remoteconnections.interfaces.*; -import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus.EStatus; -import com.nokia.carbide.remoteconnections.interfaces.IRemoteAgentInstallerProvider.IRemoteAgentInstaller; -import com.nokia.carbide.trk.support.Messages; -import com.nokia.carbide.trk.support.connection.*; -import com.nokia.cpp.internal.api.utils.core.Check; -import com.nokia.cpp.internal.api.utils.core.Pair; -import com.nokia.tcf.api.*; +import java.io.IOException; +import java.text.MessageFormat; +import java.util.Arrays; +import java.util.List; import org.eclipse.core.runtime.IProgressMonitor; import org.osgi.framework.Version; -import java.io.IOException; -import java.text.MessageFormat; -import java.util.List; +import com.freescale.cdt.debug.cw.core.SerialConnectionSettings; +import com.nokia.carbide.remoteconnections.interfaces.AbstractConnectedService; +import com.nokia.carbide.remoteconnections.interfaces.AbstractSynchronizedConnection; +import com.nokia.carbide.remoteconnections.interfaces.IConnectionType; +import com.nokia.carbide.remoteconnections.interfaces.IService; +import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus.EStatus; +import com.nokia.carbide.remoteconnections.interfaces.IRemoteAgentInstallerProvider.IRemoteAgentInstaller; +import com.nokia.carbide.trk.support.Messages; +import com.nokia.carbide.trk.support.connection.SerialConnectionType; +import com.nokia.carbide.trk.support.connection.TCPIPConnectionFactory; +import com.nokia.carbide.trk.support.connection.TCPIPConnectionType; +import com.nokia.carbide.trk.support.connection.USBConnectionType; +import com.nokia.cpp.internal.api.utils.core.Check; +import com.nokia.cpp.internal.api.utils.core.Pair; +import com.nokia.tcf.api.ITCAPIConnection; +import com.nokia.tcf.api.ITCConnection; +import com.nokia.tcf.api.ITCMessage; +import com.nokia.tcf.api.ITCMessageIds; +import com.nokia.tcf.api.ITCMessageInputStream; +import com.nokia.tcf.api.ITCMessageOptions; +import com.nokia.tcf.api.TCFClassFactory; /** * */ public class TRKConnectedService extends AbstractConnectedService { + public static final String PROP_SYS_TRK = "is-system-trk"; //$NON-NLS-1$ + static { - System.loadLibrary("GetTRKVersion"); //$NON-NLS-1$ + try { + System.loadLibrary("GetTRKVersion"); //$NON-NLS-1$ + } catch (UnsatisfiedLinkError e) { + // no such library, e.g., not on Windows or in a misconfigured dev layout + e.printStackTrace(); + } } public native static void getTRKVersionFromSerial(String portName, @@ -62,8 +82,12 @@ private static final String TCPIP_IN_USE = Messages.getString("TRKConnectedService.TCPIPInUseStatus"); //$NON-NLS-1$ + private static final Version VERSIONS3_VERSION = new Version(3, 2, 4); private static final byte[] TRK_PING = {0x7e, 0x0, 0x0, (byte) 0xff, 0x7e}; private static final byte[] TRK_VERSION = {0x7e, 0x08, 0x01, (byte) 0xf6, 0x7e}; + private static final byte[] TRK_VERSIONS3 = {0x7e, 0x51, 0x02, (byte) 0xac, 0x7e}; + private static final byte[] SYS_TRK_RESPONSE = + {0x7e, (byte) 0x80, 0x02, 0x00, 0x03, 0x02, 0x03, 0x06, 0x04, 0x00, 0x0a, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x20, 0x54, 0x52, 0x4b, (byte) 0xcb, 0x7e}; private Pair deviceOS; private TRKService trkService; @@ -140,6 +164,9 @@ ITCMessage tcMsgVersion = TCFClassFactory.createITCMessage(TRK_VERSION); tcMsgVersion.setUseMyMessageId(true, trkRequestId); + ITCMessage tcMsgVersions3 = TCFClassFactory.createITCMessage(TRK_VERSIONS3); + tcMsgVersions3.setUseMyMessageId(true, trkRequestId); + // connect ITCAPIConnection api = TCFClassFactory.createITCAPIConnection(); org.eclipse.core.runtime.IStatus connStatus = api.connect(conn, options, ids); @@ -169,6 +196,19 @@ // printMessage(message); if (message != null && message.length == 11) { version = new Version(message[4], message[5], message[8]); + if (version.compareTo(VERSIONS3_VERSION) >= 0) { + // send trk versions3 + sendStatus = api.sendMessage(tcMsgVersions3); + + waitForSingleTCMessage(stream); + if (stream.peekMessages() > 0) { + tcMessage = stream.readMessage(); // version response + message = tcMessage.getMessage(); +// printMessage(message); + boolean isSysTrk = Arrays.equals(message, SYS_TRK_RESPONSE); + getProperties().put(PROP_SYS_TRK, Boolean.valueOf(isSysTrk).toString()); + } + } } else throw new ConnectionFailException(Messages.getString("TRKConnectedService.BadVersionResponseError")); //$NON-NLS-1$ @@ -194,18 +234,18 @@ } // private void printMessage(byte[] message) { -// for (int i = 0; i < message.length; i++) { -// String hexString = Integer.toHexString(message[i]); -// if (hexString.length() == 1) -// hexString = "0" + hexString; -// else if (hexString.length() > 2) -// hexString = hexString.substring(hexString.length() - 2); -// System.out.print(hexString); -// if (i + 1 < message.length) -// System.out.print('-'); +// for (int i = 0; i < message.length; i++) { +// String hexString = Integer.toHexString(message[i]); +// if (hexString.length() == 1) +// hexString = "0" + hexString; +// else if (hexString.length() > 2) +// hexString = hexString.substring(hexString.length() - 2); +// System.out.print(hexString); +// if (i + 1 < message.length) +// System.out.print('-'); +// } +// System.out.println(); // } -// System.out.println(); -//} private void waitForSingleTCMessage(ITCMessageInputStream stream) throws IOException { int timeout = TIMEOUT; @@ -278,10 +318,17 @@ estatus = EStatus.UP; Version serverVersion = getLatestVersionFromServer(); if (serverVersion == null) { - message = MessageFormat.format(OK_STATUS, deviceVersion); + StringBuilder trkVersionString = new StringBuilder(); + String sysTrkProp = getProperties().get(PROP_SYS_TRK); + if (sysTrkProp != null) + trkVersionString.append(Boolean.parseBoolean(sysTrkProp) ? + Messages.getString("TRKConnectedService.SysTRKName") : //$NON-NLS-1$ + Messages.getString("TRKConnectedService.AppTRKName")); //$NON-NLS-1$ + trkVersionString.append(deviceVersion.toString()); + message = MessageFormat.format(OK_STATUS, trkVersionString); } else if (deviceVersion.compareTo(serverVersion) >= 0) { - message = MessageFormat.format(IS_LASTEST, deviceVersion); + message = MessageFormat.format(IS_LASTEST, deviceVersion.toString()); } else { message = MessageFormat.format(NEEDS_INSTALL, @@ -303,7 +350,7 @@ return new TestResult(estatus, getShortDescription(estatus), message); } - + public void setDeviceOS(String familyName, Version version) { deviceOS = new Pair(familyName, version); } diff -r 3f37e327885c -r d66843399035 debuggercdi/com.nokia.carbide.trk.support/src/com/nokia/carbide/trk/support/service/TRKService.java --- a/debuggercdi/com.nokia.carbide.trk.support/src/com/nokia/carbide/trk/support/service/TRKService.java Mon Feb 01 12:38:42 2010 -0600 +++ b/debuggercdi/com.nokia.carbide.trk.support/src/com/nokia/carbide/trk/support/service/TRKService.java Mon Feb 01 13:27:18 2010 -0600 @@ -22,6 +22,7 @@ import com.nokia.carbide.trk.support.Messages; import com.nokia.carbide.trk.support.connection.*; import com.nokia.cpp.internal.api.utils.core.Check; +import com.nokia.cpp.internal.api.utils.core.HostOS; import java.util.*; @@ -56,6 +57,9 @@ } public IRemoteAgentInstallerProvider getInstallerProvider() { + if (HostOS.IS_UNIX) + return null; // TODO: implement + return new TRKInstallerProvider(this); } diff -r 3f37e327885c -r d66843399035 debuggercdi/com.nokia.carbide.trk.support/src/com/nokia/carbide/trk/support/service/TracingService.java --- a/debuggercdi/com.nokia.carbide.trk.support/src/com/nokia/carbide/trk/support/service/TracingService.java Mon Feb 01 12:38:42 2010 -0600 +++ b/debuggercdi/com.nokia.carbide.trk.support/src/com/nokia/carbide/trk/support/service/TracingService.java Mon Feb 01 13:27:18 2010 -0600 @@ -23,6 +23,7 @@ import com.nokia.carbide.trk.support.connection.TCPIPConnectionType; import com.nokia.carbide.trk.support.connection.USBConnectionType; import com.nokia.cpp.internal.api.utils.core.Check; +import com.nokia.cpp.internal.api.utils.core.HostOS; import java.util.Arrays; @@ -58,6 +59,8 @@ } public IRemoteAgentInstallerProvider getInstallerProvider() { + if (HostOS.IS_UNIX) + return null; // TODO: implement return new TracingInstallerProvider(this); } diff -r 3f37e327885c -r d66843399035 debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/AttachLaunchDelegate.java --- a/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/AttachLaunchDelegate.java Mon Feb 01 12:38:42 2010 -0600 +++ b/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/AttachLaunchDelegate.java Mon Feb 01 13:27:18 2010 -0600 @@ -70,7 +70,7 @@ config = RemoteConnectionsTRKHelper.attemptUpdateLaunchConfiguration(config.getWorkingCopy()); } - final IConnection connection = RemoteConnectionsTRKHelper.getConnectionFromConfig(config); + final IConnection connection = RemoteConnectionsTRKHelper.ensureConnectionFromConfig(config); if (connection == null) { IStatus status = new Status(Status.ERROR, LaunchPlugin.PLUGIN_ID, LaunchMessages.getString("TRKLaunchDelegate.NoConnectionErrorMsg")); //$NON-NLS-1$ @@ -93,6 +93,7 @@ setDefaultSourceLocator(launch, config); if (mode.equals(ILaunchManager.DEBUG_MODE)) { + hookConnectionStatus(); // debug mode ICDebugConfiguration debugConfig = getDebugConfig(config); ICDISession dsession = null; @@ -169,11 +170,13 @@ } } } + hookSessionEnded(); } else if (mode.equals(ILaunchManager.RUN_MODE)) { // run mode not supported for attach } } catch (CoreException e) { connection.useConnection(false); + unhookConnectionStatus(); if (! monitor.isCanceled()) // don't throw on user cancellation throw e; } finally { diff -r 3f37e327885c -r d66843399035 debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/LaunchPlugin.java --- a/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/LaunchPlugin.java Mon Feb 01 12:38:42 2010 -0600 +++ b/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/LaunchPlugin.java Mon Feb 01 13:27:18 2010 -0600 @@ -293,7 +293,7 @@ // which non-emulator launch type, // or both try { - final LaunchCreationWizard wizard = + final LaunchCreationWizard wizard = LaunchCreationWizardInstance.getInstance().create(project, defaultConfigName, mmpPaths, exePaths, defaultExecutable, isX86, useEmulatorByDefault, mode); Display.getDefault().syncExec(new Runnable() { public void run() { diff -r 3f37e327885c -r d66843399035 debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/TRKLaunchDelegate.java --- a/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/TRKLaunchDelegate.java Mon Feb 01 12:38:42 2010 -0600 +++ b/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/TRKLaunchDelegate.java Mon Feb 01 13:27:18 2010 -0600 @@ -22,15 +22,28 @@ import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.debug.core.ICDebugConfiguration; +import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.ICDISession; import org.eclipse.cdt.ui.CUIPlugin; -import org.eclipse.core.runtime.*; -import org.eclipse.debug.core.*; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.core.ILaunchManager; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.widgets.Display; import com.freescale.cdt.debug.cw.CWException; import com.freescale.cdt.debug.cw.core.RemoteConnectionsTRKHelper; +import com.freescale.cdt.debug.cw.core.cdi.ISessionListener; import com.freescale.cdt.debug.cw.core.cdi.Session; import com.freescale.cdt.debug.cw.core.cdi.model.Target; import com.nokia.carbide.cdt.builder.CarbideBuilderPlugin; @@ -38,6 +51,10 @@ import com.nokia.carbide.cdt.builder.project.ICarbideBuildConfiguration; import com.nokia.carbide.cdt.builder.project.ICarbideProjectInfo; import com.nokia.carbide.remoteconnections.interfaces.IConnection; +import com.nokia.carbide.remoteconnections.internal.api.IConnection2; +import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus; +import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatusChangedListener; +import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus.EConnectionStatus; import com.nokia.cdt.debug.cw.symbian.SettingsData; import com.nokia.cdt.debug.cw.symbian.SymbianPlugin; import com.nokia.cdt.internal.debug.launch.ui.PartialUpgradeAlertDialog; @@ -50,7 +67,8 @@ private static final int LARGE_SIS_THRESHOLD = 250 * 1024; // 250K protected Session cwDebugSession; - + private IConnection connection; + private IConnectionStatusChangedListener connectionStatusChangedListener; public void launch( ILaunchConfiguration config, @@ -77,7 +95,7 @@ config = RemoteConnectionsTRKHelper.attemptUpdateLaunchConfiguration(config.getWorkingCopy()); } - final IConnection connection = RemoteConnectionsTRKHelper.getConnectionFromConfig(config); + connection = RemoteConnectionsTRKHelper.ensureConnectionFromConfig(config); if (connection == null) { IStatus status = new Status(Status.ERROR, LaunchPlugin.PLUGIN_ID, LaunchMessages.getString("TRKLaunchDelegate.NoConnectionErrorMsg")); //$NON-NLS-1$ @@ -129,7 +147,8 @@ setDefaultSourceLocator(launch, config); if (mode.equals(ILaunchManager.DEBUG_MODE)) { - // debug mode + hookConnectionStatus(); + // debug mode ICDebugConfiguration debugConfig = getDebugConfig(config); ICDISession dsession = null; String debugMode = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE, @@ -174,6 +193,7 @@ } } } + hookSessionEnded(); } else if (mode.equals(ILaunchManager.RUN_MODE)) { // Run the program. @@ -224,10 +244,12 @@ } } catch (CWException e) { connection.useConnection(false); + unhookConnectionStatus(); if (! monitor.isCanceled()) // don't throw on user cancellation e.printStackTrace(); } catch (CoreException e) { connection.useConnection(false); + unhookConnectionStatus(); if (! monitor.isCanceled()) // don't throw on user cancellation throw e; } finally { @@ -237,6 +259,40 @@ } // end of synchronized. } + protected void hookSessionEnded() { + if (cwDebugSession != null) { + cwDebugSession.addListener(new ISessionListener() { + public void sessionEnded() { + connection.useConnection(false); + unhookConnectionStatus(); + } + }); + } + } + + protected void hookConnectionStatus() { + if (connection instanceof IConnection2) { + connectionStatusChangedListener = new IConnectionStatusChangedListener() { + public void statusChanged(IConnectionStatus status) { + if (status.getEConnectionStatus().equals(EConnectionStatus.IN_USE_DISCONNECTED)) { + try { + cwDebugSession.getLaunch().terminate(); + } catch (Exception e) { + LaunchPlugin.log(e); + } + } + } + }; + ((IConnection2) connection).addStatusChangedListener(connectionStatusChangedListener); + } + } + + protected void unhookConnectionStatus() { + if (connection instanceof IConnection2 && connectionStatusChangedListener != null) { + ((IConnection2) connection).removeStatusChangedListener(connectionStatusChangedListener); + } + } + @Override public boolean buildForLaunch(final ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException { diff -r 3f37e327885c -r d66843399035 debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/ui/AttachMainTab.java --- a/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/ui/AttachMainTab.java Mon Feb 01 12:38:42 2010 -0600 +++ b/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/ui/AttachMainTab.java Mon Feb 01 13:27:18 2010 -0600 @@ -18,12 +18,12 @@ import com.freescale.cdt.debug.cw.core.RemoteConnectionsTRKHelper; import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; -import com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI; -import com.nokia.carbide.remoteconnections.interfaces.IConnection; -import com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI.IListener; +import com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI2; +import com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI2.IListener; 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; @@ -36,8 +36,8 @@ protected Text remoteText; protected Label argsLabel; protected Text argsText; - protected IConnection connection; - protected IClientServiceSiteUI clientSiteUI; + protected String connection; + protected IClientServiceSiteUI2 clientSiteUI; public AttachMainTab() { super(DONT_CHECK_PROGRAM); @@ -59,7 +59,7 @@ fProjText.setToolTipText(Messages.getString("RunModeMainTab.8")); //$NON-NLS-1$ createVerticalSpacer(comp, 1); - clientSiteUI = RemoteConnectionsActivator.getConnectionsManager().getClientSiteUI(LaunchPlugin.getTRKService()); + clientSiteUI = RemoteConnectionsActivator.getConnectionsManager().getClientSiteUI2(LaunchPlugin.getTRKService()); clientSiteUI.createComposite(comp); clientSiteUI.addListener(new IListener() { public void connectionSelected() { @@ -85,7 +85,7 @@ if (!RemoteConnectionsTRKHelper.configUsesConnectionAttribute(config)) { config = RemoteConnectionsTRKHelper.attemptUpdateLaunchConfiguration(config.getWorkingCopy()); } - connection = RemoteConnectionsTRKHelper.getConnectionFromConfig(config); + connection = RemoteConnectionsTRKHelper.getConnectionIdFromConfig(config); } catch (CoreException e) { } if (connection != null) @@ -98,7 +98,7 @@ public void performApply(ILaunchConfigurationWorkingCopy config) { super.performApply(config); if (connection != null) { - config.setAttribute(RemoteConnectionsTRKHelper.CONNECTION_ATTRIBUTE, connection.getIdentifier()); + config.setAttribute(RemoteConnectionsTRKHelper.CONNECTION_ATTRIBUTE, connection); } } @@ -110,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; diff -r 3f37e327885c -r d66843399035 debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/ui/RunModeMainTab.java --- a/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/ui/RunModeMainTab.java Mon Feb 01 12:38:42 2010 -0600 +++ b/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/ui/RunModeMainTab.java Mon Feb 01 13:27:18 2010 -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; @@ -38,9 +39,8 @@ import com.freescale.cdt.debug.cw.core.RemoteConnectionsTRKHelper; import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; -import com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI; -import com.nokia.carbide.remoteconnections.interfaces.IConnection; -import com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI.IListener; +import com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI2; +import com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI2.IListener; import com.nokia.cdt.internal.debug.launch.LaunchPlugin; import cwdbg.PreferenceConstants; @@ -58,9 +58,9 @@ protected Label remoteLabel; protected Text remoteText; - protected IConnection connection; + protected String connection; protected boolean wantsConnectionUI = true; - protected IClientServiceSiteUI clientSiteUI; + protected IClientServiceSiteUI2 clientSiteUI; public void createControl(Composite parent) { Composite comp = new Composite(parent, SWT.NONE); @@ -81,7 +81,7 @@ if (wantsConnectionUI) { createVerticalSpacer(comp, 1); - clientSiteUI = RemoteConnectionsActivator.getConnectionsManager().getClientSiteUI(LaunchPlugin.getTRKService()); + clientSiteUI = RemoteConnectionsActivator.getConnectionsManager().getClientSiteUI2(LaunchPlugin.getTRKService()); clientSiteUI.createComposite(comp); clientSiteUI.addListener(new IListener() { public void connectionSelected() { @@ -153,7 +153,7 @@ if (!RemoteConnectionsTRKHelper.configUsesConnectionAttribute(config)) { config = RemoteConnectionsTRKHelper.attemptUpdateLaunchConfiguration(config.getWorkingCopy()); } - connection = RemoteConnectionsTRKHelper.getConnectionFromConfig(config); + connection = RemoteConnectionsTRKHelper.getConnectionIdFromConfig(config); } catch (CoreException e) { } if (clientSiteUI != null) @@ -170,7 +170,7 @@ super.performApply(config); config.setAttribute(PreferenceConstants.J_PN_RemoteProcessToLaunch, remoteText.getText()); if (connection != null) { - config.setAttribute(RemoteConnectionsTRKHelper.CONNECTION_ATTRIBUTE, connection.getIdentifier()); + config.setAttribute(RemoteConnectionsTRKHelper.CONNECTION_ATTRIBUTE, connection); } // Now check if the process to launch is the main target exe // for debugging. If not, try to set process to launch as the @@ -237,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; } } } diff -r 3f37e327885c -r d66843399035 debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/ui/messages.properties --- a/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/ui/messages.properties Mon Feb 01 12:38:42 2010 -0600 +++ b/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/ui/messages.properties Mon Feb 01 13:27:18 2010 -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. StopModeDebuggerTab.0=Break at entry point\: StopModeDebuggerTab.1=When enabled the debugger will automatically set a breakpoint at the function specified. StopModeDebuggerTab.10=Target Initialization files (*.cfg) diff -r 3f37e327885c -r d66843399035 debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/wizard/TRKConnectionWizardPage.java --- a/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/wizard/TRKConnectionWizardPage.java Mon Feb 01 12:38:42 2010 -0600 +++ b/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/wizard/TRKConnectionWizardPage.java Mon Feb 01 13:27:18 2010 -0600 @@ -16,8 +16,15 @@ */ package com.nokia.cdt.internal.debug.launch.wizard; -import java.text.MessageFormat; +import com.freescale.cdt.debug.cw.core.RemoteConnectionsTRKHelper; +import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; +import com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI2; +import com.nokia.carbide.remoteconnections.interfaces.IConnection; +import com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI2.IListener; +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; @@ -26,19 +33,13 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.PlatformUI; -import com.freescale.cdt.debug.cw.core.RemoteConnectionsTRKHelper; -import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; -import com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI; -import com.nokia.carbide.remoteconnections.interfaces.IConnection; -import com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI.IListener; -import com.nokia.cdt.internal.debug.launch.LaunchPlugin; -import com.nokia.cpp.internal.api.utils.core.Check; +import java.text.MessageFormat; public class TRKConnectionWizardPage extends WizardPage { private final ISummaryTextItemContainer summaryTextItemContainer; - private IClientServiceSiteUI clientSiteUI; - private IConnection connection; + private IClientServiceSiteUI2 clientSiteUI; + private String connectionId; public TRKConnectionWizardPage(ISummaryTextItemContainer summaryTextItemContainer) { @@ -58,7 +59,7 @@ GridLayout layout = new GridLayout(); composite.setLayout(layout); - clientSiteUI = RemoteConnectionsActivator.getConnectionsManager().getClientSiteUI(LaunchPlugin.getTRKService()); + clientSiteUI = RemoteConnectionsActivator.getConnectionsManager().getClientSiteUI2(LaunchPlugin.getTRKService()); clientSiteUI.createComposite(composite); clientSiteUI.addListener(new IListener() { public void connectionSelected() { @@ -72,26 +73,37 @@ } void updateConfiguration(ILaunchConfigurationWorkingCopy config) { - if (connection != null) { - config.setAttribute(RemoteConnectionsTRKHelper.CONNECTION_ATTRIBUTE, connection.getIdentifier()); + if (connectionId != null) { + config.setAttribute(RemoteConnectionsTRKHelper.CONNECTION_ATTRIBUTE, connectionId); } } public void setVisible(boolean visible) { super.setVisible(visible); + IConnection connection = RemoteConnectionsActivator.getConnectionsManager().findConnection(connectionId); if (!visible && connection != null) { summaryTextItemContainer.putSummaryTextItem("Connection", //$NON-NLS-1$ - MessageFormat.format("{0} {1}", Messages.getString("TRKConnectionWizardPage.ConnectionSummaryLabel"), connection.getDisplayName())); //$NON-NLS-1$ //$NON-NLS-2$ + MessageFormat.format("{0} {1}", Messages.getString("TRKConnectionWizardPage.ConnectionSummaryLabel"), //$NON-NLS-1$ //$NON-NLS-2$ + connection.getDisplayName())); } } 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); + } + } + else { + connectionId = clientSiteUI.getSelectedConnection(); } }