author | dadubrow |
Thu, 18 Feb 2010 09:07:17 -0600 | |
changeset 983 | 8b4ee73c530c |
parent 969 | b0dd389735fb |
child 993 | df87e2d581e4 |
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 |
||
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 |
||
969 | 38 |
private static final String NO_CURRENT_CONNECTION_MSG = Messages.getString("ConnectToDeviceSection.NoConnectionMsg"); //$NON-NLS-1$ |
956 | 39 |
private final IConnectionsManager manager; |
40 |
||
41 |
/** |
|
42 |
* @param unifiedLaunchOptionsPage |
|
43 |
* |
|
44 |
*/ |
|
45 |
public ConnectToDeviceSection(LaunchWizardData data, UnifiedLaunchOptionsPage launchOptionsPage) { |
|
969 | 46 |
super(data, Messages.getString("ConnectToDeviceSection.Title"), launchOptionsPage); //$NON-NLS-1$ |
956 | 47 |
manager = RemoteConnectionsActivator.getConnectionsManager(); |
48 |
} |
|
49 |
||
50 |
public void createControl(Composite parent) { |
|
51 |
createSection(parent, 0); |
|
52 |
manager.addConnectionListener(this); |
|
53 |
} |
|
54 |
||
55 |
@Override |
|
56 |
protected void dispose() { |
|
57 |
manager.removeConnectionListener(this); |
|
58 |
} |
|
59 |
||
60 |
public void initializeSettings() { |
|
61 |
data.setConnection(manager.getCurrentConnection()); |
|
62 |
} |
|
63 |
||
64 |
@Override |
|
65 |
protected void validate() { |
|
66 |
status = revalidate(data); |
|
67 |
} |
|
68 |
||
69 |
/** Get the simple status for the connection state */ |
|
70 |
static IStatus revalidate(LaunchWizardData data) { |
|
71 |
IStatus status = Status.OK_STATUS; |
|
72 |
||
73 |
if (data.getConnection() == null) { |
|
74 |
status = error(NO_CURRENT_CONNECTION_MSG); |
|
75 |
} |
|
76 |
||
77 |
return status; |
|
78 |
} |
|
79 |
||
80 |
static String getStandardPNPMessage() { |
|
969 | 81 |
return Messages.getString("ConnectToDeviceSection.StdPNPMsg"); //$NON-NLS-1$ |
956 | 82 |
} |
83 |
||
84 |
@Override |
|
85 |
protected void updateUI() { |
|
86 |
if (control == null || control.isDisposed()) |
|
87 |
return; |
|
88 |
||
89 |
String msg; |
|
90 |
if (data.getConnection() != null) |
|
969 | 91 |
msg = MessageFormat.format(Messages.getString("ConnectToDeviceSection.CurrentConnectionLabel"), data.getConnectionName()); //$NON-NLS-1$ |
956 | 92 |
else |
969 | 93 |
msg = MessageFormat.format("{0} {1}", NO_CURRENT_CONNECTION_MSG, getStandardPNPMessage()); //$NON-NLS-1$ |
956 | 94 |
|
95 |
descriptionLabel.setText(msg); |
|
96 |
launchOptionsPage.changed(); |
|
983
8b4ee73c530c
New launch wizard UI tweaks based on demo feedback
dadubrow
parents:
969
diff
changeset
|
97 |
launchOptionsPage.getWizard().getContainer().getShell().pack(); |
956 | 98 |
} |
99 |
||
100 |
@Override |
|
101 |
protected AbstractLaunchSettingsDialog createChangeSettingsDialog(Shell shell, LaunchWizardData dialogData) { |
|
102 |
return new ConnectToDeviceDialog(shell, dialogData); |
|
103 |
} |
|
104 |
||
105 |
protected void refresh() { |
|
106 |
Display.getDefault().syncExec(new Runnable() { |
|
107 |
public void run() { |
|
108 |
validate(); |
|
109 |
updateUI(); |
|
110 |
} |
|
111 |
}); |
|
112 |
} |
|
113 |
||
114 |
private void doConnectionsChanged() { |
|
115 |
data.setConnection(manager.getCurrentConnection()); |
|
116 |
refresh(); |
|
117 |
} |
|
118 |
||
119 |
public void connectionAdded(IConnection connection) { |
|
120 |
doConnectionsChanged(); |
|
121 |
} |
|
122 |
||
123 |
public void connectionRemoved(IConnection connection) { |
|
124 |
doConnectionsChanged(); |
|
125 |
} |
|
126 |
||
127 |
public void currentConnectionSet(IConnection connection) { |
|
128 |
doConnectionsChanged(); |
|
129 |
} |
|
130 |
||
131 |
@Override |
|
132 |
protected void doChange() { |
|
133 |
super.doChange(); |
|
134 |
IConnection connection = data.getConnection(); |
|
135 |
if (connection != null && !connection.equals(manager.getCurrentConnection())) |
|
136 |
manager.setCurrentConnection(connection); |
|
137 |
} |
|
138 |
} |