author | dadubrow |
Tue, 02 Mar 2010 13:31:49 -0600 | |
changeset 1061 | ceac11190019 |
parent 983 | 8b4ee73c530c |
child 1184 | 745221c781a3 |
permissions | -rw-r--r-- |
956 | 1 |
/* |
2 |
* Copyright (c) 2010 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 |
package com.nokia.cdt.internal.debug.launch.newwizard; |
|
19 |
||
20 |
import java.text.MessageFormat; |
|
21 |
import java.util.ArrayList; |
|
22 |
import java.util.Collection; |
|
23 |
import java.util.HashSet; |
|
24 |
import java.util.List; |
|
25 |
import java.util.Set; |
|
26 |
||
27 |
import org.eclipse.core.runtime.IStatus; |
|
964
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
28 |
import org.eclipse.jface.dialogs.Dialog; |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
29 |
import org.eclipse.jface.dialogs.IDialogConstants; |
956 | 30 |
import org.eclipse.jface.layout.GridDataFactory; |
31 |
import org.eclipse.jface.layout.GridLayoutFactory; |
|
964
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
32 |
import org.eclipse.jface.resource.JFaceResources; |
956 | 33 |
import org.eclipse.jface.viewers.ArrayContentProvider; |
34 |
import org.eclipse.jface.viewers.ComboViewer; |
|
35 |
import org.eclipse.jface.viewers.ISelection; |
|
36 |
import org.eclipse.jface.viewers.ISelectionChangedListener; |
|
37 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
38 |
import org.eclipse.jface.viewers.LabelProvider; |
|
39 |
import org.eclipse.jface.viewers.SelectionChangedEvent; |
|
40 |
import org.eclipse.jface.viewers.StructuredSelection; |
|
41 |
import org.eclipse.swt.SWT; |
|
42 |
import org.eclipse.swt.events.ControlAdapter; |
|
43 |
import org.eclipse.swt.events.ControlEvent; |
|
44 |
import org.eclipse.swt.events.SelectionAdapter; |
|
45 |
import org.eclipse.swt.events.SelectionEvent; |
|
964
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
46 |
import org.eclipse.swt.graphics.FontMetrics; |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
47 |
import org.eclipse.swt.graphics.GC; |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
48 |
import org.eclipse.swt.graphics.Point; |
956 | 49 |
import org.eclipse.swt.widgets.Button; |
50 |
import org.eclipse.swt.widgets.Combo; |
|
51 |
import org.eclipse.swt.widgets.Composite; |
|
52 |
import org.eclipse.swt.widgets.Control; |
|
53 |
import org.eclipse.swt.widgets.Display; |
|
964
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
54 |
import org.eclipse.swt.widgets.Group; |
956 | 55 |
import org.eclipse.swt.widgets.Label; |
56 |
import org.eclipse.swt.widgets.Shell; |
|
57 |
||
58 |
import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; |
|
59 |
import com.nokia.carbide.remoteconnections.interfaces.IConnectedService; |
|
60 |
import com.nokia.carbide.remoteconnections.interfaces.IConnection; |
|
61 |
import com.nokia.carbide.remoteconnections.interfaces.IConnectionType; |
|
62 |
import com.nokia.carbide.remoteconnections.interfaces.IConnectionTypeProvider; |
|
63 |
import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager; |
|
1061
ceac11190019
bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents:
983
diff
changeset
|
64 |
import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatusChangedListener; |
956 | 65 |
import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener; |
66 |
import com.nokia.carbide.remoteconnections.settings.ui.SettingsWizard; |
|
67 |
||
68 |
/** |
|
69 |
* This dialog allows in-depth configuration of the connection settings. |
|
70 |
*/ |
|
71 |
@SuppressWarnings("restriction") |
|
1061
ceac11190019
bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents:
983
diff
changeset
|
72 |
public class ConnectToDeviceDialog extends AbstractLaunchSettingsDialog implements IConnectionListener, IStatusChangedListener { |
956 | 73 |
private IConnectionsManager manager; |
74 |
private IConnectionTypeProvider typeProvider; |
|
964
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
75 |
private FontMetrics fm; |
956 | 76 |
private ComboViewer viewer; |
77 |
private Button editButton; |
|
78 |
private Label descriptionLabel; |
|
964
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
79 |
private Button newButton; |
1061
ceac11190019
bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents:
983
diff
changeset
|
80 |
private IConnectedService currentServiceListener; |
956 | 81 |
|
82 |
protected ConnectToDeviceDialog(Shell shell, LaunchWizardData data) { |
|
83 |
super(shell, data); |
|
84 |
manager = RemoteConnectionsActivator.getConnectionsManager(); |
|
85 |
typeProvider = RemoteConnectionsActivator.getConnectionTypeProvider(); |
|
86 |
} |
|
87 |
||
88 |
@Override |
|
89 |
protected Control createDialogArea(Composite parent) { |
|
964
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
90 |
initializeDialogUnits(parent); |
956 | 91 |
final Composite composite = initDialogArea(parent, |
969 | 92 |
Messages.getString("ConnectToDeviceDialog.Title"), //$NON-NLS-1$ |
956 | 93 |
LaunchWizardHelpIds.WIZARD_DIALOG_CHANGE_CONNECTION); |
94 |
||
964
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
95 |
Group viewerGroup = new Group(composite, SWT.NONE); |
969 | 96 |
viewerGroup.setText(Messages.getString("ConnectToDeviceDialog.GroupLabel")); //$NON-NLS-1$ |
956 | 97 |
GridDataFactory.fillDefaults().applyTo(viewerGroup); |
964
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
98 |
GridLayoutFactory.swtDefaults().applyTo(viewerGroup); |
956 | 99 |
|
100 |
viewer = new ComboViewer(viewerGroup, SWT.READ_ONLY); |
|
101 |
viewer.setLabelProvider(new LabelProvider() { |
|
102 |
@Override |
|
103 |
public String getText(Object element) { |
|
104 |
if (element instanceof IConnection) |
|
105 |
return ((IConnection) element).getDisplayName(); |
|
106 |
||
969 | 107 |
return Messages.getString("ConnectToDeviceDialog.NoCurrentItem"); //$NON-NLS-1$ |
956 | 108 |
} |
109 |
}); |
|
110 |
viewer.setContentProvider(new ArrayContentProvider()); |
|
111 |
Combo combo = viewer.getCombo(); |
|
112 |
GridDataFactory.defaultsFor(combo).grab(true, false).applyTo(combo); |
|
113 |
viewer.getControl().setData(UID, "combo_viewer"); //$NON-NLS-1$ |
|
114 |
viewer.addSelectionChangedListener(new ISelectionChangedListener() { |
|
115 |
public void selectionChanged(SelectionChangedEvent event) { |
|
116 |
if (getDialogArea() != null) |
|
117 |
connectionSelected(getConnectionFromSelection(event.getSelection())); |
|
118 |
} |
|
119 |
}); |
|
120 |
manager.addConnectionListener(this); |
|
121 |
||
964
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
122 |
final Composite buttonGroup = new Composite(viewerGroup, SWT.NONE); |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
123 |
int w = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.HORIZONTAL_MARGIN); |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
124 |
int h = Dialog.convertVerticalDLUsToPixels(fm, IDialogConstants.VERTICAL_MARGIN); |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
125 |
int hs = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.HORIZONTAL_SPACING); |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
126 |
int vs = Dialog.convertVerticalDLUsToPixels(fm, IDialogConstants.VERTICAL_SPACING); |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
127 |
GridLayoutFactory.swtDefaults().numColumns(2).equalWidth(true). |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
128 |
margins(w, h).spacing(hs, vs).applyTo(buttonGroup); |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
129 |
GridDataFactory.swtDefaults().align(SWT.END, SWT.CENTER).applyTo(buttonGroup); |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
130 |
buttonGroup.setFont(parent.getFont()); |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
131 |
|
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
132 |
newButton = new Button(buttonGroup, SWT.PUSH); |
969 | 133 |
newButton.setText(Messages.getString("ConnectToDeviceDialog.NewLabel")); //$NON-NLS-1$ |
964
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
134 |
newButton.setFont(JFaceResources.getDialogFont()); |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
135 |
int widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH); |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
136 |
Point minSize = newButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
137 |
widthHint = Math.max(widthHint, minSize.x); |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
138 |
GridDataFactory.swtDefaults().align(SWT.FILL, SWT.TOP).hint(widthHint, SWT.DEFAULT).applyTo(newButton); |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
139 |
newButton.setData(UID, "newButton"); //$NON-NLS-1$ |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
140 |
newButton.addSelectionListener(new SelectionAdapter() { |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
141 |
@Override |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
142 |
public void widgetSelected(SelectionEvent e) { |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
143 |
SettingsWizard wizard = new SettingsWizard(null, data.getService()); |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
144 |
wizard.open(composite.getShell()); |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
145 |
IConnection connection = wizard.getConnectionToEdit(); |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
146 |
setViewerInput(connection); |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
147 |
} |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
148 |
}); |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
149 |
|
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
150 |
editButton = new Button(buttonGroup, SWT.PUSH); |
969 | 151 |
editButton.setText(Messages.getString("ConnectToDeviceDialog.EditLabel")); //$NON-NLS-1$ |
964
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
152 |
editButton.setFont(JFaceResources.getDialogFont()); |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
153 |
widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH); |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
154 |
minSize = editButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
155 |
widthHint = Math.max(widthHint, minSize.x); |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
156 |
GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).hint(widthHint, SWT.DEFAULT).applyTo(editButton); |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
157 |
editButton.setData(UID, "editButton"); //$NON-NLS-1$ |
956 | 158 |
editButton.addSelectionListener(new SelectionAdapter() { |
159 |
@Override |
|
160 |
public void widgetSelected(SelectionEvent e) { |
|
161 |
IConnection connection = getConnectionFromSelection(viewer.getSelection()); |
|
162 |
if (connection != null) { |
|
163 |
SettingsWizard wizard = new SettingsWizard(connection, data.getService()); |
|
164 |
wizard.open(composite.getShell()); |
|
165 |
} |
|
166 |
} |
|
167 |
}); |
|
168 |
||
169 |
descriptionLabel = new Label(composite, SWT.WRAP); |
|
170 |
GridDataFactory.defaultsFor(descriptionLabel).grab(false, true).applyTo(descriptionLabel); |
|
171 |
composite.addControlListener(new ControlAdapter() { |
|
172 |
@Override |
|
173 |
public void controlResized(ControlEvent e) { |
|
174 |
descriptionLabel.pack(); |
|
175 |
} |
|
176 |
}); |
|
177 |
||
178 |
setViewerInput(data.getConnection()); |
|
179 |
||
180 |
return composite; |
|
181 |
} |
|
182 |
||
964
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
183 |
private void initializeDialogUnits(Composite parent) { |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
184 |
GC gc = new GC(parent); |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
185 |
gc.setFont(JFaceResources.getDialogFont()); |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
186 |
fm = gc.getFontMetrics(); |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
187 |
gc.dispose(); |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
188 |
} |
b0c1a1239188
add new button to new launch wizard connection dialog
dadubrow
parents:
956
diff
changeset
|
189 |
|
956 | 190 |
protected void validate() { |
191 |
IStatus status = ConnectToDeviceSection.revalidate(data); |
|
192 |
||
193 |
if (status.isOK()) { |
|
194 |
IConnection connection = data.getConnection(); |
|
195 |
if (connection != null) { |
|
1061
ceac11190019
bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents:
983
diff
changeset
|
196 |
IConnectedService connectedService = findConnectedServiceFromConnection(connection); |
956 | 197 |
|
198 |
if (connectedService == null) { |
|
199 |
status = error(MessageFormat.format( |
|
969 | 200 |
Messages.getString("ConnectToDeviceDialog.ServiceNotSupportedError"), //$NON-NLS-1$ |
956 | 201 |
data.getService().getDisplayName())); |
202 |
} |
|
203 |
else { |
|
204 |
com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus serviceStatus = |
|
205 |
connectedService.getStatus(); |
|
206 |
if (!serviceStatus.getEStatus().equals( |
|
207 |
com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus.EStatus.UP)) { |
|
1061
ceac11190019
bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents:
983
diff
changeset
|
208 |
String description = serviceStatus.getLongDescription(); |
969 | 209 |
status = warning(Messages.getString("ConnectToDeviceDialog.ServiceNotAvailWarning"), //$NON-NLS-1$ |
1061
ceac11190019
bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents:
983
diff
changeset
|
210 |
description == null ? "" : description); //$NON-NLS-1$ |
956 | 211 |
} |
212 |
} |
|
213 |
} |
|
214 |
} |
|
215 |
updateStatus(status); |
|
216 |
} |
|
217 |
||
1061
ceac11190019
bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents:
983
diff
changeset
|
218 |
private IConnectedService findConnectedServiceFromConnection(IConnection connection) { |
ceac11190019
bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents:
983
diff
changeset
|
219 |
Collection<IConnectedService> services = manager.getConnectedServices(connection); |
ceac11190019
bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents:
983
diff
changeset
|
220 |
for (IConnectedService connectedService : services) { |
ceac11190019
bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents:
983
diff
changeset
|
221 |
if (connectedService != null && connectedService.getService().getIdentifier().equals(data.getService().getIdentifier())) { |
ceac11190019
bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents:
983
diff
changeset
|
222 |
return connectedService; |
ceac11190019
bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents:
983
diff
changeset
|
223 |
} |
ceac11190019
bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents:
983
diff
changeset
|
224 |
} |
ceac11190019
bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents:
983
diff
changeset
|
225 |
return null; |
ceac11190019
bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents:
983
diff
changeset
|
226 |
} |
ceac11190019
bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents:
983
diff
changeset
|
227 |
|
956 | 228 |
/** |
229 |
* Update for a change in the connection. We will attempt to connect to the |
|
230 |
* device (once) to detect what TRK it is running. |
|
231 |
*/ |
|
232 |
private void updateConnection(IConnection connection) { |
|
233 |
String standardPNPMessage = ConnectToDeviceSection.getStandardPNPMessage(); |
|
234 |
data.setConnection(connection); |
|
235 |
if (connection != null) { |
|
236 |
descriptionLabel.setText(standardPNPMessage); |
|
237 |
} else { |
|
969 | 238 |
descriptionLabel.setText(Messages.getString("ConnectToDeviceDialog.NoConnectionsText") + standardPNPMessage); //$NON-NLS-1$ |
956 | 239 |
} |
1061
ceac11190019
bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents:
983
diff
changeset
|
240 |
if (currentServiceListener != null) |
ceac11190019
bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents:
983
diff
changeset
|
241 |
currentServiceListener.removeStatusChangedListener(this); |
ceac11190019
bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents:
983
diff
changeset
|
242 |
currentServiceListener = findConnectedServiceFromConnection(connection); |
ceac11190019
bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents:
983
diff
changeset
|
243 |
if (currentServiceListener != null) |
ceac11190019
bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents:
983
diff
changeset
|
244 |
currentServiceListener.addStatusChangedListener(this); |
956 | 245 |
} |
246 |
||
1061
ceac11190019
bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents:
983
diff
changeset
|
247 |
protected void connectionSelected(IConnection connection) { |
956 | 248 |
updateConnection(connection); |
249 |
validate(); |
|
250 |
} |
|
251 |
||
252 |
public void connectionAdded(IConnection connection) { |
|
983
8b4ee73c530c
New launch wizard UI tweaks based on demo feedback
dadubrow
parents:
981
diff
changeset
|
253 |
refreshUI(null); |
956 | 254 |
} |
255 |
||
256 |
public void connectionRemoved(IConnection connection) { |
|
983
8b4ee73c530c
New launch wizard UI tweaks based on demo feedback
dadubrow
parents:
981
diff
changeset
|
257 |
refreshUI(null); |
956 | 258 |
} |
259 |
||
260 |
public void currentConnectionSet(IConnection connection) { |
|
1061
ceac11190019
bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents:
983
diff
changeset
|
261 |
// refreshUI(connection); |
956 | 262 |
} |
263 |
||
1061
ceac11190019
bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents:
983
diff
changeset
|
264 |
public void statusChanged(com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus status) { |
ceac11190019
bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents:
983
diff
changeset
|
265 |
validate(); |
ceac11190019
bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents:
983
diff
changeset
|
266 |
} |
ceac11190019
bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents:
983
diff
changeset
|
267 |
|
956 | 268 |
private Set<IConnectionType> getCompatibleConnectionTypes() { |
269 |
HashSet<IConnectionType> types = new HashSet<IConnectionType>(); |
|
270 |
Collection<String> compatibleTypeIds = |
|
271 |
typeProvider.getCompatibleConnectionTypeIds(data.getService()); |
|
272 |
for (String typeId : compatibleTypeIds) { |
|
273 |
types.add(typeProvider.getConnectionType(typeId)); |
|
274 |
} |
|
275 |
return types; |
|
276 |
} |
|
277 |
||
278 |
private List<IConnection> getCompatibleConnections() { |
|
279 |
Set<IConnectionType> types = getCompatibleConnectionTypes(); |
|
280 |
||
281 |
List<IConnection> compatibleConnections = new ArrayList<IConnection>(); |
|
282 |
for (IConnection connection : manager.getConnections()) { |
|
283 |
if (types.contains(connection.getConnectionType())) |
|
284 |
compatibleConnections.add(connection); |
|
285 |
} |
|
286 |
return compatibleConnections; |
|
287 |
} |
|
288 |
||
289 |
private void setViewerInput(IConnection connection) { |
|
290 |
List<IConnection> connections = getCompatibleConnections(); |
|
291 |
viewer.setInput(connections); |
|
292 |
||
293 |
if (connections.isEmpty()) |
|
294 |
viewer.getCombo().setEnabled(false); |
|
295 |
else { |
|
296 |
viewer.getCombo().setEnabled(true); |
|
297 |
if (connection == null) { |
|
298 |
viewer.getCombo().select(0); |
|
299 |
ISelection selection = viewer.getSelection(); |
|
300 |
connection = getConnectionFromSelection(selection); |
|
301 |
viewer.setSelection(selection); |
|
302 |
} |
|
303 |
else |
|
304 |
viewer.setSelection(new StructuredSelection(connection)); |
|
305 |
} |
|
306 |
editButton.setEnabled(!viewer.getSelection().isEmpty()); |
|
307 |
||
308 |
// fire listener in case we selected anew or the current connection changed |
|
309 |
connectionSelected(connection); |
|
310 |
} |
|
311 |
||
312 |
private IConnection getConnectionFromSelection(ISelection selection) { |
|
313 |
return (IConnection) ((IStructuredSelection) selection).getFirstElement(); |
|
314 |
} |
|
315 |
||
983
8b4ee73c530c
New launch wizard UI tweaks based on demo feedback
dadubrow
parents:
981
diff
changeset
|
316 |
private void refreshUI(final IConnection connection) { |
956 | 317 |
Display.getDefault().syncExec(new Runnable() { |
318 |
public void run() { |
|
319 |
if (viewer != null && viewer.getContentProvider() != null) { |
|
983
8b4ee73c530c
New launch wizard UI tweaks based on demo feedback
dadubrow
parents:
981
diff
changeset
|
320 |
IConnection connectionToSet = connection == null ? getConnectionFromSelection(viewer.getSelection()) : connection; |
8b4ee73c530c
New launch wizard UI tweaks based on demo feedback
dadubrow
parents:
981
diff
changeset
|
321 |
setViewerInput(connectionToSet); |
956 | 322 |
} |
323 |
} |
|
324 |
}); |
|
325 |
} |
|
326 |
||
327 |
@Override |
|
328 |
public boolean close() { |
|
329 |
manager.addConnectionListener(this); |
|
330 |
return super.close(); |
|
331 |
} |
|
1061
ceac11190019
bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents:
983
diff
changeset
|
332 |
|
956 | 333 |
} |
334 |