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 |
|
|
22 |
import org.eclipse.core.runtime.IStatus;
|
|
23 |
import org.eclipse.core.runtime.Status;
|
|
24 |
import org.eclipse.swt.widgets.Composite;
|
|
25 |
import org.eclipse.swt.widgets.Display;
|
|
26 |
import org.eclipse.swt.widgets.Shell;
|
|
27 |
|
|
28 |
import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator;
|
|
29 |
import com.nokia.carbide.remoteconnections.interfaces.IConnection;
|
|
30 |
import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager;
|
|
31 |
import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener;
|
|
32 |
|
|
33 |
/**
|
|
34 |
* Present the "Connect to device" section with a short description.
|
|
35 |
*/
|
|
36 |
public class ConnectToDeviceSection extends AbstractLaunchWizardSection implements IConnectionListener {
|
|
37 |
|
|
38 |
private static final String NO_CURRENT_CONNECTION_MSG = "No current connection is defined or detected.";
|
|
39 |
private final UnifiedLaunchOptionsPage launchOptionsPage;
|
|
40 |
private final IConnectionsManager manager;
|
|
41 |
|
|
42 |
/**
|
|
43 |
* @param unifiedLaunchOptionsPage
|
|
44 |
*
|
|
45 |
*/
|
|
46 |
public ConnectToDeviceSection(LaunchWizardData data, UnifiedLaunchOptionsPage launchOptionsPage) {
|
|
47 |
super(data, "Connect to device");
|
|
48 |
this.launchOptionsPage = launchOptionsPage;
|
|
49 |
manager = RemoteConnectionsActivator.getConnectionsManager();
|
|
50 |
}
|
|
51 |
|
|
52 |
public void createControl(Composite parent) {
|
|
53 |
createSection(parent, 0);
|
|
54 |
manager.addConnectionListener(this);
|
|
55 |
}
|
|
56 |
|
|
57 |
@Override
|
|
58 |
protected void dispose() {
|
|
59 |
manager.removeConnectionListener(this);
|
|
60 |
}
|
|
61 |
|
|
62 |
public void initializeSettings() {
|
|
63 |
data.setConnection(manager.getCurrentConnection());
|
|
64 |
}
|
|
65 |
|
|
66 |
@Override
|
|
67 |
protected void validate() {
|
|
68 |
status = revalidate(data);
|
|
69 |
}
|
|
70 |
|
|
71 |
/** Get the simple status for the connection state */
|
|
72 |
static IStatus revalidate(LaunchWizardData data) {
|
|
73 |
IStatus status = Status.OK_STATUS;
|
|
74 |
|
|
75 |
if (data.getConnection() == null) {
|
|
76 |
status = error(NO_CURRENT_CONNECTION_MSG);
|
|
77 |
}
|
|
78 |
|
|
79 |
return status;
|
|
80 |
}
|
|
81 |
|
|
82 |
static String getStandardPNPMessage() {
|
|
83 |
return "You may plug in a device over USB or activate it over WLAN, or create a new connection now for your device.";
|
|
84 |
}
|
|
85 |
|
|
86 |
@Override
|
|
87 |
protected void updateUI() {
|
|
88 |
if (control == null || control.isDisposed())
|
|
89 |
return;
|
|
90 |
|
|
91 |
String msg;
|
|
92 |
if (data.getConnection() != null)
|
|
93 |
msg = MessageFormat.format("The current connection is now ''{0}''.", data.getConnectionName());
|
|
94 |
else
|
|
95 |
msg = MessageFormat.format("{0} {1}", NO_CURRENT_CONNECTION_MSG, getStandardPNPMessage());
|
|
96 |
|
|
97 |
descriptionLabel.setText(msg);
|
|
98 |
launchOptionsPage.changed();
|
|
99 |
}
|
|
100 |
|
|
101 |
@Override
|
|
102 |
protected AbstractLaunchSettingsDialog createChangeSettingsDialog(Shell shell, LaunchWizardData dialogData) {
|
|
103 |
return new ConnectToDeviceDialog(shell, dialogData);
|
|
104 |
}
|
|
105 |
|
|
106 |
protected void refresh() {
|
|
107 |
Display.getDefault().syncExec(new Runnable() {
|
|
108 |
public void run() {
|
|
109 |
validate();
|
|
110 |
updateUI();
|
|
111 |
}
|
|
112 |
});
|
|
113 |
}
|
|
114 |
|
|
115 |
private void doConnectionsChanged() {
|
|
116 |
data.setConnection(manager.getCurrentConnection());
|
|
117 |
refresh();
|
|
118 |
}
|
|
119 |
|
|
120 |
public void connectionAdded(IConnection connection) {
|
|
121 |
doConnectionsChanged();
|
|
122 |
}
|
|
123 |
|
|
124 |
public void connectionRemoved(IConnection connection) {
|
|
125 |
doConnectionsChanged();
|
|
126 |
}
|
|
127 |
|
|
128 |
public void currentConnectionSet(IConnection connection) {
|
|
129 |
doConnectionsChanged();
|
|
130 |
}
|
|
131 |
|
|
132 |
@Override
|
|
133 |
protected void doChange() {
|
|
134 |
super.doChange();
|
|
135 |
IConnection connection = data.getConnection();
|
|
136 |
if (connection != null && !connection.equals(manager.getCurrentConnection()))
|
|
137 |
manager.setCurrentConnection(connection);
|
|
138 |
}
|
|
139 |
}
|