# HG changeset patch # User fturovic # Date 1265054212 21600 # Node ID c0a17ff7c85f04470441d53bc59de2aea1cf2664 # Parent 76faf0501c8907c1bfc9557d790049f8c46d28ed# Parent fd6ae4e6e3d9089c7f2a2bb20a389665e25ef702 daily merge diff -r 76faf0501c89 -r c0a17ff7c85f builder/com.nokia.carbide.cdt.builder.test/src/com/nokia/carbide/cdt/builder/test/TestEpocEngineHelper.java --- a/builder/com.nokia.carbide.cdt.builder.test/src/com/nokia/carbide/cdt/builder/test/TestEpocEngineHelper.java Mon Feb 01 13:55:02 2010 -0600 +++ b/builder/com.nokia.carbide.cdt.builder.test/src/com/nokia/carbide/cdt/builder/test/TestEpocEngineHelper.java Mon Feb 01 13:56:52 2010 -0600 @@ -185,4 +185,13 @@ } } } + + public void testSTDCPPSupport() throws Exception { + ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager().getProjectInfo(carbideProject); + for (final IPath mmpPath : EpocEngineHelper.getMMPFilesForBuildConfiguration(cpi.getDefaultConfiguration())) { + if (EpocEngineHelper.hasSTDCPPSupport(cpi, mmpPath)){ + fail("Project does not have STDCPP Support"); + } + } + } } diff -r 76faf0501c89 -r c0a17ff7c85f builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/builder/EpocEngineHelper.java --- a/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/builder/EpocEngineHelper.java Mon Feb 01 13:55:02 2010 -0600 +++ b/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/builder/EpocEngineHelper.java Mon Feb 01 13:56:52 2010 -0600 @@ -2641,4 +2641,46 @@ return paths; } + + /** + * Check whether or not the project and build for standard C++. + * The following rules apply: + * + * 1) If an MMP contains NOSTDCPP then it does not have std C++ support + * 2) Else If the STDCPP keyword is set it does have std C++ support + * 3) Else if TARGETTYPE is one of STDEXE|STDDLL|STDLIB it does have std C++ support + * 4) Else not std C++ support + * + * @param cpi + * @param mmpPath + * @return true if the MMP has standard C++ support + */ + public static boolean hasSTDCPPSupport(ICarbideProjectInfo projectInfo, + IPath relativeMMPPath) { + + Boolean result = (Boolean) EpocEnginePlugin.runWithMMPData( + relativeMMPPath, new DefaultMMPViewConfiguration(projectInfo, + new AllNodesViewFilter()), + new MMPDataRunnableAdapter() { + public Object run(IMMPData data) { + if (data.getFlags().contains(EMMPStatement.NOSTDCPP)) { + return false; + } else if (data.getFlags().contains( + EMMPStatement.STDCPP)) { + return true; + } + String targetType = data.getSingleArgumentSettings() + .get(EMMPStatement.TARGETTYPE); + if (targetType != null) { + if (targetType.toUpperCase().matches( + "STDEXE|STDLIB|STDDLL")) { //$NON-NLS-1$ + return true; + } + } + + return false; + } + }); + return result != null ? result.booleanValue() : false; + } } diff -r 76faf0501c89 -r c0a17ff7c85f builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/internal/builder/CarbideBuildConfiguration.java --- a/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/internal/builder/CarbideBuildConfiguration.java Mon Feb 01 13:55:02 2010 -0600 +++ b/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/internal/builder/CarbideBuildConfiguration.java Mon Feb 01 13:56:52 2010 -0600 @@ -28,12 +28,14 @@ import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Status; import com.nokia.carbide.cdt.builder.BuildArgumentsInfo; import com.nokia.carbide.cdt.builder.CarbideBuilderPlugin; +import com.nokia.carbide.cdt.builder.EpocEngineHelper; import com.nokia.carbide.cdt.builder.builder.CarbideCPPBuilder; import com.nokia.carbide.cdt.builder.project.IBuildArgumentsInfo; import com.nokia.carbide.cdt.builder.project.ICarbideBuildConfiguration; @@ -318,6 +320,10 @@ macros.add("NDEBUG"); //$NON-NLS-1$ } + if (hasSTDCPPSupport()){ + macros.add("__SYMBIAN_STDCPP_SUPPORT__"); + } + return macros; } @@ -374,4 +380,24 @@ public IROMBuilderInfo getROMBuildInfo() { return romBuilderInfo; } + + private boolean hasSTDCPPSupport() { + + ICarbideProjectInfo cpi = getCarbideProject(); + List buildConfig = new ArrayList(); + List normalMakMakePaths = new ArrayList(); + List testMakMakePaths = new ArrayList(); + buildConfig.add(this); + EpocEngineHelper.getMakMakeFiles(cpi.getAbsoluteBldInfPath(), + buildConfig, normalMakMakePaths, testMakMakePaths, + new NullProgressMonitor()); + + for (IPath mmpPath : normalMakMakePaths) { + if (EpocEngineHelper.hasSTDCPPSupport(cpi, mmpPath)) { + return true; + } + } + + return false; + } } diff -r 76faf0501c89 -r c0a17ff7c85f connectivity/com.nokia.carbide.remoteConnections.tests/plugin.xml --- a/connectivity/com.nokia.carbide.remoteConnections.tests/plugin.xml Mon Feb 01 13:55:02 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections.tests/plugin.xml Mon Feb 01 13:56:52 2010 -0600 @@ -63,5 +63,11 @@ class="com.nokia.carbide.remoteconnections.tests.extensions.DefaultProvidingTCPIPService"> + + + + diff -r 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections.tests/src/com/nokia/carbide/remoteconnections/tests/RegistryTest.java Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f connectivity/com.nokia.carbide.remoteConnections.tests/src/com/nokia/carbide/remoteconnections/tests/discovery/RandomDiscoveryAgent.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/connectivity/com.nokia.carbide.remoteConnections.tests/src/com/nokia/carbide/remoteconnections/tests/discovery/RandomDiscoveryAgent.java Mon Feb 01 13:56:52 2010 -0600 @@ -0,0 +1,150 @@ +/** +* 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" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +package com.nokia.carbide.remoteconnections.tests.discovery; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.HashSet; +import java.util.Map; +import java.util.Random; +import java.util.Set; + +import org.eclipse.core.runtime.CoreException; + +import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; +import com.nokia.carbide.remoteconnections.interfaces.IConnectionFactory; +import com.nokia.carbide.remoteconnections.interfaces.IConnectionType; +import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager; +import com.nokia.carbide.remoteconnections.internal.api.IConnection2; +import com.nokia.carbide.remoteconnections.internal.api.IDeviceDiscoveryAgent; +import com.nokia.carbide.remoteconnections.tests.extensions.IntervalConnectionType; +import com.nokia.carbide.remoteconnections.tests.extensions.TestFilter; + +public class RandomDiscoveryAgent implements IDeviceDiscoveryAgent { + public class RandomPrerequisiteStatus implements IPrerequisiteStatus { + + private boolean ok; + + RandomPrerequisiteStatus() { + ok = true; // modify to test + } + public String getErrorText() { + return "Test error text"; + } + + public URL getURL() { + try { + return new URL("http://www.yahoo.com"); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + return null; + } + + public boolean isOK() { + return ok; + } + + } + + private static final String CONNECTION_TYPE = + "com.nokia.carbide.remoteconnections.tests.extensions.IntervalConnectionType"; + private Random random = new Random(); + private Set connections = new HashSet(); + private IConnectionsManager manager = RemoteConnectionsActivator.getConnectionsManager(); + + private final class DiscoveryThread extends Thread { + private static final int MAX = 60000; + private static final int MIN = 10000; + private volatile boolean keepRunning; + + public void run() { + keepRunning = true; + while (keepRunning) { + try { + sleep(getRandomCreationIntervalMs()); + } catch (InterruptedException e) { + keepRunning = false; + } + if (getRandomIntBetween(0, connections.size() + 1) == 0) { + createNewConnection(); + } + else if (!connections.isEmpty()) { + IConnection2 connection = connections.iterator().next(); + connections.remove(connection); + manager.disconnect(connection); + } + } + } + + private int getRandomCreationIntervalMs() { + return getRandomIntBetween(MIN, MAX); + } + + public void stopRunning() { + keepRunning = false; + } + } + + private DiscoveryThread thread = new DiscoveryThread(); + + public URL getInformation() { + return null; + } + + private void createNewConnection() { + IConnectionType connectionType = + RemoteConnectionsActivator.getConnectionTypeProvider().getConnectionType(CONNECTION_TYPE); + IConnectionFactory factory = connectionType.getConnectionFactory(); + Map settings = factory.getSettingsFromUI(); + String val = getRandomIntervalString(); + settings.put(IntervalConnectionType.KEY, val); + IConnection2 connection = (IConnection2) factory.createConnection(settings); + connection.setDisplayName(connection.getConnectionType().getDisplayName() + " " + val + " ms"); + connection.setDynamic(true); + connections.add(connection); + manager.addConnection(connection); + } + + private String getRandomIntervalString() { + int r = getRandomIntBetween(1000, 30000); + return Integer.toString(r); + } + + private int getRandomIntBetween(int min, int max) { + return (Math.abs(random.nextInt()) % (max - min)) + min; + } + + public void start() throws CoreException { + if (TestFilter.isTest) + thread.start(); + } + + public void stop() throws CoreException { + thread.stopRunning(); + } + + public String getDisplayName() { + return "Random Test Discovery Agent"; + } + + public IPrerequisiteStatus getPrerequisiteStatus() { + return (new RandomPrerequisiteStatus()); + } + +} diff -r 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections.tests/src/com/nokia/carbide/remoteconnections/tests/extensions/AbstractServiceDialogAction.java Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections.tests/src/com/nokia/carbide/remoteconnections/tests/extensions/IntervalConnection.java Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections.tests/src/com/nokia/carbide/remoteconnections/tests/extensions/POUConnectionDialog.java Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections.tests/src/com/nokia/carbide/remoteconnections/tests/extensions/RandomCycleConnectedService.java Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f connectivity/com.nokia.carbide.remoteConnections/META-INF/MANIFEST.MF --- a/connectivity/com.nokia.carbide.remoteConnections/META-INF/MANIFEST.MF Mon Feb 01 13:55:02 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/META-INF/MANIFEST.MF Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f connectivity/com.nokia.carbide.remoteConnections/icons/connectionStatusInUse.png Binary file connectivity/com.nokia.carbide.remoteConnections/icons/connectionStatusInUse.png has changed diff -r 76faf0501c89 -r c0a17ff7c85f connectivity/com.nokia.carbide.remoteConnections/icons/connectionStatusInUseDisconnected.png Binary file connectivity/com.nokia.carbide.remoteConnections/icons/connectionStatusInUseDisconnected.png has changed diff -r 76faf0501c89 -r c0a17ff7c85f connectivity/com.nokia.carbide.remoteConnections/icons/connectionStatusNotReady.png Binary file connectivity/com.nokia.carbide.remoteConnections/icons/connectionStatusNotReady.png has changed diff -r 76faf0501c89 -r c0a17ff7c85f connectivity/com.nokia.carbide.remoteConnections/icons/connectionStatusReady.png Binary file connectivity/com.nokia.carbide.remoteConnections/icons/connectionStatusReady.png has changed diff -r 76faf0501c89 -r c0a17ff7c85f connectivity/com.nokia.carbide.remoteConnections/plugin.xml --- a/connectivity/com.nokia.carbide.remoteConnections/plugin.xml Mon Feb 01 13:55:02 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/plugin.xml Mon Feb 01 13:56:52 2010 -0600 @@ -5,6 +5,7 @@ + @@ -76,4 +77,47 @@ + + + + + + + + + + + + + + + + + + + + + + + diff -r 76faf0501c89 -r c0a17ff7c85f connectivity/com.nokia.carbide.remoteConnections/schema/deviceDiscoveryAgent.exsd --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/connectivity/com.nokia.carbide.remoteConnections/schema/deviceDiscoveryAgent.exsd Mon Feb 01 13:56:52 2010 -0600 @@ -0,0 +1,102 @@ + + + + + + + + + [Enter description of this extension point.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff -r 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/installpackages/InstallPackages.java Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/RemoteConnectionsActivator.java Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/AbstractConnectedService.java Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/AbstractConnection.java Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/IClientServiceSiteUI.java Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/IClientServiceSiteUI2.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/IClientServiceSiteUI2.java Mon Feb 01 13:56:52 2010 -0600 @@ -0,0 +1,95 @@ +/* +* Copyright (c) 2008 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" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +package com.nokia.carbide.remoteconnections.interfaces; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.swt.widgets.Composite; + +/** + * The user interface for picking or defining a connection to use that can be added to client service user interfaces. + *

