author | Ed Swartz <ed.swartz@nokia.com> |
Wed, 30 Dec 2009 11:43:43 -0600 | |
changeset 730 | 8ecd45ef360e |
parent 728 | a39d0ba41f81 |
child 731 | 68bc07acac96 |
permissions | -rw-r--r-- |
728 | 1 |
/* |
2 |
* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 |
* All rights reserved. |
|
4 |
* This component and the accompanying materials are made available |
|
5 |
* under the terms of the License "Eclipse Public License v1.0" |
|
6 |
* which accompanies this distribution, and is available |
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 |
* |
|
9 |
* Initial Contributors: |
|
10 |
* Nokia Corporation - initial contribution. |
|
11 |
* |
|
12 |
* Contributors: |
|
13 |
* |
|
14 |
* Description: |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
package com.nokia.carbide.remoteconnections.internal.ui; |
|
20 |
||
21 |
import com.nokia.carbide.remoteconnections.Messages; |
|
22 |
import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; |
|
23 |
import com.nokia.carbide.remoteconnections.interfaces.*; |
|
24 |
import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener; |
|
25 |
import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionsManagerListener; |
|
26 |
import com.nokia.carbide.remoteconnections.internal.registry.Registry; |
|
27 |
import com.nokia.carbide.remoteconnections.settings.ui.SettingsWizard; |
|
28 |
import com.nokia.cpp.internal.api.utils.core.Check; |
|
29 |
import com.nokia.cpp.internal.api.utils.core.ListenerList; |
|
30 |
||
730
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
31 |
import org.eclipse.core.runtime.IStatus; |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
32 |
import org.eclipse.core.runtime.Status; |
728 | 33 |
import org.eclipse.jface.dialogs.Dialog; |
34 |
import org.eclipse.jface.dialogs.IDialogConstants; |
|
35 |
import org.eclipse.jface.resource.JFaceResources; |
|
36 |
import org.eclipse.jface.viewers.*; |
|
37 |
import org.eclipse.swt.SWT; |
|
38 |
import org.eclipse.swt.events.DisposeEvent; |
|
39 |
import org.eclipse.swt.events.DisposeListener; |
|
40 |
import org.eclipse.swt.events.SelectionAdapter; |
|
41 |
import org.eclipse.swt.events.SelectionEvent; |
|
42 |
import org.eclipse.swt.graphics.*; |
|
43 |
import org.eclipse.swt.layout.GridData; |
|
44 |
import org.eclipse.swt.layout.GridLayout; |
|
45 |
import org.eclipse.swt.widgets.*; |
|
46 |
||
47 |
import java.text.MessageFormat; |
|
48 |
import java.util.*; |
|
49 |
import java.util.List; |
|
50 |
||
51 |
/** |
|
52 |
* Implementation of IClientServiceSiteUI2 |
|
53 |
*/ |
|
54 |
@SuppressWarnings("deprecation") |
|
55 |
public class ClientServiceSiteUI2 implements IClientServiceSiteUI2, IConnectionListener, IConnectionsManagerListener { |
|
56 |
||
57 |
private IService service; |
|
58 |
private ComboViewer viewer; |
|
59 |
private FontMetrics fm; |
|
60 |
private Set<IConnectionType> compatibleConnectionTypes; |
|
61 |
private Button editButton; |
|
62 |
private Button newButton; |
|
63 |
private String connection; |
|
64 |
private ListenerList<IListener> listenerList; |
|
65 |
private static final String UID = ".uid"; //$NON-NLS-1$ |
|
66 |
private Map<String, String> connectionNames; |
|
67 |
||
68 |
public ClientServiceSiteUI2(IService service) { |
|
69 |
Check.checkArg(service); |
|
70 |
this.service = service; |
|
71 |
} |
|
72 |
||
73 |
public void createComposite(Composite parent) { |
|
74 |
initializeDialogUnits(parent); |
|
75 |
Group group = new Group(parent, SWT.NONE); |
|
730
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
76 |
group.setText(Messages.getString("ClientServiceSiteUI2.UseConnectionGroupLabel")); //$NON-NLS-1$ |
728 | 77 |
group.setLayout(new GridLayout()); |
78 |
group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); |
|
79 |
group.setData(UID, "useConnectionGroup"); //$NON-NLS-1$ |
|
80 |
||
81 |
viewer = new ComboViewer(group, SWT.READ_ONLY); |
|
82 |
viewer.setLabelProvider(new LabelProvider() { |
|
83 |
@Override |
|
84 |
public String getText(Object element) { |
|
85 |
Check.checkContract(element instanceof String); |
|
86 |
String id = (String) element; |
|
87 |
return connectionNames.get(id); |
|
88 |
} |
|
89 |
}); |
|
90 |
viewer.setContentProvider(new ArrayContentProvider()); |
|
91 |
GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false); |
|
92 |
viewer.getCombo().setLayoutData(gd); |
|
93 |
viewer.getControl().setData(UID, "viewer"); //$NON-NLS-1$ |
|
94 |
viewer.addSelectionChangedListener(new ISelectionChangedListener() { |
|
95 |
public void selectionChanged(SelectionChangedEvent event) { |
|
96 |
IStructuredSelection selection = (IStructuredSelection) event.getSelection(); |
|
97 |
String connection = (String) selection.getFirstElement(); |
|
98 |
if (!connection.equals(ClientServiceSiteUI2.this.connection)) { |
|
99 |
ClientServiceSiteUI2.this.connection = connection; |
|
100 |
fireConnectionSelected(); |
|
101 |
} |
|
102 |
} |
|
103 |
}); |
|
104 |
||
105 |
final Composite composite = new Composite(group, SWT.NONE); |
|
106 |
GridLayout layout = new GridLayout(); |
|
107 |
layout.numColumns = 2; |
|
108 |
layout.makeColumnsEqualWidth = true; |
|
109 |
layout.marginWidth = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.HORIZONTAL_MARGIN); |
|
110 |
layout.marginHeight = Dialog.convertVerticalDLUsToPixels(fm, IDialogConstants.VERTICAL_MARGIN); |
|
111 |
layout.horizontalSpacing = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.HORIZONTAL_SPACING); |
|
112 |
layout.verticalSpacing = Dialog.convertVerticalDLUsToPixels(fm, IDialogConstants.VERTICAL_SPACING); |
|
113 |
composite.setLayout(layout); |
|
114 |
gd = new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.VERTICAL_ALIGN_CENTER); |
|
115 |
composite.setLayoutData(gd); |
|
116 |
composite.setFont(parent.getFont()); |
|
117 |
||
118 |
newButton = new Button(composite, SWT.PUSH); |
|
730
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
119 |
newButton.setText(Messages.getString("ClientServiceSiteUI2.NewButtonLabel")); //$NON-NLS-1$ |
728 | 120 |
newButton.setFont(JFaceResources.getDialogFont()); |
121 |
gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL); |
|
122 |
int widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH); |
|
123 |
Point minSize = newButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); |
|
124 |
gd.widthHint = Math.max(widthHint, minSize.x); |
|
125 |
newButton.setLayoutData(gd); |
|
126 |
newButton.setData(UID, "newButton"); //$NON-NLS-1$ |
|
127 |
newButton.addSelectionListener(new SelectionAdapter() { |
|
128 |
@Override |
|
129 |
public void widgetSelected(SelectionEvent e) { |
|
130 |
SettingsWizard wizard = new SettingsWizard(null, service); |
|
131 |
wizard.open(composite.getShell()); |
|
132 |
IConnection connection = wizard.getConnectionToEdit(); |
|
133 |
// note: refresh ASAP so the selection will be valid; but endure a listener event |
|
134 |
// which will redo this |
|
135 |
refreshUI(); |
|
136 |
setViewerInput(connection); |
|
137 |
} |
|
138 |
}); |
|
139 |
||
140 |
editButton = new Button(composite, SWT.PUSH); |
|
730
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
141 |
editButton.setText(Messages.getString("ClientServiceSiteUI2.EditButtonLabel")); //$NON-NLS-1$ |
728 | 142 |
editButton.setFont(JFaceResources.getDialogFont()); |
143 |
gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL); |
|
144 |
widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH); |
|
145 |
minSize = editButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); |
|
146 |
gd.widthHint = Math.max(widthHint, minSize.x); |
|
147 |
editButton.setLayoutData(gd); |
|
148 |
editButton.setData(UID, "editButton"); //$NON-NLS-1$ |
|
149 |
editButton.addSelectionListener(new SelectionAdapter() { |
|
150 |
@Override |
|
151 |
public void widgetSelected(SelectionEvent e) { |
|
152 |
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); |
|
153 |
Object value = selection.getFirstElement(); |
|
154 |
if (value instanceof String) { |
|
155 |
IConnection editConnection = getActualConnection((String) value); |
|
156 |
SettingsWizard wizard = new SettingsWizard(editConnection, service); |
|
157 |
wizard.open(composite.getShell()); |
|
158 |
||
159 |
// leave the viewer the same, callback will refresh anything needed |
|
160 |
} |
|
161 |
} |
|
162 |
}); |
|
163 |
||
164 |
// attach listeners |
|
165 |
RemoteConnectionsActivator.getConnectionsManager().addConnectionListener(this); |
|
166 |
RemoteConnectionsActivator.getConnectionsManager().addConnectionStoreChangedListener(this); |
|
167 |
||
168 |
// remove listeners on dispose |
|
169 |
group.addDisposeListener(new DisposeListener() { |
|
170 |
||
171 |
public void widgetDisposed(DisposeEvent e) { |
|
172 |
RemoteConnectionsActivator.getConnectionsManager().addConnectionListener(ClientServiceSiteUI2.this); |
|
173 |
RemoteConnectionsActivator.getConnectionsManager().addConnectionStoreChangedListener(ClientServiceSiteUI2.this); |
|
174 |
} |
|
175 |
}); |
|
176 |
||
177 |
setViewerInput(null); |
|
178 |
} |
|
179 |
||
180 |
/** |
|
181 |
* Get the actual connection for an identifier. |
|
182 |
* This is not {@link IConnectionsManager#ensureConnection(String, IService)} because we don't |
|
183 |
* want to actually validate the connection now. |
|
184 |
* @param id |
|
185 |
* @return {@link IConnection} or <code>null</code> |
|
186 |
*/ |
|
187 |
protected IConnection getActualConnection(String id) { |
|
730
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
188 |
if (id == null) { |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
189 |
return null; |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
190 |
} |
728 | 191 |
if (id.equals(Registry.DEFAULT_CONNECTION_ID)) { |
192 |
return RemoteConnectionsActivator.getConnectionsManager().getDefaultConnection(); |
|
193 |
} |
|
194 |
for (IConnection connection : RemoteConnectionsActivator.getConnectionsManager().getConnections()) { |
|
195 |
if (connection.getIdentifier().equals(id)) { |
|
196 |
return connection; |
|
197 |
} |
|
198 |
} |
|
199 |
return null; |
|
200 |
} |
|
201 |
||
202 |
/** |
|
203 |
* Set the selected input. |
|
204 |
* @param connection existing connection or <code>null</code> for the default |
|
205 |
*/ |
|
206 |
private void setViewerInput(IConnection connection) { |
|
207 |
List<IConnection> compatible = getCompatibleConnections(); |
|
208 |
connectionNames = new LinkedHashMap<String, String>(); |
|
209 |
||
210 |
// update the default |
|
211 |
IConnection defaultConnection = RemoteConnectionsActivator.getConnectionsManager().getDefaultConnection(); |
|
212 |
||
213 |
connectionNames.put(Registry.DEFAULT_CONNECTION_ID, createDefaultConnectionName(defaultConnection)); |
|
214 |
||
215 |
for (IConnection conn : compatible) { |
|
216 |
connectionNames.put(conn.getIdentifier(), conn.getDisplayName()); |
|
217 |
} |
|
218 |
||
219 |
viewer.setInput(connectionNames.keySet()); |
|
220 |
||
221 |
if (connectionNames.isEmpty()) |
|
222 |
viewer.getCombo().setEnabled(false); |
|
223 |
else { |
|
224 |
viewer.getCombo().setEnabled(true); |
|
225 |
if (connection == null) { |
|
226 |
viewer.getCombo().select(0); |
|
227 |
viewer.setSelection(viewer.getSelection()); |
|
228 |
} |
|
229 |
else |
|
230 |
selectConnection(connection.getIdentifier()); |
|
231 |
} |
|
232 |
editButton.setEnabled(!viewer.getSelection().isEmpty()); |
|
730
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
233 |
|
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
234 |
// fire listener in case we selected anew or the default connection changed |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
235 |
fireConnectionSelected(); |
728 | 236 |
} |
237 |
||
238 |
private void refreshUI() { |
|
239 |
Display.getDefault().syncExec(new Runnable() { |
|
240 |
public void run() { |
|
730
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
241 |
if (viewer != null && viewer.getContentProvider() != null) { |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
242 |
|
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
243 |
// try to preserve the currently selected item, if it's a concrete |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
244 |
// connection; if it's default, allow for the new default to be chosen. |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
245 |
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
246 |
Object value = selection.getFirstElement(); |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
247 |
String current = null; |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
248 |
if (value instanceof String) { |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
249 |
current = (String) value; |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
250 |
} |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
251 |
if (Registry.DEFAULT_CONNECTION_ID.equals(current)) { |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
252 |
current = null; |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
253 |
} |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
254 |
setViewerInput(getActualConnection(current)); |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
255 |
} |
728 | 256 |
} |
257 |
}); |
|
258 |
} |
|
259 |
||
260 |
/** |
|
261 |
* @param defaultConnection |
|
262 |
* @return |
|
263 |
*/ |
|
264 |
private String createDefaultConnectionName(IConnection defaultConnection) { |
|
265 |
return MessageFormat.format("Default connection ({0})", |
|
266 |
defaultConnection != null ? defaultConnection.getDisplayName() : |
|
267 |
"when defined"); |
|
268 |
} |
|
269 |
||
270 |
private void initializeDialogUnits(Composite parent) { |
|
271 |
GC gc = new GC(parent); |
|
272 |
gc.setFont(JFaceResources.getDialogFont()); |
|
273 |
fm = gc.getFontMetrics(); |
|
274 |
gc.dispose(); |
|
275 |
} |
|
276 |
||
277 |
private List<IConnection> getCompatibleConnections() { |
|
278 |
getCompatibleConnectionTypes(); |
|
279 |
||
280 |
List<IConnection> compatibleConnections = new ArrayList<IConnection>(); |
|
281 |
for (IConnection connection : Registry.instance().getConnections()) { |
|
282 |
if (isCompatibleConnection(connection)) |
|
283 |
compatibleConnections.add(connection); |
|
284 |
} |
|
285 |
return compatibleConnections; |
|
286 |
} |
|
287 |
||
288 |
private boolean isCompatibleConnection(IConnection connection) { |
|
289 |
return compatibleConnectionTypes.contains(connection.getConnectionType()); |
|
290 |
} |
|
291 |
||
292 |
private void getCompatibleConnectionTypes() { |
|
293 |
compatibleConnectionTypes = new HashSet<IConnectionType>(); |
|
294 |
Collection<String> compatibleTypeIds = |
|
295 |
Registry.instance().getCompatibleConnectionTypeIds(service); |
|
296 |
for (String typeId : compatibleTypeIds) { |
|
297 |
compatibleConnectionTypes.add( |
|
298 |
Registry.instance().getConnectionType(typeId)); |
|
299 |
} |
|
300 |
} |
|
301 |
||
302 |
public void selectConnection(String connection) { |
|
303 |
viewer.setSelection(new StructuredSelection(connection)); |
|
304 |
} |
|
305 |
||
306 |
public String getSelectedConnection() { |
|
307 |
return connection; |
|
308 |
} |
|
309 |
||
730
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
310 |
public IStatus getSelectionStatus() { |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
311 |
// no selection yet...? |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
312 |
if (connection == null) { |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
313 |
return new Status(IStatus.ERROR, RemoteConnectionsActivator.PLUGIN_ID, |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
314 |
Messages.getString("ClientServiceSiteUI2.NoConnectionError")); |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
315 |
} |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
316 |
|
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
317 |
// check whether the default is compatible with the service and connection type |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
318 |
if (Registry.DEFAULT_CONNECTION_ID.equals(connection)) { |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
319 |
IConnection actual = getActualConnection(connection); |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
320 |
if (actual != null) { |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
321 |
// is the service supported? |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
322 |
boolean found = false; |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
323 |
for (IConnectedService aService : Registry.instance().getConnectedServices(actual)) { |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
324 |
if (service.getIdentifier().equals(aService.getService().getIdentifier())) { |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
325 |
found = true; |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
326 |
break; |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
327 |
} |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
328 |
} |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
329 |
if (!found) { |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
330 |
return new Status(IStatus.WARNING, RemoteConnectionsActivator.PLUGIN_ID, |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
331 |
MessageFormat.format( |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
332 |
Messages.getString("ClientServiceSiteUI2.IncompatibleDefaultConnectionService"), |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
333 |
actual.getDisplayName(), |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
334 |
service.getDisplayName())); |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
335 |
} |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
336 |
|
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
337 |
// is the hardware type supported by the service? |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
338 |
if (!isCompatibleConnection(actual)) { |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
339 |
String requiredConnectionTypes = ""; |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
340 |
for (IConnectionType type : compatibleConnectionTypes) { |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
341 |
if (requiredConnectionTypes.length() > 0) |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
342 |
requiredConnectionTypes += ", "; |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
343 |
requiredConnectionTypes += type.getDisplayName(); |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
344 |
} |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
345 |
return new Status(IStatus.WARNING, RemoteConnectionsActivator.PLUGIN_ID, |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
346 |
MessageFormat.format( |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
347 |
Messages.getString("ClientServiceSiteUI2.IncompatibleDefaultConnectionType"), |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
348 |
actual.getDisplayName(), |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
349 |
requiredConnectionTypes)); |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
350 |
|
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
351 |
} |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
352 |
|
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
353 |
} |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
354 |
} |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
355 |
|
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
356 |
// otherwise, it's okay! |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
357 |
return Status.OK_STATUS; |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
358 |
} |
8ecd45ef360e
Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents:
728
diff
changeset
|
359 |
|
728 | 360 |
/* (non-Javadoc) |
361 |
* @see com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI2#getConnectionDisplayName(java.lang.String) |
|
362 |
*/ |
|
363 |
public String getConnectionDisplayName(String connection) { |
|
364 |
String display = connectionNames.get(connection); |
|
365 |
if (display == null) |
|
366 |
display = MessageFormat.format("<<nonexistent connection {0}>>", connection); |
|
367 |
return display; |
|
368 |
} |
|
369 |
||
370 |
public void addListener(IListener listener) { |
|
371 |
if (listenerList == null) |
|
372 |
listenerList = new ListenerList<IListener>(); |
|
373 |
listenerList.add(listener); |
|
374 |
} |
|
375 |
||
376 |
public void removeListener(IListener listener) { |
|
377 |
if (listenerList != null) |
|
378 |
listenerList.remove(listener); |
|
379 |
} |
|
380 |
||
381 |
private void fireConnectionSelected() { |
|
382 |
if (listenerList != null) { |
|
383 |
for (IListener listener : listenerList) { |
|
384 |
listener.connectionSelected(); |
|
385 |
} |
|
386 |
} |
|
387 |
} |
|
388 |
||
389 |
/* (non-Javadoc) |
|
390 |
* @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener#connectionAdded(com.nokia.carbide.remoteconnections.interfaces.IConnection) |
|
391 |
*/ |
|
392 |
public void connectionAdded(IConnection connection) { |
|
393 |
refreshUI(); |
|
394 |
} |
|
395 |
||
396 |
/* (non-Javadoc) |
|
397 |
* @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener#connectionRemoved(com.nokia.carbide.remoteconnections.interfaces.IConnection) |
|
398 |
*/ |
|
399 |
public void connectionRemoved(IConnection connection) { |
|
400 |
refreshUI(); |
|
401 |
} |
|
402 |
||
403 |
/* (non-Javadoc) |
|
404 |
* @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener#defaultConnectionSet(com.nokia.carbide.remoteconnections.interfaces.IConnection) |
|
405 |
*/ |
|
406 |
public void defaultConnectionSet(IConnection connection) { |
|
407 |
refreshUI(); |
|
408 |
} |
|
409 |
||
410 |
/* (non-Javadoc) |
|
411 |
* @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionsManagerListener#connectionStoreChanged() |
|
412 |
*/ |
|
413 |
public void connectionStoreChanged() { |
|
414 |
refreshUI(); |
|
415 |
} |
|
416 |
||
417 |
/* (non-Javadoc) |
|
418 |
* @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionsManagerListener#displayChanged() |
|
419 |
*/ |
|
420 |
public void displayChanged() { |
|
421 |
refreshUI(); |
|
422 |
} |
|
423 |
} |