186 */ |
186 */ |
187 protected IConnection getActualConnection(String id) { |
187 protected IConnection getActualConnection(String id) { |
188 if (id == null) { |
188 if (id == null) { |
189 return null; |
189 return null; |
190 } |
190 } |
191 if (id.equals(Registry.DEFAULT_CONNECTION_ID)) { |
191 if (id.equals(Registry.CURRENT_CONNECTION_ID)) { |
192 return RemoteConnectionsActivator.getConnectionsManager().getDefaultConnection(); |
192 return RemoteConnectionsActivator.getConnectionsManager().getCurrentConnection(); |
193 } |
193 } |
194 for (IConnection connection : RemoteConnectionsActivator.getConnectionsManager().getConnections()) { |
194 for (IConnection connection : RemoteConnectionsActivator.getConnectionsManager().getConnections()) { |
195 if (connection.getIdentifier().equals(id)) { |
195 if (connection.getIdentifier().equals(id)) { |
196 return connection; |
196 return connection; |
197 } |
197 } |
199 return null; |
199 return null; |
200 } |
200 } |
201 |
201 |
202 /** |
202 /** |
203 * Set the selected input. |
203 * Set the selected input. |
204 * @param connection existing connection or <code>null</code> for the default |
204 * @param connection existing connection or <code>null</code> for the current |
205 */ |
205 */ |
206 private void setViewerInput(IConnection connection) { |
206 private void setViewerInput(IConnection connection) { |
207 List<IConnection> compatible = getCompatibleConnections(); |
207 List<IConnection> compatible = getCompatibleConnections(); |
208 connectionNames = new LinkedHashMap<String, String>(); |
208 connectionNames = new LinkedHashMap<String, String>(); |
209 |
209 |
210 // update the default |
210 // update the current |
211 IConnection defaultConnection = RemoteConnectionsActivator.getConnectionsManager().getDefaultConnection(); |
211 IConnection currentConnection = RemoteConnectionsActivator.getConnectionsManager().getCurrentConnection(); |
212 |
212 |
213 connectionNames.put(Registry.DEFAULT_CONNECTION_ID, createDefaultConnectionName(defaultConnection)); |
213 connectionNames.put(Registry.CURRENT_CONNECTION_ID, createCurrentConnectionName(currentConnection)); |
214 |
214 |
215 for (IConnection conn : compatible) { |
215 for (IConnection conn : compatible) { |
216 connectionNames.put(conn.getIdentifier(), conn.getDisplayName()); |
216 connectionNames.put(conn.getIdentifier(), conn.getDisplayName()); |
217 } |
217 } |
218 |
218 |
229 else |
229 else |
230 selectConnection(connection.getIdentifier()); |
230 selectConnection(connection.getIdentifier()); |
231 } |
231 } |
232 editButton.setEnabled(!viewer.getSelection().isEmpty()); |
232 editButton.setEnabled(!viewer.getSelection().isEmpty()); |
233 |
233 |
234 // fire listener in case we selected anew or the default connection changed |
234 // fire listener in case we selected anew or the current connection changed |
235 fireConnectionSelected(); |
235 fireConnectionSelected(); |
236 } |
236 } |
237 |
237 |
238 private void refreshUI() { |
238 private void refreshUI() { |
239 Display.getDefault().syncExec(new Runnable() { |
239 Display.getDefault().syncExec(new Runnable() { |
240 public void run() { |
240 public void run() { |
241 if (viewer != null && viewer.getContentProvider() != null) { |
241 if (viewer != null && viewer.getContentProvider() != null) { |
242 |
242 |
243 // try to preserve the currently selected item, if it's a concrete |
243 // try to preserve the currently selected item, if it's a concrete |
244 // connection; if it's default, allow for the new default to be chosen. |
244 // connection; if it's current, allow for the new current to be chosen. |
245 IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); |
245 IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); |
246 Object value = selection.getFirstElement(); |
246 Object value = selection.getFirstElement(); |
247 String current = null; |
247 String current = null; |
248 if (value instanceof String) { |
248 if (value instanceof String) { |
249 current = (String) value; |
249 current = (String) value; |
250 } |
250 } |
251 if (Registry.DEFAULT_CONNECTION_ID.equals(current)) { |
251 if (Registry.CURRENT_CONNECTION_ID.equals(current)) { |
252 current = null; |
252 current = null; |
253 } |
253 } |
254 setViewerInput(getActualConnection(current)); |
254 setViewerInput(getActualConnection(current)); |
255 } |
255 } |
256 } |
256 } |
257 }); |
257 }); |
258 } |
258 } |
259 |
259 |
260 /** |
260 /** |
261 * @param defaultConnection |
261 * @param currentConnection |
262 * @return |
262 * @return |
263 */ |
263 */ |
264 private String createDefaultConnectionName(IConnection defaultConnection) { |
264 private String createCurrentConnectionName(IConnection currentConnection) { |
265 return MessageFormat.format(Messages.getString("ClientServiceSiteUI2.DefaultConnectionFormat"), //$NON-NLS-1$ |
265 return MessageFormat.format(Messages.getString("ClientServiceSiteUI2.CurrentConnectionFormat"), //$NON-NLS-1$ |
266 defaultConnection != null ? defaultConnection.getDisplayName() : |
266 currentConnection != null ? currentConnection.getDisplayName() : |
267 Messages.getString("ClientServiceSiteUI2.DefaultConnection_NoneDetected")); //$NON-NLS-1$ |
267 Messages.getString("ClientServiceSiteUI2.CurrentConnection_NoneDetected")); //$NON-NLS-1$ |
268 } |
268 } |
269 |
269 |
270 private void initializeDialogUnits(Composite parent) { |
270 private void initializeDialogUnits(Composite parent) { |
271 GC gc = new GC(parent); |
271 GC gc = new GC(parent); |
272 gc.setFont(JFaceResources.getDialogFont()); |
272 gc.setFont(JFaceResources.getDialogFont()); |
317 Messages.getString("ClientServiceSiteUI2.NoConnectionError"), //$NON-NLS-1$ |
317 Messages.getString("ClientServiceSiteUI2.NoConnectionError"), //$NON-NLS-1$ |
318 service.getDisplayName(), |
318 service.getDisplayName(), |
319 requiredConnectionTypes)); |
319 requiredConnectionTypes)); |
320 } |
320 } |
321 |
321 |
322 // check whether the default is compatible with the service and connection type |
322 // check whether the current is compatible with the service and connection type |
323 if (Registry.DEFAULT_CONNECTION_ID.equals(connection)) { |
323 if (Registry.CURRENT_CONNECTION_ID.equals(connection)) { |
324 IConnection actual = getActualConnection(connection); |
324 IConnection actual = getActualConnection(connection); |
325 if (actual == null) { |
325 if (actual == null) { |
326 return new Status(IStatus.ERROR, RemoteConnectionsActivator.PLUGIN_ID, |
326 return new Status(IStatus.ERROR, RemoteConnectionsActivator.PLUGIN_ID, |
327 MessageFormat.format( |
327 MessageFormat.format( |
328 Messages.getString("ClientServiceSiteUI2.NoDefaultConnection"), //$NON-NLS-1$ |
328 Messages.getString("ClientServiceSiteUI2.NoCurrentConnection"), //$NON-NLS-1$ |
329 service.getDisplayName(), |
329 service.getDisplayName(), |
330 requiredConnectionTypes)); |
330 requiredConnectionTypes)); |
331 } |
331 } |
332 |
332 |
333 // is the service supported? |
333 // is the service supported? |
339 } |
339 } |
340 } |
340 } |
341 if (!found) { |
341 if (!found) { |
342 return new Status(IStatus.WARNING, RemoteConnectionsActivator.PLUGIN_ID, |
342 return new Status(IStatus.WARNING, RemoteConnectionsActivator.PLUGIN_ID, |
343 MessageFormat.format( |
343 MessageFormat.format( |
344 Messages.getString("ClientServiceSiteUI2.IncompatibleDefaultConnectionService") //$NON-NLS-1$ |
344 Messages.getString("ClientServiceSiteUI2.IncompatibleCurrentConnectionService") //$NON-NLS-1$ |
345 + "\n" //$NON-NLS-1$ |
345 + "\n" //$NON-NLS-1$ |
346 + Messages.getString("ClientServiceSiteUI2.IncompatibleDefaultConnectionFixupAdvice"), //$NON-NLS-1$ |
346 + Messages.getString("ClientServiceSiteUI2.IncompatibleCurrentConnectionFixupAdvice"), //$NON-NLS-1$ |
347 actual.getDisplayName(), |
347 actual.getDisplayName(), |
348 service.getDisplayName())); |
348 service.getDisplayName())); |
349 } |
349 } |
350 |
350 |
351 // is the hardware type supported by the service? |
351 // is the hardware type supported by the service? |
352 if (!isCompatibleConnection(actual)) { |
352 if (!isCompatibleConnection(actual)) { |
353 return new Status(IStatus.WARNING, RemoteConnectionsActivator.PLUGIN_ID, |
353 return new Status(IStatus.WARNING, RemoteConnectionsActivator.PLUGIN_ID, |
354 MessageFormat.format( |
354 MessageFormat.format( |
355 Messages.getString("ClientServiceSiteUI2.IncompatibleDefaultConnectionType") //$NON-NLS-1$ |
355 Messages.getString("ClientServiceSiteUI2.IncompatibleCurrentConnectionType") //$NON-NLS-1$ |
356 + "\n" //$NON-NLS-1$ |
356 + "\n" //$NON-NLS-1$ |
357 + Messages.getString("ClientServiceSiteUI2.IncompatibleDefaultConnectionFixupAdvice"), //$NON-NLS-1$ |
357 + Messages.getString("ClientServiceSiteUI2.IncompatibleCurrentConnectionFixupAdvice"), //$NON-NLS-1$ |
358 actual.getDisplayName(), |
358 actual.getDisplayName(), |
359 requiredConnectionTypes)); |
359 requiredConnectionTypes)); |
360 |
360 |
361 } |
361 } |
362 } |
362 } |