14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 package com.nokia.cdt.internal.debug.launch.ui; |
17 package com.nokia.cdt.internal.debug.launch.ui; |
18 |
18 |
|
19 import java.util.Collection; |
|
20 import java.util.HashMap; |
|
21 import java.util.Map; |
|
22 |
19 import org.eclipse.core.runtime.CoreException; |
23 import org.eclipse.core.runtime.CoreException; |
20 import org.eclipse.debug.core.ILaunchConfiguration; |
24 import org.eclipse.debug.core.ILaunchConfiguration; |
21 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; |
25 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; |
22 import org.eclipse.swt.SWT; |
26 import org.eclipse.swt.SWT; |
23 import org.eclipse.swt.layout.GridLayout; |
27 import org.eclipse.swt.layout.GridLayout; |
26 import com.freescale.cdt.debug.cw.core.RemoteConnectionsTRKHelper; |
30 import com.freescale.cdt.debug.cw.core.RemoteConnectionsTRKHelper; |
27 import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; |
31 import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; |
28 import com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI2; |
32 import com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI2; |
29 import com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI2.IListener; |
33 import com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI2.IListener; |
30 import com.nokia.carbide.remoteconnections.interfaces.IConnection; |
34 import com.nokia.carbide.remoteconnections.interfaces.IConnection; |
|
35 import com.nokia.carbide.remoteconnections.interfaces.IConnectionFactory; |
|
36 import com.nokia.carbide.remoteconnections.interfaces.IConnectionType; |
31 import com.nokia.cdt.internal.debug.launch.LaunchPlugin; |
37 import com.nokia.cdt.internal.debug.launch.LaunchPlugin; |
32 |
38 |
33 public class StopModeMainTab extends CarbideMainTab { |
39 public class StopModeMainTab extends CarbideMainTab { |
34 |
40 |
35 protected IClientServiceSiteUI2 clientSiteUI; |
41 protected IClientServiceSiteUI2 clientSiteUI; |
36 protected String connection; |
42 protected String connection; |
37 |
43 |
|
44 // PlatSim settings keys |
|
45 private final static String SETTING_LOCATION = "location"; //$NON-NLS-1$ |
|
46 private final static String SETTING_INSTANCE = "instance"; //$NON-NLS-1$ |
|
47 |
|
48 private static String PLATSIM_CONNECTION_TYPE = "com.nokia.carbide.trk.support.connection.PlatSimConnectionType"; //$NON-NLS-1$ |
|
49 |
38 public void createControl(Composite parent) { |
50 public void createControl(Composite parent) { |
39 Composite comp = new Composite(parent, SWT.NONE); |
51 Composite comp = new Composite(parent, SWT.NONE); |
40 setControl(comp); |
52 setControl(comp); |
41 |
53 |
42 LaunchPlugin.getDefault().getWorkbench().getHelpSystem().setHelp(getControl(), LaunchTabHelpIds.STOP_MODE_MAIN); |
54 LaunchPlugin.getDefault().getWorkbench().getHelpSystem().setHelp(getControl(), LaunchTabHelpIds.STOP_MODE_MAIN); |
102 |
114 |
103 ILaunchConfigurationWorkingCopy wcConfig = (ILaunchConfigurationWorkingCopy)config; |
115 ILaunchConfigurationWorkingCopy wcConfig = (ILaunchConfigurationWorkingCopy)config; |
104 |
116 |
105 // if an existing PlatSim connection matches, then use it |
117 // if an existing PlatSim connection matches, then use it |
106 // if no connection matches, then create a new one |
118 // if no connection matches, then create a new one |
107 IConnection connectionToUse = RemoteConnectionsTRKHelper.findOrCreatePlatSimConnection(location, instanceId); |
119 IConnection connectionToUse = findOrCreatePlatSimConnection(location, instanceId); |
108 connection = connectionToUse.getIdentifier(); |
120 connection = connectionToUse.getIdentifier(); |
109 if (connection != null) { |
121 if (connection != null) { |
110 wcConfig.setAttribute(RemoteConnectionsTRKHelper.CONNECTION_ATTRIBUTE, connection); |
122 wcConfig.setAttribute(RemoteConnectionsTRKHelper.CONNECTION_ATTRIBUTE, connection); |
111 } |
123 } |
112 } |
124 } |
136 */ |
148 */ |
137 public boolean isValid(ILaunchConfiguration config) { |
149 public boolean isValid(ILaunchConfiguration config) { |
138 boolean result = super.isValid(config); |
150 boolean result = super.isValid(config); |
139 return result; |
151 return result; |
140 } |
152 } |
|
153 |
|
154 |
|
155 /** |
|
156 * Find a PlatSim connection with the given location and instance, or create one |
|
157 * |
|
158 * @param locationToFind path to PlatSim executable |
|
159 * @param instanceToFind PlatSim instance number |
|
160 * @return |
|
161 */ |
|
162 private IConnection findOrCreatePlatSimConnection(String locationToFind, String instanceToFind) { |
|
163 Collection<IConnection> connections = RemoteConnectionsActivator.getConnectionsManager().getConnections(); |
|
164 IConnection matchingConnection = null; |
|
165 for (IConnection connection : connections) { |
|
166 String connectionTypeId = connection.getConnectionType().getIdentifier(); |
|
167 if (connectionTypeId.equals(PLATSIM_CONNECTION_TYPE)) { |
|
168 Map<String, String> settings = connection.getSettings(); |
|
169 String instance = settings.get(SETTING_INSTANCE); |
|
170 String location = settings.get(SETTING_LOCATION); |
|
171 if (instanceToFind.equals(instance) && locationToFind.equals(location)) { |
|
172 matchingConnection = connection; |
|
173 break; |
|
174 } |
|
175 } |
|
176 } |
|
177 |
|
178 if (matchingConnection == null) { |
|
179 // create a new one |
|
180 IConnectionType connectionType = RemoteConnectionsActivator.getConnectionTypeProvider().getConnectionType(PLATSIM_CONNECTION_TYPE); |
|
181 if (connectionType == null) |
|
182 return null; |
|
183 IConnectionFactory factory = connectionType.getConnectionFactory(); |
|
184 Map<String, String> settings = new HashMap<String, String>(factory.getSettingsFromUI()); |
|
185 settings.put(SETTING_LOCATION, locationToFind); |
|
186 settings.put(SETTING_INSTANCE, instanceToFind); |
|
187 matchingConnection = factory.createConnection(settings); |
|
188 |
|
189 // if location is non-null, see if you can find the brief SDK name |
|
190 // TODO: if we could access PlatSimManager from here, use the following |
|
191 // String preferredName = null; |
|
192 // try { |
|
193 // IPlatSimInstance theInstance = PlatSimManager.INSTANCE.getInstallationInstance( |
|
194 // new Path(locationToFind), Integer.parseInt(instanceToFind)); |
|
195 // preferredName = PlatSimManager.INSTANCE.getPreferredConnectionName(theInstance); |
|
196 // } catch (Exception e) { |
|
197 // // no luck: suggest nothing |
|
198 // } |
|
199 // |
|
200 // if (preferredName == null) { |
|
201 // if (locationToFind.charAt(1) == ':') // Windows drive indicator |
|
202 // preferredName = "PlatSim " + locationToFind.substring(0, 2) + |
|
203 // ", Instance " + instanceToFind; |
|
204 // else |
|
205 // preferredName = "PlatSim Instance " + instanceToFind; |
|
206 // } |
|
207 |
|
208 String preferredName; |
|
209 if (locationToFind.charAt(1) == ':') // Windows drive indicator |
|
210 preferredName = "PlatSim " + locationToFind.substring(0, 2) + |
|
211 ", Instance " + instanceToFind; |
|
212 else |
|
213 preferredName = "PlatSim Instance " + instanceToFind; |
|
214 |
|
215 String newName = preferredName; |
|
216 boolean isUnique = true; |
|
217 long i = 1; |
|
218 do { |
|
219 for (IConnection connection : connections) { |
|
220 if (preferredName.equals(connection.getDisplayName())) { |
|
221 isUnique = false; |
|
222 break; |
|
223 } |
|
224 } |
|
225 |
|
226 if (!isUnique) |
|
227 newName = preferredName + i; |
|
228 } while (!isUnique); |
|
229 |
|
230 matchingConnection.setDisplayName(newName); |
|
231 RemoteConnectionsActivator.getConnectionsManager().addConnection(matchingConnection); |
|
232 } |
|
233 |
|
234 return matchingConnection; |
|
235 } |
|
236 |
141 |
237 |
142 } |
238 } |