26 import com.nokia.carbide.remoteconnections.internal.registry.Registry; |
26 import com.nokia.carbide.remoteconnections.internal.registry.Registry; |
27 import com.nokia.carbide.remoteconnections.settings.ui.SettingsWizard; |
27 import com.nokia.carbide.remoteconnections.settings.ui.SettingsWizard; |
28 import com.nokia.cpp.internal.api.utils.core.Check; |
28 import com.nokia.cpp.internal.api.utils.core.Check; |
29 import com.nokia.cpp.internal.api.utils.core.ListenerList; |
29 import com.nokia.cpp.internal.api.utils.core.ListenerList; |
30 |
30 |
|
31 import org.eclipse.core.runtime.IStatus; |
|
32 import org.eclipse.core.runtime.Status; |
31 import org.eclipse.jface.dialogs.Dialog; |
33 import org.eclipse.jface.dialogs.Dialog; |
32 import org.eclipse.jface.dialogs.IDialogConstants; |
34 import org.eclipse.jface.dialogs.IDialogConstants; |
33 import org.eclipse.jface.resource.JFaceResources; |
35 import org.eclipse.jface.resource.JFaceResources; |
34 import org.eclipse.jface.viewers.*; |
36 import org.eclipse.jface.viewers.*; |
35 import org.eclipse.swt.SWT; |
37 import org.eclipse.swt.SWT; |
69 } |
71 } |
70 |
72 |
71 public void createComposite(Composite parent) { |
73 public void createComposite(Composite parent) { |
72 initializeDialogUnits(parent); |
74 initializeDialogUnits(parent); |
73 Group group = new Group(parent, SWT.NONE); |
75 Group group = new Group(parent, SWT.NONE); |
74 group.setText(Messages.getString("ClientServiceSiteUI.UseConnectionGroupLabel")); //$NON-NLS-1$ |
76 group.setText(Messages.getString("ClientServiceSiteUI2.UseConnectionGroupLabel")); //$NON-NLS-1$ |
75 group.setLayout(new GridLayout()); |
77 group.setLayout(new GridLayout()); |
76 group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); |
78 group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); |
77 group.setData(UID, "useConnectionGroup"); //$NON-NLS-1$ |
79 group.setData(UID, "useConnectionGroup"); //$NON-NLS-1$ |
78 |
80 |
79 viewer = new ComboViewer(group, SWT.READ_ONLY); |
81 viewer = new ComboViewer(group, SWT.READ_ONLY); |
112 gd = new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.VERTICAL_ALIGN_CENTER); |
114 gd = new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.VERTICAL_ALIGN_CENTER); |
113 composite.setLayoutData(gd); |
115 composite.setLayoutData(gd); |
114 composite.setFont(parent.getFont()); |
116 composite.setFont(parent.getFont()); |
115 |
117 |
116 newButton = new Button(composite, SWT.PUSH); |
118 newButton = new Button(composite, SWT.PUSH); |
117 newButton.setText(Messages.getString("ClientServiceSiteUI.NewButtonLabel")); //$NON-NLS-1$ |
119 newButton.setText(Messages.getString("ClientServiceSiteUI2.NewButtonLabel")); //$NON-NLS-1$ |
118 newButton.setFont(JFaceResources.getDialogFont()); |
120 newButton.setFont(JFaceResources.getDialogFont()); |
119 gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL); |
121 gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL); |
120 int widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH); |
122 int widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH); |
121 Point minSize = newButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); |
123 Point minSize = newButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); |
122 gd.widthHint = Math.max(widthHint, minSize.x); |
124 gd.widthHint = Math.max(widthHint, minSize.x); |
134 setViewerInput(connection); |
136 setViewerInput(connection); |
135 } |
137 } |
136 }); |
138 }); |
137 |
139 |
138 editButton = new Button(composite, SWT.PUSH); |
140 editButton = new Button(composite, SWT.PUSH); |
139 editButton.setText(Messages.getString("ClientServiceSiteUI.EditButtonLabel")); //$NON-NLS-1$ |
141 editButton.setText(Messages.getString("ClientServiceSiteUI2.EditButtonLabel")); //$NON-NLS-1$ |
140 editButton.setFont(JFaceResources.getDialogFont()); |
142 editButton.setFont(JFaceResources.getDialogFont()); |
141 gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL); |
143 gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL); |
142 widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH); |
144 widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH); |
143 minSize = editButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); |
145 minSize = editButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); |
144 gd.widthHint = Math.max(widthHint, minSize.x); |
146 gd.widthHint = Math.max(widthHint, minSize.x); |
181 * want to actually validate the connection now. |
183 * want to actually validate the connection now. |
182 * @param id |
184 * @param id |
183 * @return {@link IConnection} or <code>null</code> |
185 * @return {@link IConnection} or <code>null</code> |
184 */ |
186 */ |
185 protected IConnection getActualConnection(String id) { |
187 protected IConnection getActualConnection(String id) { |
|
188 if (id == null) { |
|
189 return null; |
|
190 } |
186 if (id.equals(Registry.DEFAULT_CONNECTION_ID)) { |
191 if (id.equals(Registry.DEFAULT_CONNECTION_ID)) { |
187 return RemoteConnectionsActivator.getConnectionsManager().getDefaultConnection(); |
192 return RemoteConnectionsActivator.getConnectionsManager().getDefaultConnection(); |
188 } |
193 } |
189 for (IConnection connection : RemoteConnectionsActivator.getConnectionsManager().getConnections()) { |
194 for (IConnection connection : RemoteConnectionsActivator.getConnectionsManager().getConnections()) { |
190 if (connection.getIdentifier().equals(id)) { |
195 if (connection.getIdentifier().equals(id)) { |
223 } |
228 } |
224 else |
229 else |
225 selectConnection(connection.getIdentifier()); |
230 selectConnection(connection.getIdentifier()); |
226 } |
231 } |
227 editButton.setEnabled(!viewer.getSelection().isEmpty()); |
232 editButton.setEnabled(!viewer.getSelection().isEmpty()); |
|
233 |
|
234 // fire listener in case we selected anew or the default connection changed |
|
235 fireConnectionSelected(); |
228 } |
236 } |
229 |
237 |
230 private void refreshUI() { |
238 private void refreshUI() { |
231 Display.getDefault().syncExec(new Runnable() { |
239 Display.getDefault().syncExec(new Runnable() { |
232 public void run() { |
240 public void run() { |
233 setViewerInput(null); |
241 if (viewer != null && viewer.getContentProvider() != null) { |
|
242 |
|
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. |
|
245 IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); |
|
246 Object value = selection.getFirstElement(); |
|
247 String current = null; |
|
248 if (value instanceof String) { |
|
249 current = (String) value; |
|
250 } |
|
251 if (Registry.DEFAULT_CONNECTION_ID.equals(current)) { |
|
252 current = null; |
|
253 } |
|
254 setViewerInput(getActualConnection(current)); |
|
255 } |
234 } |
256 } |
235 }); |
257 }); |
236 } |
258 } |
237 |
259 |
238 /** |
260 /** |
283 |
305 |
284 public String getSelectedConnection() { |
306 public String getSelectedConnection() { |
285 return connection; |
307 return connection; |
286 } |
308 } |
287 |
309 |
|
310 public IStatus getSelectionStatus() { |
|
311 // no selection yet...? |
|
312 if (connection == null) { |
|
313 return new Status(IStatus.ERROR, RemoteConnectionsActivator.PLUGIN_ID, |
|
314 Messages.getString("ClientServiceSiteUI2.NoConnectionError")); |
|
315 } |
|
316 |
|
317 // check whether the default is compatible with the service and connection type |
|
318 if (Registry.DEFAULT_CONNECTION_ID.equals(connection)) { |
|
319 IConnection actual = getActualConnection(connection); |
|
320 if (actual != null) { |
|
321 // is the service supported? |
|
322 boolean found = false; |
|
323 for (IConnectedService aService : Registry.instance().getConnectedServices(actual)) { |
|
324 if (service.getIdentifier().equals(aService.getService().getIdentifier())) { |
|
325 found = true; |
|
326 break; |
|
327 } |
|
328 } |
|
329 if (!found) { |
|
330 return new Status(IStatus.WARNING, RemoteConnectionsActivator.PLUGIN_ID, |
|
331 MessageFormat.format( |
|
332 Messages.getString("ClientServiceSiteUI2.IncompatibleDefaultConnectionService"), |
|
333 actual.getDisplayName(), |
|
334 service.getDisplayName())); |
|
335 } |
|
336 |
|
337 // is the hardware type supported by the service? |
|
338 if (!isCompatibleConnection(actual)) { |
|
339 String requiredConnectionTypes = ""; |
|
340 for (IConnectionType type : compatibleConnectionTypes) { |
|
341 if (requiredConnectionTypes.length() > 0) |
|
342 requiredConnectionTypes += ", "; |
|
343 requiredConnectionTypes += type.getDisplayName(); |
|
344 } |
|
345 return new Status(IStatus.WARNING, RemoteConnectionsActivator.PLUGIN_ID, |
|
346 MessageFormat.format( |
|
347 Messages.getString("ClientServiceSiteUI2.IncompatibleDefaultConnectionType"), |
|
348 actual.getDisplayName(), |
|
349 requiredConnectionTypes)); |
|
350 |
|
351 } |
|
352 |
|
353 } |
|
354 } |
|
355 |
|
356 // otherwise, it's okay! |
|
357 return Status.OK_STATUS; |
|
358 } |
|
359 |
288 /* (non-Javadoc) |
360 /* (non-Javadoc) |
289 * @see com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI2#getConnectionDisplayName(java.lang.String) |
361 * @see com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI2#getConnectionDisplayName(java.lang.String) |
290 */ |
362 */ |
291 public String getConnectionDisplayName(String connection) { |
363 public String getConnectionDisplayName(String connection) { |
292 String display = connectionNames.get(connection); |
364 String display = connectionNames.get(connection); |