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