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