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