debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/newwizard/ConnectToDeviceDialog.java
author John Dean <john.3.dean@nokia.com>
Wed, 17 Feb 2010 12:57:24 -0800
changeset 979 1dc37cfc99cd
parent 969 b0dd389735fb
child 980 2856f9bc4ddf
permissions -rw-r--r--
In Registry.getConnectedServices(IConnection), return empty collection instead of null. Use isEmpty() instead of == null for caller conditionals
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
				// note: refresh ASAP so the selection will be valid; but endure a listener event
b0c1a1239188 add new button to new launch wizard connection dialog
dadubrow
parents: 956
diff changeset
   145
				// which will redo this
b0c1a1239188 add new button to new launch wizard connection dialog
dadubrow
parents: 956
diff changeset
   146
				refreshUI();
b0c1a1239188 add new button to new launch wizard connection dialog
dadubrow
parents: 956
diff changeset
   147
				setViewerInput(connection);
b0c1a1239188 add new button to new launch wizard connection dialog
dadubrow
parents: 956
diff changeset
   148
			}
b0c1a1239188 add new button to new launch wizard connection dialog
dadubrow
parents: 956
diff changeset
   149
		});
b0c1a1239188 add new button to new launch wizard connection dialog
dadubrow
parents: 956
diff changeset
   150
		
b0c1a1239188 add new button to new launch wizard connection dialog
dadubrow
parents: 956
diff changeset
   151
		editButton = new Button(buttonGroup, SWT.PUSH);
969
b0dd389735fb externalize strings
dadubrow
parents: 964
diff changeset
   152
		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
   153
		editButton.setFont(JFaceResources.getDialogFont());
b0c1a1239188 add new button to new launch wizard connection dialog
dadubrow
parents: 956
diff changeset
   154
		widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH);
b0c1a1239188 add new button to new launch wizard connection dialog
dadubrow
parents: 956
diff changeset
   155
		minSize = editButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
b0c1a1239188 add new button to new launch wizard connection dialog
dadubrow
parents: 956
diff changeset
   156
		widthHint = Math.max(widthHint, minSize.x);
b0c1a1239188 add new button to new launch wizard connection dialog
dadubrow
parents: 956
diff changeset
   157
		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
   158
		editButton.setData(UID, "editButton"); //$NON-NLS-1$
956
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   159
		editButton.addSelectionListener(new SelectionAdapter() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   160
			@Override
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   161
			public void widgetSelected(SelectionEvent e) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   162
				IConnection connection = getConnectionFromSelection(viewer.getSelection()); 
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   163
				if (connection != null) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   164
					SettingsWizard wizard = new SettingsWizard(connection, data.getService());
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   165
					wizard.open(composite.getShell());
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   166
				}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   167
			}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   168
		});
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   169
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   170
		descriptionLabel = new Label(composite, SWT.WRAP);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   171
		GridDataFactory.defaultsFor(descriptionLabel).grab(false, true).applyTo(descriptionLabel);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   172
		composite.addControlListener(new ControlAdapter() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   173
			@Override
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   174
			public void controlResized(ControlEvent e) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   175
				descriptionLabel.pack();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   176
			}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   177
		});
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   178
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   179
		setViewerInput(data.getConnection());
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   180
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   181
		return composite;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   182
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   183
	
964
b0c1a1239188 add new button to new launch wizard connection dialog
dadubrow
parents: 956
diff changeset
   184
	private void initializeDialogUnits(Composite parent) {
b0c1a1239188 add new button to new launch wizard connection dialog
dadubrow
parents: 956
diff changeset
   185
		GC gc = new GC(parent);
b0c1a1239188 add new button to new launch wizard connection dialog
dadubrow
parents: 956
diff changeset
   186
		gc.setFont(JFaceResources.getDialogFont());
b0c1a1239188 add new button to new launch wizard connection dialog
dadubrow
parents: 956
diff changeset
   187
		fm = gc.getFontMetrics();
b0c1a1239188 add new button to new launch wizard connection dialog
dadubrow
parents: 956
diff changeset
   188
		gc.dispose();
b0c1a1239188 add new button to new launch wizard connection dialog
dadubrow
parents: 956
diff changeset
   189
	}
b0c1a1239188 add new button to new launch wizard connection dialog
dadubrow
parents: 956
diff changeset
   190
956
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   191
	protected void validate() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   192
		IStatus status = ConnectToDeviceSection.revalidate(data);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   193
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   194
		if (status.isOK()) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   195
			IConnection connection = data.getConnection();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   196
			if (connection != null) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   197
				IConnectedService connectedService = null;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   198
				Collection<IConnectedService> services = manager.getConnectedServices(connection);
