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