debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/newwizard/ConnectToDeviceSection.java
author dadubrow
Mon, 15 Feb 2010 13:49:01 -0600
changeset 956 d1e221a2875f
child 960 1b51db390dc4
permissions -rw-r--r--
new launch wizard implementation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
956
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
     1
/*
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
     2
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
     3
* All rights reserved.
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
     4
* This component and the accompanying materials are made available
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
     6
* which accompanies this distribution, and is available
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
     8
*
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
     9
* Initial Contributors:
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    11
*
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    12
* Contributors:
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    13
*
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    14
* Description: 
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    15
*
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    16
*/
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    17
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    18
package com.nokia.cdt.internal.debug.launch.newwizard;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    19
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    20
import java.text.MessageFormat;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    21
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    22
import org.eclipse.core.runtime.IStatus;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    23
import org.eclipse.core.runtime.Status;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    24
import org.eclipse.swt.widgets.Composite;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    25
import org.eclipse.swt.widgets.Display;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    26
import org.eclipse.swt.widgets.Shell;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    27
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    28
import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    29
import com.nokia.carbide.remoteconnections.interfaces.IConnection;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    30
import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    31
import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    32
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    33
/**
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    34
 * Present the "Connect to device" section with a short description.
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    35
 */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    36
public class ConnectToDeviceSection extends AbstractLaunchWizardSection implements IConnectionListener {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    37
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    38
	private static final String NO_CURRENT_CONNECTION_MSG = "No current connection is defined or detected.";
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    39
	private final UnifiedLaunchOptionsPage launchOptionsPage;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    40
	private final IConnectionsManager manager;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    41
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    42
	/**
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    43
	 * @param unifiedLaunchOptionsPage 
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    44
	 * 
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    45
	 */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    46
	public ConnectToDeviceSection(LaunchWizardData data, UnifiedLaunchOptionsPage launchOptionsPage) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    47
		super(data, "Connect to device");
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    48
		this.launchOptionsPage = launchOptionsPage;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    49
		manager = RemoteConnectionsActivator.getConnectionsManager();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    50
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    51
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    52
	public void createControl(Composite parent) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    53
		createSection(parent, 0);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    54
		manager.addConnectionListener(this);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    55
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    56
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    57
	@Override
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    58
	protected void dispose() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    59
		manager.removeConnectionListener(this);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    60
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    61
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    62
	public void initializeSettings() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    63
		data.setConnection(manager.getCurrentConnection());
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    64
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    65
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    66
	@Override
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    67
	protected void validate() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    68
		status = revalidate(data);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    69
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    70
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    71
	/** Get the simple status for the connection state */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    72
	static IStatus revalidate(LaunchWizardData data) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    73
		IStatus status = Status.OK_STATUS;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    74
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    75
		if (data.getConnection() == null) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    76
			status = error(NO_CURRENT_CONNECTION_MSG);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    77
		}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    78
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    79
		return status;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    80
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    81
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    82
	static String getStandardPNPMessage() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    83
		return "You may plug in a device over USB or activate it over WLAN, or create a new connection now for your device.";
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    84
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    85
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    86
	@Override
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    87
	protected void updateUI() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    88
		if (control == null || control.isDisposed())
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    89
			return;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    90
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    91
		String msg;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    92
		if (data.getConnection() != null)
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    93
			msg = MessageFormat.format("The current connection is now ''{0}''.", data.getConnectionName());
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    94
		else
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    95
			msg = MessageFormat.format("{0} {1}", NO_CURRENT_CONNECTION_MSG, getStandardPNPMessage());
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    96
			
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    97
		descriptionLabel.setText(msg);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    98
		launchOptionsPage.changed();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    99
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   100
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   101
	@Override
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   102
	protected AbstractLaunchSettingsDialog createChangeSettingsDialog(Shell shell, LaunchWizardData dialogData) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   103
		return new ConnectToDeviceDialog(shell, dialogData);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   104
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   105
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   106
	protected void refresh() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   107
		Display.getDefault().syncExec(new Runnable() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   108
			public void run() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   109
				validate();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   110
				updateUI();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   111
			}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   112
		});
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   113
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   114
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   115
	private void doConnectionsChanged() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   116
		data.setConnection(manager.getCurrentConnection());
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   117
		refresh();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   118
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   119
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   120
	public void connectionAdded(IConnection connection) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   121
		doConnectionsChanged();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   122
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   123
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   124
	public void connectionRemoved(IConnection connection) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   125
		doConnectionsChanged();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   126
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   127
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   128
	public void currentConnectionSet(IConnection connection) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   129
		doConnectionsChanged();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   130
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   131
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   132
	@Override
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   133
	protected void doChange() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   134
		super.doChange();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   135
		IConnection connection = data.getConnection();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   136
		if (connection != null && !connection.equals(manager.getCurrentConnection()))
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   137
			manager.setCurrentConnection(connection);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   138
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   139
}