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