+ * This variant allows selecting a "default connection" which will map to the currently selected default at runtime. + *

+ * This requires that you use {@link IConnectionsManager#ensureConnection(String, IService)} + * to map from a persisted connection identifier to an IConnection. Do not rely on "validating" + * the identifier manually by iterating the {@link IConnectionsManager#getConnections()}! + * @noimplement + * @noextend + * @since 3.0 + */ +public interface IClientServiceSiteUI2 { + + /** + * A listener interface to allow client sites to be notified when a new connection is selected + */ + public interface IListener { + void connectionSelected(); + } + + /** + * Create the composite with the client site UI for IService + * @param parent Composite + */ + void createComposite(Composite parent); + + /** + * Select a specific connection object - must be called after create composite + * @param connection the connection id or null + */ + void selectConnection(String connection); + + /** + * Return the selected connection object - may be called after UI is disposed. + *

+ * Do not expect to find this identifier in the {@link IConnectionsManager#getConnections()} list. + * Instead, use {@link IConnectionsManager#ensureConnection(String, IService)} to find + * the actual IConnection at runtime. + * @return the connection id, which may represent a "default". + */ + String getSelectedConnection(); + + /** + * Adds a listener to the client site UI + * @param listener IListener + */ + void addListener(IListener listener); + + /** + * Removes a listener from the client site UI + * @param listener IListener + */ + void removeListener(IListener listener); + + /** + * Validate the selected connection and return a status. + *

+ * @return IStatus for the state of the selection: + *

    + *
  1. If a connection is selected and it's compatible, return OK. + *
  2. If no connection is selected, return ERROR. + *
  3. If selected connection is a default, but the current default is incompatible, + * return WARNING. + * (Normally, the concrete connections are already filtered to show only + * compatible ones, but the default may be anything.) This is only a warning + * because the default connection can be changed externally to this UI, thus + * isn't a fatal error. + *
+ */ + IStatus getSelectionStatus(); +} diff -r 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/IConnectionFactory.java Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/IConnectionTypeProvider.java Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/IConnectionsManager.java Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/api/IConnectedService2.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/api/IConnectedService2.java Mon Feb 01 13:56:52 2010 -0600 @@ -0,0 +1,35 @@ +/** +* 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" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +package com.nokia.carbide.remoteconnections.internal.api; + +import java.util.Map; + +import com.nokia.carbide.remoteconnections.interfaces.IConnectedService; + +/** + * An extended interface to a connected service + * @since 3.0 + */ +public interface IConnectedService2 extends IConnectedService { + + /** + * Return the properties for this connected service + * @return Map + */ + Map getProperties(); +} diff -r 76faf0501c89 -r c0a17ff7c85f connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/api/IConnection2.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/api/IConnection2.java Mon Feb 01 13:56:52 2010 -0600 @@ -0,0 +1,105 @@ +/** +* 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" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +package com.nokia.carbide.remoteconnections.internal.api; + +import org.eclipse.jface.resource.ImageDescriptor; + +import com.nokia.carbide.remoteconnections.interfaces.IConnection; + +/** + * An extended interface to a connection + * @since 3.0 + */ +public interface IConnection2 extends IConnection { + + /** + * Whether this connection is dynamic (managed by an automated process) + * Dynamic connections are not persisted or user editable. + * @return boolean + */ + boolean isDynamic(); + + /** + * Sets this connection's dynamic attribute. + * @see IConnection2#isDynamic() + * @param dynamic boolean + */ + void setDynamic(boolean dynamic); + + /** + * The status of a connection + */ + public interface IConnectionStatus { + enum EConnectionStatus { + READY, NOT_READY, IN_USE, IN_USE_DISCONNECTED, NONE + }; + + EConnectionStatus getEConnectionStatus(); + + String getShortDescription(); + + String getLongDescription(); + } + + /** + * Gets this connection's status + * @return IStatus + */ + IConnectionStatus getStatus(); + + /** + * Sets this connection's status + * @see IConnection2#getStatus() + * @param status IStatus + */ + void setStatus(IConnectionStatus status); + + /** + * A listener for status changes + */ + public interface IConnectionStatusChangedListener { + void statusChanged(IConnectionStatus status); + } + + /** + * Adds a listener for status changes + * @param listener IStatusChangedListener + */ + void addStatusChangedListener(IConnectionStatusChangedListener listener); + + /** + * Removes a listener for status changes + * @param listener IStatusChangedListener + */ + void removeStatusChangedListener(IConnectionStatusChangedListener listener); + + /** + * An optional icon representing this connection. + * If none is set, the default icon is used. + * @return ImageDescriptor + */ + ImageDescriptor getImageDescriptor(); + + /** + * Set the image descriptor for this connection. + * @see IConnection2#getImageDescriptor() + * @param imageDescriptor + */ + void setImageDescriptor(ImageDescriptor imageDescriptor); + +} diff -r 76faf0501c89 -r c0a17ff7c85f connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/api/IDeviceDiscoveryAgent.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/api/IDeviceDiscoveryAgent.java Mon Feb 01 13:56:52 2010 -0600 @@ -0,0 +1,96 @@ +/** +* 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" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +package com.nokia.carbide.remoteconnections.internal.api; + +import java.net.URL; + +import org.eclipse.core.runtime.CoreException; + +/** + * An interface to a device discovery agent + * @since 3.0 + */ +public interface IDeviceDiscoveryAgent { + + /** + * An interface for discovery agents to implement that the manager uses + * before loading the agent to get errors about required components. + *

+ * Every discovery agent must implement this interface. + */ + public interface IPrerequisiteStatus { + /** + * Is the status OK? + * @return boolean + */ + boolean isOK(); + /** + * If status is not OK, return error message text. + * @return String + */ + String getErrorText(); + /** + * Optionally return a URL for user to browse to for more information on error. + * @return URL + */ + URL getURL(); + + } + + /** + * Starts agent. Once started, runs until stopped. + * @throws CoreException + */ + void start() throws CoreException; + + /** + * Stops agent. + * @throws CoreException + */ + void stop() throws CoreException; + + /** + * Returns a URL to specific information about this discovery mechanism, + * troubleshooting, etc. + * @return URL + */ + URL getInformation(); + + /** + * Returns a display name for the particular discovery agent in case we need to + * let the user know errors from the agents. + * @return String + */ + String getDisplayName(); + + /** + * Manager will call this to get any status of prerequisites not satisfied before + * the manager calls start(). The agent should check its prerequisites at this time. + *

+ * If the agent has no prerequisites return a status of OK. + * @return IPrerequisiteStatus + */ + IPrerequisiteStatus getPrerequisiteStatus(); + + // In addition, there may need to be an additional API to do a deeper form of discovery for + // connection mechanisms that require pairing (like BT or Wifi). In these cases, normal discovery + // will probably be for already paired devices, however, the user will want to discover all + // potential devices from some UI in order to set up a paired device. + // A method for doing this will need to be added. + +} diff -r 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/registry/Registry.java Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ui/ClientServiceSiteUI2.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ui/ClientServiceSiteUI2.java Mon Feb 01 13:56:52 2010 -0600 @@ -0,0 +1,446 @@ +/* +* Copyright (c) 2008 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" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +package com.nokia.carbide.remoteconnections.internal.ui; + +import com.nokia.carbide.remoteconnections.Messages; +import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; +import com.nokia.carbide.remoteconnections.interfaces.*; +import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener; +import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionsManagerListener; +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; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.viewers.*; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.*; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.*; + +import java.text.MessageFormat; +import java.util.*; +import java.util.List; + +/** + * Implementation of IClientServiceSiteUI2 + */ +@SuppressWarnings("deprecation") +public class ClientServiceSiteUI2 implements IClientServiceSiteUI2, IConnectionListener, IConnectionsManagerListener { + + private IService service; + private ComboViewer viewer; + private FontMetrics fm; + private Set compatibleConnectionTypes; + private Button editButton; + private Button newButton; + private String connection; + private ListenerList listenerList; + private static final String UID = ".uid"; //$NON-NLS-1$ + private Map connectionNames; + + public ClientServiceSiteUI2(IService service) { + Check.checkArg(service); + this.service = service; + } + + public void createComposite(Composite parent) { + initializeDialogUnits(parent); + Group group = new Group(parent, SWT.NONE); + group.setText(Messages.getString("ClientServiceSiteUI2.UseConnectionGroupLabel")); //$NON-NLS-1$ + group.setLayout(new GridLayout()); + group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + group.setData(UID, "useConnectionGroup"); //$NON-NLS-1$ + + viewer = new ComboViewer(group, SWT.READ_ONLY); + viewer.setLabelProvider(new LabelProvider() { + @Override + public String getText(Object element) { + Check.checkContract(element instanceof String); + String id = (String) element; + return connectionNames.get(id); + } + }); + viewer.setContentProvider(new ArrayContentProvider()); + GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false); + viewer.getCombo().setLayoutData(gd); + viewer.getControl().setData(UID, "viewer"); //$NON-NLS-1$ + viewer.addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + IStructuredSelection selection = (IStructuredSelection) event.getSelection(); + String connection = (String) selection.getFirstElement(); + if (!connection.equals(ClientServiceSiteUI2.this.connection)) { + ClientServiceSiteUI2.this.connection = connection; + fireConnectionSelected(); + } + } + }); + + final Composite composite = new Composite(group, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + layout.makeColumnsEqualWidth = true; + layout.marginWidth = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.HORIZONTAL_MARGIN); + layout.marginHeight = Dialog.convertVerticalDLUsToPixels(fm, IDialogConstants.VERTICAL_MARGIN); + layout.horizontalSpacing = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.HORIZONTAL_SPACING); + layout.verticalSpacing = Dialog.convertVerticalDLUsToPixels(fm, IDialogConstants.VERTICAL_SPACING); + composite.setLayout(layout); + gd = new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.VERTICAL_ALIGN_CENTER); + composite.setLayoutData(gd); + composite.setFont(parent.getFont()); + + newButton = new Button(composite, SWT.PUSH); + newButton.setText(Messages.getString("ClientServiceSiteUI2.NewButtonLabel")); //$NON-NLS-1$ + newButton.setFont(JFaceResources.getDialogFont()); + gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL); + int widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH); + Point minSize = newButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); + gd.widthHint = Math.max(widthHint, minSize.x); + newButton.setLayoutData(gd); + newButton.setData(UID, "newButton"); //$NON-NLS-1$ + newButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + SettingsWizard wizard = new SettingsWizard(null, service); + wizard.open(composite.getShell()); + IConnection connection = wizard.getConnectionToEdit(); + // note: refresh ASAP so the selection will be valid; but endure a listener event + // which will redo this + refreshUI(); + setViewerInput(connection); + } + }); + + editButton = new Button(composite, SWT.PUSH); + editButton.setText(Messages.getString("ClientServiceSiteUI2.EditButtonLabel")); //$NON-NLS-1$ + editButton.setFont(JFaceResources.getDialogFont()); + gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL); + widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH); + minSize = editButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); + gd.widthHint = Math.max(widthHint, minSize.x); + editButton.setLayoutData(gd); + editButton.setData(UID, "editButton"); //$NON-NLS-1$ + editButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); + Object value = selection.getFirstElement(); + if (value instanceof String) { + IConnection editConnection = getActualConnection((String) value); + SettingsWizard wizard = new SettingsWizard(editConnection, service); + wizard.open(composite.getShell()); + + // leave the viewer the same, callback will refresh anything needed + } + } + }); + + // attach listeners + RemoteConnectionsActivator.getConnectionsManager().addConnectionListener(this); + RemoteConnectionsActivator.getConnectionsManager().addConnectionStoreChangedListener(this); + + // remove listeners on dispose + group.addDisposeListener(new DisposeListener() { + + public void widgetDisposed(DisposeEvent e) { + RemoteConnectionsActivator.getConnectionsManager().addConnectionListener(ClientServiceSiteUI2.this); + RemoteConnectionsActivator.getConnectionsManager().addConnectionStoreChangedListener(ClientServiceSiteUI2.this); + } + }); + + setViewerInput(null); + } + + /** + * Get the actual connection for an identifier. + * This is not {@link IConnectionsManager#ensureConnection(String, IService)} because we don't + * want to actually validate the connection now. + * @param id + * @return {@link IConnection} or null + */ + protected IConnection getActualConnection(String id) { + if (id == null) { + return null; + } + if (id.equals(Registry.CURRENT_CONNECTION_ID)) { + return RemoteConnectionsActivator.getConnectionsManager().getCurrentConnection(); + } + for (IConnection connection : RemoteConnectionsActivator.getConnectionsManager().getConnections()) { + if (connection.getIdentifier().equals(id)) { + return connection; + } + } + return null; + } + + /** + * Set the selected input. + * @param connection existing connection or null for the current + */ + private void setViewerInput(IConnection connection) { + List compatible = getCompatibleConnections(); + connectionNames = new LinkedHashMap(); + + // update the current + IConnection currentConnection = RemoteConnectionsActivator.getConnectionsManager().getCurrentConnection(); + + connectionNames.put(Registry.CURRENT_CONNECTION_ID, createCurrentConnectionName(currentConnection)); + + for (IConnection conn : compatible) { + connectionNames.put(conn.getIdentifier(), conn.getDisplayName()); + } + + viewer.setInput(connectionNames.keySet()); + + if (connectionNames.isEmpty()) + viewer.getCombo().setEnabled(false); + else { + viewer.getCombo().setEnabled(true); + if (connection == null) { + viewer.getCombo().select(0); + viewer.setSelection(viewer.getSelection()); + } + else + selectConnection(connection.getIdentifier()); + } + editButton.setEnabled(!viewer.getSelection().isEmpty()); + + // fire listener in case we selected anew or the current connection changed + fireConnectionSelected(); + } + + private void refreshUI() { + Display.getDefault().syncExec(new Runnable() { + public void run() { + if (viewer != null && viewer.getContentProvider() != null) { + + // try to preserve the currently selected item, if it's a concrete + // connection; if it's current, allow for the new current to be chosen. + IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); + Object value = selection.getFirstElement(); + String current = null; + if (value instanceof String) { + current = (String) value; + } + if (Registry.CURRENT_CONNECTION_ID.equals(current)) { + current = null; + } + setViewerInput(getActualConnection(current)); + } + } + }); + } + + /** + * @param currentConnection + * @return + */ + private String createCurrentConnectionName(IConnection currentConnection) { + return MessageFormat.format(Messages.getString("ClientServiceSiteUI2.CurrentConnectionFormat"), //$NON-NLS-1$ + currentConnection != null ? currentConnection.getDisplayName() : + Messages.getString("ClientServiceSiteUI2.CurrentConnection_NoneDetected")); //$NON-NLS-1$ + } + + private void initializeDialogUnits(Composite parent) { + GC gc = new GC(parent); + gc.setFont(JFaceResources.getDialogFont()); + fm = gc.getFontMetrics(); + gc.dispose(); + } + + private List getCompatibleConnections() { + getCompatibleConnectionTypes(); + + List compatibleConnections = new ArrayList(); + for (IConnection connection : Registry.instance().getConnections()) { + if (isCompatibleConnection(connection)) + compatibleConnections.add(connection); + } + return compatibleConnections; + } + + private boolean isCompatibleConnection(IConnection connection) { + return compatibleConnectionTypes.contains(connection.getConnectionType()); + } + + private void getCompatibleConnectionTypes() { + compatibleConnectionTypes = new HashSet(); + Collection compatibleTypeIds = + Registry.instance().getCompatibleConnectionTypeIds(service); + for (String typeId : compatibleTypeIds) { + compatibleConnectionTypes.add( + Registry.instance().getConnectionType(typeId)); + } + } + + public void selectConnection(String connection) { + viewer.setSelection(new StructuredSelection(connection)); + } + + public String getSelectedConnection() { + return connection; + } + + public IStatus getSelectionStatus() { + String requiredConnectionTypes = getAllowedConnectionTypesString(); + + // no selection yet...? + if (connection == null) { + return new Status(IStatus.ERROR, RemoteConnectionsActivator.PLUGIN_ID, + MessageFormat.format( + Messages.getString("ClientServiceSiteUI2.NoConnectionError"), //$NON-NLS-1$ + service.getDisplayName(), + requiredConnectionTypes)); + } + + // check whether the current is compatible with the service and connection type + if (Registry.CURRENT_CONNECTION_ID.equals(connection)) { + IConnection actual = getActualConnection(connection); + if (actual == null) { + return new Status(IStatus.ERROR, RemoteConnectionsActivator.PLUGIN_ID, + MessageFormat.format( + Messages.getString("ClientServiceSiteUI2.NoCurrentConnection"), //$NON-NLS-1$ + service.getDisplayName(), + requiredConnectionTypes)); + } + + // is the service supported? + boolean found = false; + for (IConnectedService aService : Registry.instance().getConnectedServices(actual)) { + if (service.getIdentifier().equals(aService.getService().getIdentifier())) { + found = true; + break; + } + } + if (!found) { + return new Status(IStatus.WARNING, RemoteConnectionsActivator.PLUGIN_ID, + MessageFormat.format( + Messages.getString("ClientServiceSiteUI2.IncompatibleCurrentConnectionService") //$NON-NLS-1$ + + "\n" //$NON-NLS-1$ + + Messages.getString("ClientServiceSiteUI2.IncompatibleCurrentConnectionFixupAdvice"), //$NON-NLS-1$ + actual.getDisplayName(), + service.getDisplayName())); + } + + // is the hardware type supported by the service? + if (!isCompatibleConnection(actual)) { + return new Status(IStatus.WARNING, RemoteConnectionsActivator.PLUGIN_ID, + MessageFormat.format( + Messages.getString("ClientServiceSiteUI2.IncompatibleCurrentConnectionType") //$NON-NLS-1$ + + "\n" //$NON-NLS-1$ + + Messages.getString("ClientServiceSiteUI2.IncompatibleCurrentConnectionFixupAdvice"), //$NON-NLS-1$ + actual.getDisplayName(), + requiredConnectionTypes)); + + } + } + + // otherwise, it's okay! + return Status.OK_STATUS; + } + + private String getAllowedConnectionTypesString() { + StringBuilder requiredConnectionTypes = new StringBuilder(); + IConnectionType[] connectionTypes = + (IConnectionType[]) compatibleConnectionTypes.toArray(new IConnectionType[compatibleConnectionTypes.size()]); + for (int i = 0; i < connectionTypes.length; i++) { + IConnectionType type = connectionTypes[i]; + if (requiredConnectionTypes.length() > 0) + requiredConnectionTypes.append(", "); //$NON-NLS-1$ + if (i == connectionTypes.length - 1) + requiredConnectionTypes.append(Messages.getString("ClientServiceSiteUI2.Or")); //$NON-NLS-1$ + requiredConnectionTypes.append(type.getDisplayName()); + } + return requiredConnectionTypes.toString(); + } + + /* (non-Javadoc) + * @see com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI2#getConnectionDisplayName(java.lang.String) + */ + public String getConnectionDisplayName(String connection) { + String display = connectionNames.get(connection); + if (display == null) + display = MessageFormat.format(Messages.getString("ClientServiceSiteUI2.DeletedConnectionDisplayName"), connection); //$NON-NLS-1$ + return display; + } + + public void addListener(IListener listener) { + if (listenerList == null) + listenerList = new ListenerList(); + listenerList.add(listener); + } + + public void removeListener(IListener listener) { + if (listenerList != null) + listenerList.remove(listener); + } + + private void fireConnectionSelected() { + if (listenerList != null) { + for (IListener listener : listenerList) { + listener.connectionSelected(); + } + } + } + + /* (non-Javadoc) + * @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener#connectionAdded(com.nokia.carbide.remoteconnections.interfaces.IConnection) + */ + public void connectionAdded(IConnection connection) { + refreshUI(); + } + + /* (non-Javadoc) + * @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener#connectionRemoved(com.nokia.carbide.remoteconnections.interfaces.IConnection) + */ + public void connectionRemoved(IConnection connection) { + refreshUI(); + } + + /* (non-Javadoc) + * @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener#currentConnectionSet(com.nokia.carbide.remoteconnections.interfaces.IConnection) + */ + public void currentConnectionSet(IConnection connection) { + refreshUI(); + } + + /* (non-Javadoc) + * @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionsManagerListener#connectionStoreChanged() + */ + public void connectionStoreChanged() { + refreshUI(); + } + + /* (non-Javadoc) + * @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionsManagerListener#displayChanged() + */ + public void displayChanged() { + refreshUI(); + } +} diff -r 76faf0501c89 -r c0a17ff7c85f connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ui/ConnectionStatusSelectorContribution.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ui/ConnectionStatusSelectorContribution.java Mon Feb 01 13:56:52 2010 -0600 @@ -0,0 +1,551 @@ +/* +* 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" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +package com.nokia.carbide.remoteconnections.internal.ui; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +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.graphics.Rectangle; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.swt.widgets.ToolItem; +import org.eclipse.swt.widgets.ToolTip; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.menus.CommandContributionItem; +import org.eclipse.ui.menus.WorkbenchWindowControlContribution; + +import com.nokia.carbide.remoteconnections.Messages; +import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; +import com.nokia.carbide.remoteconnections.interfaces.IConnection; +import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager; +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.api.IConnection2.IConnectionStatusChangedListener; +import com.nokia.carbide.remoteconnections.internal.registry.Registry; +import com.nokia.carbide.remoteconnections.view.ConnectionsView; +import com.nokia.cpp.internal.api.utils.core.TextUtils; +import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils; + + +/** + * This widget appears in the Eclipse trim and allows the user to select the + * "current" device connection and also see its status at a glance. + *

+ * Note: the UI for this control should behave similarly to that of the News Reader + * trim. Due to the way we're modifying the icon and the state dynamically + * for this contribution, they can't be implemented the same way, however. + */ +@SuppressWarnings("deprecation") +public class ConnectionStatusSelectorContribution extends WorkbenchWindowControlContribution { + + /** + * This is the id on the command in the toolbar contribution associated with this + * widget. Keep this in sync with the extension point! + */ + private static final String OPEN_REMOTE_CONNECTIONS_VIEW_COMMAND_ID = "openRemoteConnectionsView"; //$NON-NLS-1$ + private Composite container; + private CLabel connectionInfo; + private ToolItem connectionIcon; + private IConnectionsManager manager; + private IConnection currentConnection; + private ListenerBlock listenerBlock; + private ToolTip tooltip; + private MouseAdapter toolbarListener; + private ToolBar toolbar; + + /** + * Contains all the listeners. In most cases we just recreate the contribution status item. + */ + class ListenerBlock implements IConnectionListener, IConnectionsManagerListener, IConnectionStatusChangedListener { + + /* (non-Javadoc) + * @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener#connectionAdded(com.nokia.carbide.remoteconnections.interfaces.IConnection) + */ + public void connectionAdded(IConnection connection) { + updateUI(); + boolean display = (connection instanceof IConnection2 && ((IConnection2) connection).isDynamic()); + if (display) + launchBubble(MessageFormat.format( + Messages.getString("ConnectionStatusSelectorContribution.AddedConnectionFormat"), //$NON-NLS-1$ + connection.getDisplayName())); + } + + /* (non-Javadoc) + * @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener#connectionRemoved(com.nokia.carbide.remoteconnections.interfaces.IConnection) + */ + public void connectionRemoved(IConnection connection) { + updateUI(); + boolean display = (connection instanceof IConnection2 && ((IConnection2) connection).isDynamic()); + if (display) + launchBubble(MessageFormat.format( + Messages.getString("ConnectionStatusSelectorContribution.RemovedConnectionFormat"), //$NON-NLS-1$ + connection.getDisplayName())); + } + + /* (non-Javadoc) + * @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener#currentConnectionSet(com.nokia.carbide.remoteconnections.interfaces.IConnection) + */ + public void currentConnectionSet(IConnection connection) { + updateUI(); + } + + /* (non-Javadoc) + * @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionsManagerListener#connectionStoreChanged() + */ + public void connectionStoreChanged() { + updateUI(); + } + + /* (non-Javadoc) + * @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionsManagerListener#displayChanged() + */ + public void displayChanged() { + updateUI(); + } + + /* (non-Javadoc) + * @see com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatusChangedListener#statusChanged(com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus) + */ + public void statusChanged(IConnectionStatus status) { + updateConnectionStatus(status); + } + + } + + public ConnectionStatusSelectorContribution() { + manager = RemoteConnectionsActivator.getConnectionsManager(); + listenerBlock = new ListenerBlock(); + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.action.ControlContribution#createControl(org.eclipse.swt.widgets.Composite) + */ + @Override + protected Control createControl(Composite parent) { + + // This UI is recreated whenever the current connection changes. + + // This is gross. The normal parent of this is a toolbar, + // but we cannot add arbitrary stuff to the toolbar besides + // this control. (If you try, it will usually show up + // out of order!) + // + // But we want to have a toolbar button for the connection icon + // for which we can change the tooltip and image, and attach + // a mouse listener responds to left and right clicking. + // + // In order to do this, we need to poke around in the widget tree + // to find the expected Eclipse-generated toolitem. Unfortunately, + // controlling all this ourselves is even uglier (I tried). + + if (parent instanceof ToolBar) { + toolbar = (ToolBar) parent; + ToolItem[] items = toolbar.getItems(); + for (ToolItem item : items) { + Object data = item.getData(); + if (data instanceof CommandContributionItem && + ((CommandContributionItem) data).getId().contains(OPEN_REMOTE_CONNECTIONS_VIEW_COMMAND_ID)) { + connectionIcon = item; + break; + } + } + } else { + toolbar = null; + } + + container = new Composite(parent, SWT.NONE); + GridLayoutFactory.fillDefaults().margins(2, 0).applyTo(container); + + // Create a label for the trim, outside the toolbar. + connectionInfo = new CLabel(container, SWT.NONE); + GridDataFactory.fillDefaults().grab(false, true).applyTo(connectionInfo); + + String text = Messages.getString("ConnectionStatusSelectorContribution_NoCurrentConnectionMessage"); //$NON-NLS-1$ + currentConnection = manager.getCurrentConnection(); + if (currentConnection != null) + text = currentConnection.getDisplayName(); + + connectionInfo.setText(text); + + attachListeners(); + + updateConnectionStatus(getConnectionStatus(currentConnection)); + + + // Yuck, toolbars and items have a wonky UI. We need to do these events on the parent, + // since the ToolItem itself is just an area inside the parent. (#getControl() is only for separators ?!) + + // On icon: left click = open view, right click = menu + + if (toolbar != null) { + if (toolbarListener != null) + toolbar.removeMouseListener(toolbarListener); + + toolbarListener = new MouseAdapter() { + /* (non-Javadoc) + * @see org.eclipse.swt.events.MouseAdapter#mouseDown(org.eclipse.swt.events.MouseEvent) + */ + @Override + public void mouseDown(MouseEvent event) { + ToolItem item = toolbar.getItem(new Point(event.x, event.y)); + if (item == connectionIcon) { + if (event.button == 1) { + openConnectionsView(); + } else if (event.button == 3) { + Point screenLoc = toolbar.toDisplay(event.x, event.y); + handleConnectionMenu(screenLoc); + } + } + } + }; + toolbar.addMouseListener(toolbarListener); + + // On label: left or right click = menu + connectionInfo.addMouseListener(new MouseAdapter() { + public void mouseDown(MouseEvent event) { + if (event.button == 1 || event.button == 3) { + Point screenLoc = toolbar.toDisplay(event.x, event.y); + handleConnectionMenu(screenLoc); + } + } + }); + } + + RemoteConnectionsActivator.setHelp(container, "ConnectionStatusSelector"); //$NON-NLS-1$ + return container; + } + + private void handleConnectionMenu(Point screenLoc) { + Shell shell = connectionInfo.getParent().getShell(); + final Display display = shell.getDisplay(); + + final Menu menu = new Menu(shell, SWT.POP_UP); + populateConnectionMenu(menu); + + menu.setLocation(screenLoc.x, screenLoc.y); + menu.setVisible(true); + + while (!menu.isDisposed() && menu.isVisible()) { + if (!display.readAndDispatch()) + display.sleep(); + } + menu.dispose(); + + } + + /** + * @return + */ + protected void populateConnectionMenu(Menu menu) { + // Display the connections with dynamic ones first, + // then static ones, separated by a separator + + List dynamicConnections = new ArrayList(); + List staticConnections = new ArrayList(); + for (IConnection connection : RemoteConnectionsActivator.getConnectionsManager().getConnections()) { + if (connection instanceof IConnection2 && ((IConnection2)connection).isDynamic()) + dynamicConnections.add(connection); + else + staticConnections.add(connection); + } + + + Comparator connectionComparator = new Comparator() { + public int compare(IConnection o1, IConnection o2) { + return o1.getDisplayName().compareToIgnoreCase(o2.getDisplayName()); + } + }; + Collections.sort(dynamicConnections, connectionComparator); + Collections.sort(staticConnections, connectionComparator); + + MenuItem label = new MenuItem(menu, SWT.NONE); + label.setEnabled(false); + + int number = 1; + if (dynamicConnections.size() + staticConnections.size() == 0) { + label.setText(Messages.getString("ConnectionStatusSelectorContribution.NoConnectionsDefinedOrDetected")); //$NON-NLS-1$ + } else { + label.setText(Messages.getString("ConnectionStatusSelectorContribution_SelectTheCurrentConnectionMessage")); //$NON-NLS-1$ + + for (IConnection connection : dynamicConnections) { + createConnectionMenuItem(menu, connection, currentConnection, number++); + } + + if (!staticConnections.isEmpty()) + new MenuItem(menu, SWT.SEPARATOR); + + for (IConnection connection : staticConnections) { + createConnectionMenuItem(menu, connection, currentConnection, number++); + } + } + + new MenuItem(menu, SWT.SEPARATOR); + + MenuItem openView = new MenuItem(menu, SWT.PUSH); + openView.setText(Messages.getString("ConnectionStatusSelectorContribution.OpenRemoteConnectionsView")); //$NON-NLS-1$ + openView.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + openConnectionsView(); + } + }); + } + + /** + * @param menu + * @param connection + * @param currentConnection + */ + private MenuItem createConnectionMenuItem(Menu menu, + final IConnection connection, + IConnection currentConnection, + int number) { + MenuItem item = new MenuItem(menu, SWT.CHECK); + + boolean isCurrent = false; + isCurrent = connection.equals(currentConnection); + + item.setSelection(isCurrent); + + item.setText(MessageFormat.format("&{0} - {1}", number, connection.getDisplayName())); //$NON-NLS-1$ + + item.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + manager.setCurrentConnection(connection); + } + }); + + return item; + } + + private void attachListeners() { + manager.addConnectionListener(listenerBlock); + Registry.instance().addConnectionStoreChangedListener(listenerBlock); + + if (currentConnection != null) { + if (currentConnection instanceof IConnection2) { + ((IConnection2) currentConnection).addStatusChangedListener(listenerBlock); + } + } + } + + private void removeListeners() { + if (currentConnection != null) { + if (currentConnection instanceof IConnection2) { + ((IConnection2) currentConnection).removeStatusChangedListener(listenerBlock); + } + } + manager.removeConnectionListener(listenerBlock); + Registry.instance().removeConnectionStoreChangedListener(listenerBlock); + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.action.ContributionItem#dispose() + */ + public void dispose() { + removeListeners(); + if (connectionIcon != null) + connectionIcon.dispose(); + if (toolbarListener != null && !toolbar.isDisposed()) + toolbar.removeMouseListener(toolbarListener); + if (connectionInfo != null) + connectionInfo.dispose(); + + super.dispose(); + } + + /** + * @param ev + */ + protected void openConnectionsView() { + try { + IViewPart view = WorkbenchUtils.getView(ConnectionsView.VIEW_ID); + if (currentConnection != null && view instanceof ConnectionsView) { + ((ConnectionsView) view).setSelectedConnection(currentConnection); + } + } + catch (PartInitException e) { + RemoteConnectionsActivator.logError(e); + } + } + + /** + * @param currentConnection + * @param status + * @return + */ + private String createConnectionStatusTooltip(IConnection currentConnection, + IConnectionStatus status) { + if (currentConnection == null) { + return Messages.getString("ConnectionStatusSelectorContribution.NoDynamicOrManualConnectionsTooltip"); //$NON-NLS-1$ + } + + String statusString = null; + if (status != null) { + statusString = createStatusString(status); + } + + if (TextUtils.isEmpty(statusString)) { + // fallback string; the status should not be empty + if (ConnectionUIUtils.isSomeServiceInUse(currentConnection)) + statusString = Messages.getString("ConnectionStatusSelectorContribution.InUse"); //$NON-NLS-1$ + else + statusString = Messages.getString("ConnectionStatusSelectorContribution.NotInUse"); //$NON-NLS-1$ + } + + return MessageFormat.format(Messages.getString("ConnectionStatusSelectorContribution.ConnectionStatusFormat"), currentConnection.getDisplayName(), statusString); //$NON-NLS-1$ + } + + private String createStatusString(IConnectionStatus status) { + String shortDescription = status.getShortDescription(); + if (shortDescription == null || shortDescription.length() == 0) + return ""; //$NON-NLS-1$ + String pattern = Messages.getString("ConnectionStatusSelectorContribution.StatusFormat"); //$NON-NLS-1$ + if (shortDescription != null) + shortDescription = shortDescription.toLowerCase(); + return MessageFormat.format(pattern, shortDescription, status.getLongDescription()); + } + + /** + * Get the image representing the connection status. + * @param connection + * @return Image, to be disposed + */ + private IConnectionStatus getConnectionStatus(IConnection connection) { + if (!(connection instanceof IConnection2)) { + return null; + } else { + return ((IConnection2) connection).getStatus(); + } + } + + /** + * @param status + */ + private void updateConnectionStatus(final IConnectionStatus status) { + Display.getDefault().asyncExec(new Runnable() { + public void run() { + if (connectionIcon == null || connectionIcon.isDisposed()) + return; + + Image statusImage; + if (status != null) + statusImage = ConnectionUIUtils.getConnectionStatusImage(status); + else + statusImage = ConnectionUIUtils.getConnectionImage(currentConnection); + + connectionIcon.setImage(statusImage); + String tip = createConnectionStatusTooltip(currentConnection, status); + connectionInfo.setToolTipText(tip); + + String preamble = Messages.getString("ConnectionStatusSelectorContribution.IconTooltipPrefixMessage"); //$NON-NLS-1$ + connectionIcon.setToolTipText(preamble + tip); + } + }); + + } + + /** + * + */ + private void updateUI() { + // perform update in UI thread + final IWorkbench workbench = PlatformUI.getWorkbench(); + workbench.getDisplay().asyncExec(new Runnable() { + public void run() { + IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); + if (window != null) { + update(); + } + } + }); + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.action.ContributionItem#isDynamic() + */ + @Override + public boolean isDynamic() { + return true; + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.action.ContributionItem#update() + */ + @Override + public void update() { + getParent().update(true); + } + + /** + * Show a status bubble for important changes. + * @param string + */ + public void launchBubble(final String string) { + Display.getDefault().asyncExec(new Runnable() { + public void run() { + if (tooltip != null) + tooltip.dispose(); + + if (connectionInfo == null || connectionInfo.isDisposed()) + return; + + tooltip = new ToolTip(connectionInfo.getParent().getShell(), SWT.BALLOON | SWT.ICON_INFORMATION); + tooltip.setMessage(string); + Rectangle bounds = connectionInfo.getBounds(); + Point center = new Point(bounds.x + bounds.width / 2, + bounds.y + bounds.height); + Point location = connectionInfo.getParent().toDisplay(center); + //System.out.println(connectionInfo.hashCode() + ": " + connectionInfo.getLocation() + " : " + location); + tooltip.setLocation(location); + tooltip.setVisible(true); + } + }); + } + + +} \ No newline at end of file diff -r 76faf0501c89 -r c0a17ff7c85f connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ui/ConnectionUIUtils.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ui/ConnectionUIUtils.java Mon Feb 01 13:56:52 2010 -0600 @@ -0,0 +1,162 @@ +/* +* 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" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +package com.nokia.carbide.remoteconnections.internal.ui; + +import java.util.Collection; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; + +import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; +import com.nokia.carbide.remoteconnections.interfaces.IConnectedService; +import com.nokia.carbide.remoteconnections.interfaces.IConnection; +import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus; +import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus.EStatus; +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.IConnectionStatus.EConnectionStatus; +import com.nokia.carbide.remoteconnections.internal.registry.Registry; + +/** + * + */ +public class ConnectionUIUtils { + + 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 STATUS_INUSE_IMGDESC = + RemoteConnectionsActivator.getImageDescriptor("icons/statusInUse.png"); //$NON-NLS-1$ + + private static final ImageDescriptor CONNECTION_READY_IMGDESC = + RemoteConnectionsActivator.getImageDescriptor("icons/connectionStatusReady.png"); //$NON-NLS-1$ + private static final ImageDescriptor CONNECTION_IN_USE_IMGDESC = + RemoteConnectionsActivator.getImageDescriptor("icons/connectionStatusInUse.png"); //$NON-NLS-1$ + private static final ImageDescriptor CONNECTION_NOT_READY_IMGDESC = + RemoteConnectionsActivator.getImageDescriptor("icons/connectionStatusNotReady.png"); //$NON-NLS-1$ + private static final ImageDescriptor CONNECTION_IN_USE_DISCONNECTED_IMGDESC = + RemoteConnectionsActivator.getImageDescriptor("icons/connectionStatusInUseDisconnected.png"); //$NON-NLS-1$ + + public static final ImageDescriptor CONNECTION_IMGDESC = + RemoteConnectionsActivator.getImageDescriptor("icons/connection.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_READY_IMG = CONNECTION_READY_IMGDESC.createImage(); + private static final Image CONNECTION_IN_USE_IMG = CONNECTION_IN_USE_IMGDESC.createImage(); + private static final Image CONNECTION_NOT_READY_IMG = CONNECTION_NOT_READY_IMGDESC.createImage(); + private static final Image CONNECTION_IN_USE_DISCONNECTED_IMG = CONNECTION_IN_USE_DISCONNECTED_IMGDESC.createImage(); + + private static final Image CONNECTION_IMG = CONNECTION_IMGDESC.createImage(); + + public static final Color COLOR_RED = new Color(Display.getDefault(), 192, 0, 0); + public static final Color COLOR_GREEN = new Color(Display.getDefault(), 0, 128, 0); + public static final Color COLOR_ELECTRIC = new Color(Display.getDefault(), 0, 0, 255); + public static final Color COLOR_GREY = new Color(Display.getDefault(), 96, 96, 96); + + /** + * Get the image representing the connection status. + * @param connection + * @return Image, not to be disposed + */ + public static Image getConnectionStatusImage(IConnectionStatus status) { + if (status != null) { + EConnectionStatus severity = status.getEConnectionStatus(); + + switch (severity) { + case READY: + return CONNECTION_READY_IMG; + case IN_USE: + return CONNECTION_IN_USE_IMG; + case NOT_READY: + return CONNECTION_NOT_READY_IMG; + case IN_USE_DISCONNECTED: + return CONNECTION_IN_USE_DISCONNECTED_IMG; + } + } + return ConnectionUIUtils.CONNECTION_IMG; + } + + /** + * Get the image representing the connection status. + * @param connection + * @return Image, not to be disposed + */ + public static Image getConnectionImage(IConnection connection) { + // TODO: remove this when we have real statuses from a connection + if (isSomeServiceInUse(connection)) { + return ConnectionUIUtils.STATUS_INUSE_IMG; + } + if (connection instanceof IConnection2) { + IConnectionStatus status = ((IConnection2) connection).getStatus(); + return getConnectionStatusImage(status); + } else { + // old connection logic + if (isSomeServiceInUse(connection)) { + return ConnectionUIUtils.STATUS_INUSE_IMG; + } + return ConnectionUIUtils.CONNECTION_IMG; + } + } + + /** + * @param status + * @return + */ + public static Image getConnectedServiceStatusImage(IConnectedService.IStatus.EStatus status) { + switch (status) { + case DOWN: + return ConnectionUIUtils.STATUS_UNAVAIL_IMG; + case UP: + return ConnectionUIUtils.STATUS_AVAIL_IMG; + case IN_USE: + return ConnectionUIUtils.CONNECTION_IMG; + case UNKNOWN: + return ConnectionUIUtils.STATUS_UNK_IMG; + } + return null; + } + + public static IStatus getFirstInUseServiceStatus(IConnection connection) { + Collection connectedServices = + Registry.instance().getConnectedServices(connection); + // if any service is in-use, then connection is in-use + if (connectedServices == null) + return null; + + for (IConnectedService connectedService : connectedServices) { + IStatus status = connectedService.getStatus(); + if (status.getEStatus().equals(EStatus.IN_USE)) + return status; + } + + return null; + } + + public static boolean isSomeServiceInUse(IConnection connection) { + return getFirstInUseServiceStatus(connection) != null; + } +} diff -r 76faf0501c89 -r c0a17ff7c85f connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ui/DeviceDiscoveryPrequisiteErrorDialog.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ui/DeviceDiscoveryPrequisiteErrorDialog.java Mon Feb 01 13:56:52 2010 -0600 @@ -0,0 +1,223 @@ +/* +* Copyright (c) 2010 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" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ +package com.nokia.carbide.remoteconnections.internal.ui; + +import java.net.URL; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Collection; + +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.TrayDialog; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.ISelection; +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.window.IShellProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.SashForm; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Link; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.browser.IWebBrowser; + +import com.nokia.carbide.remoteconnections.Messages; +import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; + +public class DeviceDiscoveryPrequisiteErrorDialog extends TrayDialog { + + private class AgentItem { + public String agentName; + public String agentErrorText; + public URL agentLocation; + + AgentItem(String name, String text, URL location) { + agentName = name; + agentErrorText = text; + agentLocation = location; + // if location is not null and error text doesn't contain href + // then do it here + if (agentLocation != null && !agentErrorText.contains("href")) { //$NON-NLS-1$ + String msg = MessageFormat.format(Messages.getString("DeviceDiscoveryPrequisiteErrorDialog_ErrorFormatWithURL"), //$NON-NLS-1$ + agentErrorText, location, location); + agentErrorText = msg; + } + } + } + + private Collection agentList = new ArrayList(); + private boolean dontAskAgain; + private ListViewer agentListViewer; + private Link errorText; + private Button dontAskAgainCheckBox; + + /** + * @param parentShell + */ + public DeviceDiscoveryPrequisiteErrorDialog(Shell parentShell) { + super(parentShell); + agentList.clear(); + } + + /** + * @param parentShell + */ + public DeviceDiscoveryPrequisiteErrorDialog(IShellProvider parentShell) { + super(parentShell); + agentList.clear(); + } + + public void addAgentData(String name, String errorText, URL location) { + agentList.add(new AgentItem(name, errorText, location)); + } + + public boolean isDontAskAgainChecked() { + return dontAskAgain; + } + + @Override + protected void createButtonsForButtonBar(Composite parent) { + // OK button == "Close" + // no Cancel button + createButton(parent, IDialogConstants.OK_ID, IDialogConstants.CLOSE_LABEL, true); + } + + @Override + protected Control createDialogArea(Composite parent) { + initializeDialogUnits(parent); + + Composite container = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(1, true); + container.setLayout(layout); + container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + // Message at top + Text topMessage = new Text(container, SWT.MULTI | SWT.WRAP); + topMessage.setText(Messages.getString("DeviceDiscoveryPrequisiteErrorDialog_Description")); //$NON-NLS-1$ + topMessage.setEditable(false); + topMessage.setDoubleClickEnabled(false); + GridData topMsgData = new GridData(SWT.LEFT, SWT.CENTER, true, false); + topMsgData.heightHint = 48; + topMessage.setLayoutData(topMsgData); + topMessage.setToolTipText(Messages.getString("DeviceDiscoveryPrequisiteErrorDialog_ToolTipText")); //$NON-NLS-1$ + + // next two panes can be resized with a sash form + SashForm sashForm = new SashForm(container, SWT.VERTICAL); + GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); + sashForm.setLayoutData(gridData); + + // this pane lists all the agent display names + agentListViewer = new ListViewer(sashForm, SWT.V_SCROLL | SWT.BORDER); + agentListViewer.setContentProvider(new ArrayContentProvider()); + agentListViewer.setLabelProvider(new LabelProvider() { + + @Override + public String getText(Object element) { + return ((AgentItem)element).agentName; + } + + }); + agentListViewer.addSelectionChangedListener(new ISelectionChangedListener() { + + public void selectionChanged(SelectionChangedEvent event) { + IStructuredSelection selection = (IStructuredSelection) event.getSelection(); + AgentItem item = (AgentItem) selection.getFirstElement(); + errorText.setText(item.agentErrorText); + } + + }); + agentListViewer.setInput(agentList); + + // pane to view the information about the selected agent + errorText = new Link(sashForm, SWT.V_SCROLL | SWT.BORDER | SWT.WRAP); + errorText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); + errorText.setToolTipText(Messages.getString("DeviceDiscoveryPrequisiteErrorDialog_ErrorTextToolTipText")); //$NON-NLS-1$ + errorText.addListener(SWT.Selection, new Listener() { + + public void handleEvent(Event event) { + // Launch an external browser + String siteText = event.text; + IWorkbench workbench = PlatformUI.getWorkbench(); + try { + IWebBrowser browser = workbench.getBrowserSupport().getExternalBrowser(); + browser.openURL(new URL(siteText)); + } catch (Exception e) { + RemoteConnectionsActivator.logError(e); + } + } + + }); + + // add initial weights to the above two panes + sashForm.setWeights(new int[] {150,200}); + + // now the don't ask again check box + dontAskAgainCheckBox = new Button(container, SWT.CHECK); + dontAskAgainCheckBox.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false)); + dontAskAgainCheckBox.setText(Messages.getString("DeviceDiscoveryPrequisiteErrorDialog_DontAskAgainLabel")); //$NON-NLS-1$ + dontAskAgainCheckBox.setToolTipText(Messages.getString("DeviceDiscoveryPrequisiteErrorDialog_DontAskAgainToolTipText")); //$NON-NLS-1$ + dontAskAgainCheckBox.addSelectionListener(new SelectionAdapter() { + + public void widgetSelected(SelectionEvent e) { + dontAskAgain = dontAskAgainCheckBox.getSelection(); + } + + }); + + // now finish by selecting the top most agent in the list + // and bringing it into view + Object o = agentListViewer.getElementAt(0); + if (o != null) + agentListViewer.setSelection(new StructuredSelection(o)); + + ISelection selection = agentListViewer.getSelection(); + if (selection != null && !selection.isEmpty()) { + agentListViewer.reveal(selection); + } + + return container; + } + + @Override + protected Point getInitialSize() { + return new Point(400,400); + } + + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + // set our title to the dialog + newShell.setText(Messages.getString("DeviceDiscoveryPrequisiteErrorDialog_Title")); //$NON-NLS-1$ + } +} diff -r 76faf0501c89 -r c0a17ff7c85f connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ui/OpenConnectionViewCommandHandler.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ui/OpenConnectionViewCommandHandler.java Mon Feb 01 13:56:52 2010 -0600 @@ -0,0 +1,46 @@ +/* +* 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" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +package com.nokia.carbide.remoteconnections.internal.ui; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.ui.PartInitException; + +import com.nokia.carbide.remoteconnections.Messages; +import com.nokia.carbide.remoteconnections.view.ConnectionsView; +import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils; + +/** + * + */ +public class OpenConnectionViewCommandHandler extends AbstractHandler { + + /* (non-Javadoc) + * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) + */ + public Object execute(ExecutionEvent event) throws ExecutionException { + try { + WorkbenchUtils.getView(ConnectionsView.VIEW_ID); + } catch (PartInitException e) { + throw new ExecutionException(Messages.getString("OpenConnectionViewCommandHandler_FailedToOpenMsg"), e); //$NON-NLS-1$ + } + return null; + } + +} diff -r 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/messages.properties Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/settings/ui/ConnectionSettingsPage.java Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/settings/ui/ConnectionTypePage.java Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/settings/ui/OnDeviceConnectionAction.java Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/settings/ui/SettingsWizard.java Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/ui/ClientServiceSiteUI.java Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/view/ConnectionsView.java Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/wizard/ExportPage.java Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/wizard/ImportPage.java Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/wizard/ImportWizard.java Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/api/sdk/SymbianBuildContext.java --- a/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/api/sdk/SymbianBuildContext.java Mon Feb 01 13:55:02 2010 -0600 +++ b/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/api/sdk/SymbianBuildContext.java Mon Feb 01 13:56:52 2010 -0600 @@ -398,9 +398,12 @@ } if (prefixFile != null) { - + + List systemPaths = new ArrayList(); + // Always add epoc32/include to the search path as this is implicit for includes in the HRH + systemPaths.add(new File(getSDK().getEPOCROOT() + "epoc32/include")); + // add any BSF/SBV includes so the headers are picked up from the correct location - List systemPaths = new ArrayList(); IBSFPlatform bsfPlat = getSDK().getBSFCatalog().findPlatform(platform); ISBVPlatform sbvPlat = getSDK().getSBVCatalog().findPlatform(platform); if (bsfPlat != null) { diff -r 76faf0501c89 -r c0a17ff7c85f core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/sdk/core/model/SymbianSDK.java --- a/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/sdk/core/model/SymbianSDK.java Mon Feb 01 13:55:02 2010 -0600 +++ b/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/sdk/core/model/SymbianSDK.java Mon Feb 01 13:56:52 2010 -0600 @@ -192,9 +192,16 @@ public String getFamily() { String[] parts = getName().split("\\."); - if (parts.length == 3) - return parts[2]; - + if (parts.length == 3){ + if (getSDKVersion().getMajor() == 5 && getName().equalsIgnoreCase(NOKIA_SF_SDK_NAME)){ + // A vendor of "symbian" and SDK major version 5 is the same as prior naming for "com.nokia.s60" & 5th Edition. + // Return "s60" so that project template generation continues to work as it's a S60 5th ed. SDK. + return ISymbianSDK.S60_FAMILY_ID; + } else { + return parts[2]; + } + } + return ""; } diff -r 76faf0501c89 -r c0a17ff7c85f core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/sdk/core/ISymbianSDK.java --- a/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/sdk/core/ISymbianSDK.java Mon Feb 01 13:55:02 2010 -0600 +++ b/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/sdk/core/ISymbianSDK.java Mon Feb 01 13:56:52 2010 -0600 @@ -48,10 +48,12 @@ public static final String S80_FAMILY_ID = "Series80"; public static final String UIQ_FAMILY_ID = "UIQ"; public static final String TECHVIEW_FAMILY_ID = "TechView"; + public static final String SYMBIAN_FOUNDATION_FAMILY_ID = "symbian"; // Symbian Foundation, starting with Symbian^3 // Unique Ids include the vendor public static final String SERIES60_SDK_NAME = "com.nokia." + SERIES60_FAMILY_ID; public static final String S60_SDK_NAME = "com.nokia." + S60_FAMILY_ID; + public static final String NOKIA_SF_SDK_NAME = "com.nokia." + SYMBIAN_FOUNDATION_FAMILY_ID; // Nokia+Symbian Foundation SDK public static final String S80_SDK_NAME = "com.nokia." + S80_FAMILY_ID; public static final String UIQ_SDK_NAME = "com.symbian." + UIQ_FAMILY_ID; public static final String TECHVIEW_SDK_NAME = "com.symbian." + TECHVIEW_FAMILY_ID; diff -r 76faf0501c89 -r c0a17ff7c85f core/com.nokia.carbide.cpp.sdk.ui/src/com/nokia/carbide/cpp/internal/api/sdk/ui/TemplateUtils.java --- a/core/com.nokia.carbide.cpp.sdk.ui/src/com/nokia/carbide/cpp/internal/api/sdk/ui/TemplateUtils.java Mon Feb 01 13:55:02 2010 -0600 +++ b/core/com.nokia.carbide.cpp.sdk.ui/src/com/nokia/carbide/cpp/internal/api/sdk/ui/TemplateUtils.java Mon Feb 01 13:56:52 2010 -0600 @@ -50,7 +50,7 @@ */ public static boolean sdkMatchesTemplate(ISymbianSDK symbianSDK, ITemplate template) { Version sdkVersion = symbianSDK.getSDKVersion(); - String family = symbianSDK.getFamily(); // ??? is this S60, UIQ, etc. ??? + String family = symbianSDK.getFamily(); // S60, symbian... 3rd segment of devices.xml 'name' attrib return sdkMatchesTemplate(sdkVersion, family, template); } diff -r 76faf0501c89 -r c0a17ff7c85f core/com.nokia.cpp.utils.core/src/com/nokia/cpp/internal/api/utils/core/HostOS.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/com.nokia.cpp.utils.core/src/com/nokia/cpp/internal/api/utils/core/HostOS.java Mon Feb 01 13:56:52 2010 -0600 @@ -0,0 +1,81 @@ +/* +* 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" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +package com.nokia.cpp.internal.api.utils.core; + +import java.io.File; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; + + +/** + * Utilities used for portability between hosts. + *

+ * NOTE: please keep this in sync with the org.eclipse.cdt.debug.edc version of this class! + */ +public class HostOS { + /** Is the host Windows? */ + public static boolean IS_WIN32 = File.separatorChar == '\\'; + /** Is the host some Unix variant? */ + public static boolean IS_UNIX = File.separatorChar == '/'; + /** Executable file extension */ + public static final String EXE_EXT = IS_WIN32 ? ".exe" : ""; + + /** + * Ensure that the executable name mentioned is canonical for the machine. + * This only affects Windows, currently, ensuring that an ".exe" is attached. + * @param executablePath + * @return updated path + */ + public static String canonicalizeExecutableName(String executable) { + if (IS_WIN32) { + IPath executablePath = new Path(executable); + String ext = executablePath.getFileExtension(); + if (ext == null) { + executable += EXE_EXT; + } + } + return executable; + } + + /** + * Scan the PATH variable and see if the given binary is visible on + * the PATH that will be used at runtime (with the default environment and overrides). + * @param pathValue the expected Path + * @param program + * @return IPath if program is on PATH, else null + */ + public static IPath findProgramOnPath(String program, String pathValue) { + + // be sure proper path/extension are present + program = HostOS.canonicalizeExecutableName(program); + + IPath path = null; + + IPath[] pathEntries = PathUtils.getPathEntries(pathValue); + for (IPath pathEntry : pathEntries) { + IPath testPath = pathEntry.append(program); + if (testPath.toFile().exists()) { + path = testPath; + break; + } + } + + return path; + } +} diff -r 76faf0501c89 -r c0a17ff7c85f core/com.nokia.cpp.utils.core/src/com/nokia/cpp/internal/api/utils/core/PathUtils.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/com.nokia.cpp.utils.core/src/com/nokia/cpp/internal/api/utils/core/PathUtils.java Mon Feb 01 13:56:52 2010 -0600 @@ -0,0 +1,272 @@ +/* +* 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" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +package com.nokia.cpp.internal.api.utils.core; + +import java.io.File; +import java.io.FilenameFilter; +import java.io.IOException; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; + +/** + * These utilities handle some common portability issues when dealing with + * (absolute) paths which may be in a format intended for another operating system. + * It also handles shortcomings in the org.eclipse.core.runtime.Path + * implementation, which is not able to construct a meaningful path from + * a Win32 path outside of Windows. + *

+ * NOTE: please keep this in sync with the org.eclipse.cdt.debug.edc version of this class! + */ +public class PathUtils { + + /** + * Convert a variable constructed blindly for a Win32 environment into + * Unix-like syntax. This is typically used for PATH or lists + * of paths where ';' is the entry separator and '\' is the + * path component separator. + *

+ * NOTE: we assume that the entries in the + * path list are already legal Unix paths, but just with the + * wrong slash. + * @param env + * @return converted string + */ + public static String convertPathListToUnix(String env) { + if (env == null) return null; + env = env.replaceAll(";", ":"); // entry separators + env = env.replaceAll("\\\\", "/"); // path separators + return env; + } + + /** + * Convert a path constructed blindly for a Win32 environment into + * Unix-like syntax.

+ * NOTE: we assume that the path is already a legal Unix path, + * but just with the wrong slash. + * @param file + * @return converted string + */ + public static String convertPathToUnix(String file) { + if (file == null) return null; + // handle Windows slashes and canonicalize + file = file.replaceAll("\\\\", "/"); + return file; + } + + /** + * Convert a path which may be in Windows or Unix format to Windows format. + * NOTE: we assume that the path is already a legal path, + * but just with the wrong slash. + * @param file + * @return converted string + */ + public static String convertPathToWindows(String file) { + if (file == null) return null; + file = file.replaceAll("/", "\\\\"); + return file; + } + + /** + * Convert a path which may be in Windows or Unix format to Windows format. + * NOTE: we assume that the path is already a legal path, + * but just with the wrong slash. + * @param file + * @return converted string + */ + public static String convertPathToWindows(IPath path) { + return convertPathToWindows(path.toPortableString()); + } + + /** + * Convert a path which may be in the opposite slash format to the local slash format. + * NOTE: we assume that the path is already a legal path, + * but just with the wrong slash. + * @param file + * @return converted string + */ + public static String convertPathToNative(String path) { + if (path == null) return null; + if (HostOS.IS_UNIX) + return path.replaceAll("\\\\", "/"); + else + return path.replaceAll("/", "\\\\"); + } + + /** + * Create an IPath from a string which may be a Win32 path.

+ *

+ * ("new Path(...)" won't work in Unix when using a Win32 path: the backslash + * separator and the device notation are completely munged.) + * @param path + * @return converted string + */ + public static IPath createPath(String path) { + if (path == null) return null; + if (path.contains("\\")) { + // handle Windows slashes and canonicalize + path = path.replaceAll("\\\\", "/"); + } + + // also check for device or UNC + int idx = path.indexOf(":"); + if (idx > 0) { + String device = path.substring(0, idx + 1); + path = path.substring(idx + 1); + return new Path(path).setDevice(device); + } + else { + // Cygwin or UNC path + if (path.startsWith("//")) { + String network; + idx = path.indexOf("/", 2); + if (idx > 0) { + network = path.substring(0, idx); + path = path.substring(idx); + } else { + network = path; + path = ""; + } + return new Path(network, path).makeUNC(true); + } + } + + // fallthrough + return new Path(path); + } + + /** + * Get the PATH entries from the given path environment value or the + * system environment. + * @param pathValue the expected PATH/Path value, or null for the system value + * @return array of IPath, never null + */ + public static IPath[] getPathEntries(String pathValue) { + String pathVar = null; + if (pathValue != null) { + pathVar = pathValue; + } else { + if (HostOS.IS_WIN32) { + // canonical name, plus fallback below + pathVar = System.getenv("Path"); //$NON-NLS-1$ + } + if (pathVar == null) { + pathVar = System.getenv("PATH"); //$NON-NLS-1$ + } + } + + if (pathVar == null) + pathVar = ""; + + String pathSeparator = System.getProperty("path.separator"); + String[] pathEntries = pathVar.split(pathSeparator); + IPath[] paths = new IPath[pathEntries.length]; + for (int i = 0; i < pathEntries.length; i++) { + paths[i] = new Path(pathEntries[i]); + } + return paths; + } + + /** + * If the filesystem is case sensitive, locate the file on the filesystem + * on the given path, by ignoring case sensitivity differences. + * This is needed on case-preserving but not case-insensitive filesystems. + * @param path + * @return path pointing to existing file (possibly with different case in components) or + * original path if there is no match + */ + public static IPath findExistingPathIfCaseSensitive(IPath path) { + // case is insensitive already + if (HostOS.IS_WIN32) + return path; + + if (path == null || !path.isAbsolute()) + return path; + + File pathFile = path.toFile(); + if (pathFile.exists()) { + try { + return new Path(pathFile.getCanonicalPath()); + } catch (IOException e) { + // should not happen + return path; + } + } + + + // start with the assumption that the path is mostly correct except for the + // last N segments. + IPath goodPath = Path.ROOT; + if (path.getDevice() != null) + goodPath = goodPath.setDevice(path.getDevice()); + + // if bad drive or no root (?!), just skip + if (!goodPath.toFile().exists()) + return path; + + for (int seg = path.segmentCount(); seg > 0; seg--) { + final IPath prefix = path.uptoSegment(seg - 1); + + if (prefix.toFile().exists()) { + goodPath = prefix; + break; + } + } + + StringBuilder builder = new StringBuilder(); + + builder.append(goodPath.addTrailingSeparator().toOSString()); + + boolean failedLookup = false; + + for (int seg = goodPath.segmentCount(); seg < path.segmentCount(); seg++) { + final String segment = path.segment(seg); + + final String[] matches = { segment }; + + if (!failedLookup) { + File dir = new File(builder.toString()); + if (!new File(dir, matches[0]).exists()) { + // component has wrong case; find the first one matching case-insensitively + String[] names = dir.list(new FilenameFilter() { + + public boolean accept(File dir, String name) { + if (name.equalsIgnoreCase(segment)) { + matches[0] = name; + return true; + } + return false; + } + }); + + if (names.length == 0) { + // no matches! the rest of the path won't match either + failedLookup = true; + } + } + } + builder.append(matches[0]); + builder.append('/'); + } + + if (!path.hasTrailingSeparator() && builder.length() > 0 && builder.charAt(builder.length() - 1) == '/') { + builder.setLength(builder.length() - 1); + } + return new Path(builder.toString()); + } +} diff -r 76faf0501c89 -r c0a17ff7c85f core/com.nokia.cpp.utils.ui/src/com/nokia/cpp/internal/api/utils/ui/BrowseDialogUtils.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/com.nokia.cpp.utils.ui/src/com/nokia/cpp/internal/api/utils/ui/BrowseDialogUtils.java Mon Feb 01 13:56:52 2010 -0600 @@ -0,0 +1,183 @@ +/* +* 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" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +package com.nokia.cpp.internal.api.utils.ui; + +import java.io.File; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Text; + +/** + * Utilities to make it easier to use file and directory dialogs which are associated + * with text entry fields. + *

+ * First, promote UI where Browse... starts from the current textual entry rather than + * some random place. + *

+ * Second, overcome terrible SWT behavior: even if you do set the filter path, then if it + * is not 100% correct, it will again revert to the home directory. So, find the nearest + * directory that does exist. + */ +public class BrowseDialogUtils { + /** + * When issuing a "Browse..." command next to a text entry field, initialize + * the dialog with the nearest existing file or directory in that text field. + * @param dialog + * @param textEntry + * @pathm defaultPath the path to use when the text entry is empty + */ + public static void initializeFrom(FileDialog dialog, Text textEntry, IPath defaultPath) { + if (textEntry != null) { + String existing = textEntry.getText().trim(); + if (existing.length() > 0) { + initializeFrom(dialog, existing); + return; + } + } + if (defaultPath != null) { + initializeFrom(dialog, defaultPath); + } + } + + /** + * When issuing a "Browse..." command next to a text entry field, initialize + * the dialog with the nearest existing file or directory in that text field. + * @param dialog + * @param textEntry + */ + public static void initializeFrom(FileDialog dialog, Text textEntry) { + if (textEntry == null) + return; + String existing = textEntry.getText().trim(); + initializeFrom(dialog, existing); + } + + /** + * When issuing a "Browse..." command with an expected file, initialize + * the dialog with the nearest existing file or directory. + * @param dialog + * @param path + */ + public static void initializeFrom(FileDialog dialog, IPath path) { + if (path != null) { + initializeFrom(dialog, path.toOSString()); + } + } + + /** + * When issuing a "Browse..." command with an expected file, initialize + * the dialog with the nearest existing file or directory. + * @param dialog + * @param path + */ + public static void initializeFrom(FileDialog dialog, String path) { + if (path != null && path.length() > 0) { + boolean isDirectory = path.endsWith("/") || path.endsWith("\\"); + File file = new File(path); + boolean exists = file.exists(); + if (exists) { + isDirectory = file.isDirectory(); + } + if (!isDirectory) { + dialog.setFileName(file.getName()); + } + if (exists) { + if (file.isAbsolute()) { + dialog.setFilterPath(isDirectory ? file.getAbsolutePath() : file.getParent()); + } + } else { + if (!file.isAbsolute()) + return; + File dir = file.getParentFile(); + while (dir != null && !dir.exists()) { + dir = dir.getParentFile(); + } + if (dir != null) { + dialog.setFilterPath(dir.getAbsolutePath()); + } + } + } + } + + /** + * When issuing a "Browse..." command next to a text entry field, initialize + * the dialog with the nearest existing directory in that text field. + * @param dialog + * @param textEntry + * @param defaultPath the default path if the text entry is empty + */ + public static void initializeFrom(DirectoryDialog dialog, Text textEntry, IPath defaultPath) { + if (textEntry != null) { + String existing = textEntry.getText().trim(); + if (existing.length() > 0) { + initializeFrom(dialog, existing); + return; + } + } + if (defaultPath != null) { + initializeFrom(dialog, defaultPath); + } + } + + /** + * When issuing a "Browse..." command next to a text entry field, initialize + * the dialog with the nearest existing directory in that text field. + * @param dialog + * @param textEntry + */ + public static void initializeFrom(DirectoryDialog dialog, Text textEntry) { + if (textEntry == null) + return; + String existing = textEntry.getText().trim(); + initializeFrom(dialog, existing); + } + + /** + * When issuing a "Browse..." command with an expected directory, initialize + * the dialog with the nearest existing path. + * @param dialog + * @param path + */ + public static void initializeFrom(DirectoryDialog dialog, IPath path) { + if (path != null) { + initializeFrom(dialog, path.toOSString()); + } + } + + /** + * When issuing a "Browse..." command with an expected directory, initialize + * the dialog with the nearest existing path. + * @param dialog + * @param path + */ + public static void initializeFrom(DirectoryDialog dialog, String path) { + if (path != null && path.length() > 0) { + File file = new File(path); + if (!file.isAbsolute()) + return; + while (file != null && !file.exists()) { + file = file.getParentFile(); + } + if (file != null) { + dialog.setFilterPath(file.getAbsolutePath()); + } + } + } +} diff -r 76faf0501c89 -r c0a17ff7c85f debuggercdi/com.nokia.carbide.trk.support/META-INF/MANIFEST.MF --- a/debuggercdi/com.nokia.carbide.trk.support/META-INF/MANIFEST.MF Mon Feb 01 13:55:02 2010 -0600 +++ b/debuggercdi/com.nokia.carbide.trk.support/META-INF/MANIFEST.MF Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/debuggercdi/com.nokia.carbide.trk.support/src/com/nokia/carbide/trk/support/Activator.java Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/debuggercdi/com.nokia.carbide.trk.support/src/com/nokia/carbide/trk/support/messages.properties Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/debuggercdi/com.nokia.carbide.trk.support/src/com/nokia/carbide/trk/support/service/ConnectedServiceFactory.java Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f debuggercdi/com.nokia.carbide.trk.support/src/com/nokia/carbide/trk/support/service/RemoteConnectedService.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debuggercdi/com.nokia.carbide.trk.support/src/com/nokia/carbide/trk/support/service/RemoteConnectedService.java Mon Feb 01 13:56:52 2010 -0600 @@ -0,0 +1,136 @@ +/* +* Copyright (c) 2008 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" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +package com.nokia.carbide.trk.support.service; + +import org.osgi.framework.Version; + +import com.nokia.carbide.remoteconnections.Messages; +import com.nokia.carbide.remoteconnections.interfaces.IConnectedService; +import com.nokia.carbide.remoteconnections.interfaces.IService; +import com.nokia.cpp.internal.api.utils.core.IListenerFiring; +import com.nokia.cpp.internal.api.utils.core.ListenerList; + +/** + * This is a stub for the TRK and Trace connected services used when the host + * does not support Chad's TCF. This reconciles the fact that a TRK connection publishes + * these services, but we cannot actually instantiate them. + *

+ * In the future this should find a way to talk to the device over Eclipse TCF or something. + */ +public class RemoteConnectedService implements IConnectedService { + + private boolean enabled = true; + private final IService service; + private IStatus unknownStatus = new IStatus() { + + public IConnectedService getConnectedService() { + return RemoteConnectedService.this; + } + + public EStatus getEStatus() { + return EStatus.UNKNOWN; + } + + public String getLongDescription() { + return "The device is connected remotely; testing not yet implemented."; + } + + public String getShortDescription() { + return "Unknown"; + } + + }; + + private IStatus noStatus = new IStatus() { + + public IConnectedService getConnectedService() { + return RemoteConnectedService.this; + } + + public EStatus getEStatus() { + return EStatus.UNKNOWN; + } + + public String getLongDescription() { + return Messages.getString("AbstractConnectedService.UserDisabledMessage"); + } + + public String getShortDescription() { + return Messages.getString("AbstractConnectedService.NoTestingLabel"); + } + + }; + private ListenerList listeners; + private IStatus currentStatus; + /** + * + */ + public RemoteConnectedService(IService service) { + this.service = service; + listeners = new ListenerList(); + currentStatus = noStatus; + } + public void addStatusChangedListener(IStatusChangedListener listener) { + listeners.add(listener); + } + + public void dispose() { + } + + public IService getService() { + return service; + } + + public IStatus getStatus() { + return currentStatus; + } + + public void removeStatusChangedListener(IStatusChangedListener listener) { + listeners.remove(listener); + } + + public void testStatus() { + } + + public void setDeviceOS(String familyName, Version version) { + } + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + + currentStatus = enabled ? unknownStatus : noStatus; + + fireListeners(); + } + /** + * + */ + private void fireListeners() { + listeners.fireListeners(new IListenerFiring() { + + public void fire(IStatusChangedListener listener) { + listener.statusChanged(getStatus()); + } + }); + } +} diff -r 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/debuggercdi/com.nokia.carbide.trk.support/src/com/nokia/carbide/trk/support/service/TRKConnectedService.java Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/debuggercdi/com.nokia.carbide.trk.support/src/com/nokia/carbide/trk/support/service/TRKService.java Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/debuggercdi/com.nokia.carbide.trk.support/src/com/nokia/carbide/trk/support/service/TracingService.java Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f debuggercdi/com.nokia.carbide.trk.support/src/com/nokia/carbide/trk/support/status/ConnectionStatusReconciler.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debuggercdi/com.nokia.carbide.trk.support/src/com/nokia/carbide/trk/support/status/ConnectionStatusReconciler.java Mon Feb 01 13:56:52 2010 -0600 @@ -0,0 +1,290 @@ +/** +* Copyright (c) 2010 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" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +package com.nokia.carbide.trk.support.status; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.ui.PartInitException; + +import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; +import com.nokia.carbide.remoteconnections.interfaces.IConnectedService; +import com.nokia.carbide.remoteconnections.interfaces.IConnection; +import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager; +import com.nokia.carbide.remoteconnections.interfaces.AbstractConnection.ConnectionStatus; +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.internal.api.IConnection2; +import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus; +import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus.EConnectionStatus; +import com.nokia.carbide.trk.support.Messages; +import com.nokia.carbide.trk.support.connection.USBConnectionType; +import com.nokia.carbide.trk.support.service.TRKConnectedService; +import com.nokia.carbide.trk.support.service.TracingConnectedService; +import com.nokia.cpp.internal.api.utils.ui.RunRunnableWhenWorkbenchVisibleJob; +import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils; + +/** + * A singleton object that manages the device status of dynamic connections + * based on the status of the TRK and Tracing services. + */ +public class ConnectionStatusReconciler { + + private static final String CONNECTIONS_VIEW_ID = + "com.nokia.carbide.remoteconnections.view.ConnectionsView"; //$NON-NLS-1$ + + private class ConnectionListener implements IConnectionListener { + + public void connectionAdded(IConnection connection) { + addConnection(connection); + } + + public void connectionRemoved(IConnection connection) { + if (connection.equals(userSetCurrentConnection)) + userSetCurrentConnection = null; + removeConnection(connection); + } + + public void currentConnectionSet(IConnection connection) { + if (connection != null && !connection.equals(reconcilerSetCurrentConnection)) + userSetCurrentConnection = connection; + } + + } + + private class ServiceStatusListener implements IStatusChangedListener { + + public void statusChanged(IStatus status) { + handleServiceStatusChange(status); + } + + } + + private static ConnectionStatusReconciler instance; + private IConnectionsManager manager; + private IConnectionListener connectionListener; + private List handledConnections; + private ServiceStatusListener serviceStatusListener; + private IConnection reconcilerSetCurrentConnection; + private IConnection userSetCurrentConnection; + + private ConnectionStatusReconciler() { + connectionListener = new ConnectionListener(); + manager = RemoteConnectionsActivator.getConnectionsManager(); + manager.addConnectionListener(connectionListener); + handledConnections = new ArrayList(); + serviceStatusListener = new ServiceStatusListener(); + } + + public static ConnectionStatusReconciler getInstance() { + if (instance == null) + instance = new ConnectionStatusReconciler(); + + return instance; + } + + public void dispose() { + manager.removeConnectionListener(connectionListener); + for (IConnection connection : new ArrayList(handledConnections)) { + removeConnection(connection); + } + } + + private boolean isDynamic(IConnection connection) { + return connection instanceof IConnection2 && ((IConnection2) connection).isDynamic(); + } + + private boolean isSysTRK(TRKConnectedService service) { + String value = service.getProperties().get(TRKConnectedService.PROP_SYS_TRK); + return Boolean.parseBoolean(value); + } + + private void addConnection(IConnection connection) { + handledConnections.add(connection); + for (IConnectedService service : manager.getConnectedServices(connection)) { + if (service instanceof TRKConnectedService || + service instanceof TracingConnectedService) { + service.addStatusChangedListener(serviceStatusListener); + } + } + showConnectionsView(); + } + + private void showConnectionsView() { + RunRunnableWhenWorkbenchVisibleJob.start(new Runnable() { + public void run() { + // try to show the connections view to start service testers + try { + WorkbenchUtils.getView(CONNECTIONS_VIEW_ID); + } catch (PartInitException e) { + } + } + }); + } + + private void reconcileAsCurrent(IConnection connection) { + if (canBeSetToCurrent(connection)) { + if (isReady(connection)) { // set as current + reconcilerSetCurrentConnection = connection; + manager.setCurrentConnection(connection); + } else if (isNotReady(connection) && connection.equals(manager.getCurrentConnection())) { + // unset current or set something else current + if (isDynamic(connection) && userSetCurrentConnection != null) { + manager.setCurrentConnection(userSetCurrentConnection); + } + else { + // look for some other existing connection that is ready + for (IConnection c : manager.getConnections()) { + if (canBeSetToCurrent(c) && isReady(c)) { + reconcilerSetCurrentConnection = connection; + manager.setCurrentConnection(connection); + return; + } + } + // set to no current connection + manager.setCurrentConnection(null); + } + } + } + } + + private boolean isReady(IConnection connection) { + return equalsConnectionStatus(connection, EConnectionStatus.READY); + } + + private boolean isNotReady(IConnection connection) { + return equalsConnectionStatus(connection, EConnectionStatus.NOT_READY); + } + + private boolean equalsConnectionStatus(IConnection connection, EConnectionStatus status) { + if (connection instanceof IConnection2) { + IConnectionStatus connectionStatus = ((IConnection2) connection).getStatus(); + if (connectionStatus != null) + return connectionStatus.getEConnectionStatus().equals(status); + } + return false; + } + + private boolean canBeSetToCurrent(IConnection connection) { + // USB connections for now + return USBConnectionType.ID.equals(connection.getConnectionType().getIdentifier()); + } + + private void reconcileStatus(IConnection connection) { + if (!isDynamic(connection)) // don't set status for user generated connections + return; + + boolean isSysTRK = false; + EStatus trkStatus = EStatus.UNKNOWN; + EStatus traceStatus = EStatus.UNKNOWN; + for (IConnectedService service : manager.getConnectedServices(connection)) { + if (service instanceof TRKConnectedService) { + isSysTRK = isSysTRK((TRKConnectedService) service); + trkStatus = service.getStatus().getEStatus(); + } + if (service instanceof TracingConnectedService) { + traceStatus = service.getStatus().getEStatus(); + } + } + setConnectionStatus((IConnection2) connection, isSysTRK, trkStatus, traceStatus); + } + + private void setConnectionStatus(IConnection2 connection, boolean isSysTRK, EStatus trkStatus, EStatus traceStatus) { + // use trk status + EConnectionStatus connectionStatus = service2ConnectionStatus(trkStatus); + // if sys trk, tracing also used + if (isSysTRK && connectionStatus.equals(EConnectionStatus.READY)) { + connectionStatus = service2ConnectionStatus(traceStatus); + } + + String shortDesc = getShortDescriptionForStatus(connectionStatus); + StringBuilder longDesc = new StringBuilder(Messages.getString("ConnectionStatusReconciler_TRKServicePrefix")); //$NON-NLS-1$ + longDesc.append(getServiceStatusString(trkStatus)); + if (isSysTRK) { + longDesc.append(Messages.getString("ConnectionStatusReconciler_TracingServicePrefix")); //$NON-NLS-1$ + longDesc.append(getServiceStatusString(traceStatus)); + } + + connection.setStatus(new ConnectionStatus(connectionStatus, shortDesc, longDesc.toString())); + } + + private String getShortDescriptionForStatus(EConnectionStatus connectionStatus) { + switch (connectionStatus) { + case READY: + return Messages.getString("ConnectionStatusReconciler_ReadyLabel"); //$NON-NLS-1$ + case NOT_READY: + return Messages.getString("ConnectionStatusReconciler_NotReadyLabel"); //$NON-NLS-1$ + case IN_USE: + return Messages.getString("ConnectionStatusReconciler_InUseLabel"); //$NON-NLS-1$ + case IN_USE_DISCONNECTED: + return Messages.getString("ConnectionStatusReconciler_DisconnectedLabel"); //$NON-NLS-1$ + } + return ""; //$NON-NLS-1$ + } + + private String getServiceStatusString(EStatus status) { + switch (status) { + case UP: + return Messages.getString("ConnectionStatusReconciler_availableLabel"); //$NON-NLS-1$ + case DOWN: + return Messages.getString("ConnectionStatusReconciler_unavailableLabel"); //$NON-NLS-1$ + case IN_USE: + return Messages.getString("ConnectionStatusReconciler_inUseLabel_lower"); //$NON-NLS-1$ + } + return ""; //$NON-NLS-1$ + } + + private EConnectionStatus service2ConnectionStatus(EStatus serviceStatus) { + switch (serviceStatus) { + case UP: + return EConnectionStatus.READY; + case DOWN: + return EConnectionStatus.NOT_READY; + case IN_USE: + return EConnectionStatus.IN_USE; + } + return EConnectionStatus.NONE; + } + + private void removeConnection(IConnection connection) { + handledConnections.remove(connection); + } + + private IConnection findConnection(IConnectedService cs) { + for (IConnection connection : handledConnections) { + for (IConnectedService connectedService : manager.getConnectedServices(connection)) { + if (cs.equals(connectedService)) + return connection; + } + } + return null; + } + + public void handleServiceStatusChange(IStatus status) { + IConnectedService service = status.getConnectedService(); + IConnection connection = findConnection(service); + if (connection instanceof IConnection2) { + reconcileStatus((IConnection2) connection); + } + if (connection != null) + reconcileAsCurrent(connection); + } + +} diff -r 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/AttachLaunchDelegate.java Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/LaunchPlugin.java Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/TRKLaunchDelegate.java Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/ui/AttachMainTab.java Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/ui/RunModeMainTab.java Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/ui/messages.properties Mon Feb 01 13:56:52 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 76faf0501c89 -r c0a17ff7c85f 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 13:55:02 2010 -0600 +++ b/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/wizard/TRKConnectionWizardPage.java Mon Feb 01 13:56:52 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(); } } diff -r 76faf0501c89 -r c0a17ff7c85f project/com.nokia.carbide.cpp.epoc.engine/src/com/nokia/carbide/cpp/epoc/engine/model/mmp/EMMPStatement.java --- a/project/com.nokia.carbide.cpp.epoc.engine/src/com/nokia/carbide/cpp/epoc/engine/model/mmp/EMMPStatement.java Mon Feb 01 13:55:02 2010 -0600 +++ b/project/com.nokia.carbide.cpp.epoc.engine/src/com/nokia/carbide/cpp/epoc/engine/model/mmp/EMMPStatement.java Mon Feb 01 13:56:52 2010 -0600 @@ -76,6 +76,12 @@ */ FEATUREVARIANT("FEATUREVARIANT", IMMPParserConfiguration.FLAG_STATEMENT), //$NON-NLS-1$ + /** + * @since 2.5 - Added with Symbian^3 + */ + STDCPP("STDCPP", IMMPParserConfiguration.FLAG_STATEMENT), //$NON-NLS-1$ + NOSTDCPP("NOSTDCPP", IMMPParserConfiguration.FLAG_STATEMENT), //$NON-NLS-1$ + HEADER("HEADER", IMMPParserConfiguration.FLAG_STATEMENT, "RESOURCE|BITMAP"), //$NON-NLS-1$ //$NON-NLS-2$ HEADERONLY("HEADERONLY", IMMPParserConfiguration.FLAG_STATEMENT, "RESOURCE|BITMAP"), //$NON-NLS-1$ //$NON-NLS-2$