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