979
1dc37cfc99cd 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: 969
diff changeset
   199
				for (IConnectedService service : services) {
1dc37cfc99cd 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: 969
diff changeset
   200
					if (service != null && service.getService().getIdentifier().equals(data.getService().getIdentifier())) {
1dc37cfc99cd 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: 969
diff changeset
   201
						connectedService = service;
956
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   202
					}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   203
				}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   204
				
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   205
				if (connectedService == null) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   206
					status = error(MessageFormat.format(
969
b0dd389735fb externalize strings
dadubrow
parents: 964
diff changeset
   207
							Messages.getString("ConnectToDeviceDialog.ServiceNotSupportedError"), //$NON-NLS-1$
956
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   208
							data.getService().getDisplayName()));
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   209
				}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   210
				else {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   211
					com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus serviceStatus = 
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   212
						connectedService.getStatus();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   213
					if (!serviceStatus.getEStatus().equals(
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   214
							com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus.EStatus.UP)) {
969
b0dd389735fb externalize strings
dadubrow
parents: 964
diff changeset
   215
						status = warning(Messages.getString("ConnectToDeviceDialog.ServiceNotAvailWarning"),  //$NON-NLS-1$
956
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   216
								serviceStatus.getLongDescription());
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   217
					}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   218
				}
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
		updateStatus(status);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   222
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   223
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   224
	/**
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   225
	 *	Update for a change in the connection.  We will attempt to connect to the
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   226
	 *  device (once) to detect what TRK it is running.
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   227
	 */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   228
	private void updateConnection(IConnection connection) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   229
		String standardPNPMessage = ConnectToDeviceSection.getStandardPNPMessage();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   230
		data.setConnection(connection);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   231
		if (connection != null) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   232
			descriptionLabel.setText(standardPNPMessage);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   233
		} else {
969
b0dd389735fb externalize strings
dadubrow
parents: 964
diff changeset
   234
			descriptionLabel.setText(Messages.getString("ConnectToDeviceDialog.NoConnectionsText") + standardPNPMessage); //$NON-NLS-1$
956
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   235
		}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   236
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   237
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   238
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   239
	public void connectionSelected(IConnection connection) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   240
		updateConnection(connection);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   241
		validate();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   242
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   243
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   244
	public void connectionAdded(IConnection connection) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   245
		refreshUI();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   246
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   247
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   248
	public void connectionRemoved(IConnection connection) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   249
		refreshUI();		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   250
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   251
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   252
	public void currentConnectionSet(IConnection connection) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   253
		refreshUI();		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   254
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   255
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   256
	private Set<IConnectionType> getCompatibleConnectionTypes() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   257
		HashSet<IConnectionType> types = new HashSet<IConnectionType>();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   258
		Collection<String> compatibleTypeIds =
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   259
			typeProvider.getCompatibleConnectionTypeIds(data.getService());
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   260
		for (String typeId : compatibleTypeIds) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   261
			types.add(typeProvider.getConnectionType(typeId));
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   262
		}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   263
		return types;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   264
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   265
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   266
	private List<IConnection> getCompatibleConnections() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   267
		Set<IConnectionType> types = getCompatibleConnectionTypes();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   268
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   269
		List<IConnection> compatibleConnections = new ArrayList<IConnection>();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   270
		for (IConnection connection : manager.getConnections()) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   271
			if (types.contains(connection.getConnectionType()))
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   272
				compatibleConnections.add(connection);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   273
		}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   274
		return compatibleConnections;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   275
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   276
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   277
	private void setViewerInput(IConnection connection) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   278
		List<IConnection> connections = getCompatibleConnections();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   279
		viewer.setInput(connections);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   280
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   281
		if (connections.isEmpty())
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   282
			viewer.getCombo().setEnabled(false);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   283
		else {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   284
			viewer.getCombo().setEnabled(true);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   285
			if (connection == null) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   286
				viewer.getCombo().select(0);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   287
				ISelection selection = viewer.getSelection();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   288
				connection = getConnectionFromSelection(selection);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   289
				viewer.setSelection(selection);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   290
			}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   291
			else
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   292
				viewer.setSelection(new StructuredSelection(connection));
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   293
		}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   294
		editButton.setEnabled(!viewer.getSelection().isEmpty());
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   295
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   296
		// fire listener in case we selected anew or the current connection changed
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   297
		connectionSelected(connection);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   298
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   299
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   300
	private IConnection getConnectionFromSelection(ISelection selection) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   301
		return (IConnection) ((IStructuredSelection) selection).getFirstElement();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   302
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   303
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   304
	private void refreshUI() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   305
		Display.getDefault().syncExec(new Runnable() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   306
			public void run() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   307
				if (viewer != null && viewer.getContentProvider() != null) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   308
					setViewerInput(getConnectionFromSelection(viewer.getSelection()));
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
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   313
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   314
	@Override
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   315
	public boolean close() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   316
		manager.addConnectionListener(this);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   317
		return super.close();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   318
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   319
}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   320