debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/newwizard/ConnectToDeviceDialog.java
author Ed Swartz <ed.swartz@nokia.com>
Fri, 09 Apr 2010 07:45:47 -0500
branchRCL_2_4
changeset 1191 0523013ddf00
parent 1060 852f9f9927e6
child 1262 f88340f6e139
permissions -rw-r--r--
Merge commits 1174, 1175, 1176, 1184, 1185 from default: Fix issues not disposing listeners in PNP launch wizard Fix use of PathUtils: do not use new Path() on a Windows format path; this breaks in Linux. Bug 11067: fix some issues with the PNP launch wizard Connected service properties need to be propagated just as their statuses are
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
911
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
     1
/*
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
     2
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
     3
* All rights reserved.
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
     4
* This component and the accompanying materials are made available
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
     6
* which accompanies this distribution, and is available
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
     8
*
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
     9
* Initial Contributors:
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    11
*
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    12
* Contributors:
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    13
*
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    14
* Description: 
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    15
*
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    16
*/
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    17
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    18
package com.nokia.cdt.internal.debug.launch.newwizard;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    19
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    20
import java.text.MessageFormat;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    21
import java.util.ArrayList;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    22
import java.util.Collection;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    23
import java.util.HashSet;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    24
import java.util.List;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    25
import java.util.Set;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    26
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    27
import org.eclipse.core.runtime.IStatus;
963
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
    28
import org.eclipse.jface.dialogs.Dialog;
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
    29
import org.eclipse.jface.dialogs.IDialogConstants;
911
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    30
import org.eclipse.jface.layout.GridDataFactory;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    31
import org.eclipse.jface.layout.GridLayoutFactory;
963
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
    32
import org.eclipse.jface.resource.JFaceResources;
911
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    33
import org.eclipse.jface.viewers.ArrayContentProvider;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    34
import org.eclipse.jface.viewers.ComboViewer;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    35
import org.eclipse.jface.viewers.ISelection;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    36
import org.eclipse.jface.viewers.ISelectionChangedListener;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    37
import org.eclipse.jface.viewers.IStructuredSelection;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    38
import org.eclipse.jface.viewers.LabelProvider;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    39
import org.eclipse.jface.viewers.SelectionChangedEvent;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    40
import org.eclipse.jface.viewers.StructuredSelection;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    41
import org.eclipse.swt.SWT;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    42
import org.eclipse.swt.events.ControlAdapter;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    43
import org.eclipse.swt.events.ControlEvent;
1191
0523013ddf00 Merge commits 1174, 1175, 1176, 1184, 1185 from default:
Ed Swartz <ed.swartz@nokia.com>
parents: 1060
diff changeset
    44
import org.eclipse.swt.events.DisposeEvent;
0523013ddf00 Merge commits 1174, 1175, 1176, 1184, 1185 from default:
Ed Swartz <ed.swartz@nokia.com>
parents: 1060
diff changeset
    45
import org.eclipse.swt.events.DisposeListener;
911
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    46
import org.eclipse.swt.events.SelectionAdapter;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    47
import org.eclipse.swt.events.SelectionEvent;
963
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
    48
import org.eclipse.swt.graphics.FontMetrics;
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
    49
import org.eclipse.swt.graphics.GC;
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
    50
import org.eclipse.swt.graphics.Point;
911
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    51
import org.eclipse.swt.widgets.Button;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    52
import org.eclipse.swt.widgets.Combo;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    53
import org.eclipse.swt.widgets.Composite;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    54
import org.eclipse.swt.widgets.Control;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    55
import org.eclipse.swt.widgets.Display;
963
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
    56
import org.eclipse.swt.widgets.Group;
911
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    57
import org.eclipse.swt.widgets.Label;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    58
import org.eclipse.swt.widgets.Shell;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    59
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    60
import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    61
import com.nokia.carbide.remoteconnections.interfaces.IConnectedService;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    62
import com.nokia.carbide.remoteconnections.interfaces.IConnection;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    63
import com.nokia.carbide.remoteconnections.interfaces.IConnectionType;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    64
import com.nokia.carbide.remoteconnections.interfaces.IConnectionTypeProvider;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    65
import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager;
1060
852f9f9927e6 bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents: 982
diff changeset
    66
import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatusChangedListener;
911
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    67
import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    68
import com.nokia.carbide.remoteconnections.settings.ui.SettingsWizard;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    69
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    70
/**
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    71
 *	This dialog allows in-depth configuration of the connection settings.
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    72
 */
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    73
@SuppressWarnings("restriction")
1060
852f9f9927e6 bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents: 982
diff changeset
    74
public class ConnectToDeviceDialog extends AbstractLaunchSettingsDialog implements IConnectionListener, IStatusChangedListener {
911
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    75
	private IConnectionsManager manager;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    76
	private IConnectionTypeProvider typeProvider;
963
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
    77
	private FontMetrics fm;
911
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    78
	private ComboViewer viewer;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    79
	private Button editButton;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    80
	private Label descriptionLabel;
963
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
    81
	private Button newButton;
1060
852f9f9927e6 bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents: 982
diff changeset
    82
	private IConnectedService currentServiceListener;
911
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    83
953
68b6a294ab01 new launch wizard implementation
dadubrow
parents: 911
diff changeset
    84
	protected ConnectToDeviceDialog(Shell shell, LaunchWizardData data) {
911
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    85
		super(shell, data);
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    86
		manager = RemoteConnectionsActivator.getConnectionsManager();
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    87
		typeProvider = RemoteConnectionsActivator.getConnectionTypeProvider();
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    88
	}
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    89
	
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    90
	@Override
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    91
	protected Control createDialogArea(Composite parent) {
963
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
    92
		initializeDialogUnits(parent);
911
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    93
		final Composite composite = initDialogArea(parent, 
966
15c9cbbf6707 externalize strings
dadubrow
parents: 963
diff changeset
    94
				Messages.getString("ConnectToDeviceDialog.Title"), //$NON-NLS-1$
911
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    95
				LaunchWizardHelpIds.WIZARD_DIALOG_CHANGE_CONNECTION);
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    96
		
963
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
    97
		Group viewerGroup = new Group(composite, SWT.NONE);
966
15c9cbbf6707 externalize strings
dadubrow
parents: 963
diff changeset
    98
		viewerGroup.setText(Messages.getString("ConnectToDeviceDialog.GroupLabel")); //$NON-NLS-1$
911
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
    99
		GridDataFactory.fillDefaults().applyTo(viewerGroup);
963
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   100
		GridLayoutFactory.swtDefaults().applyTo(viewerGroup);
911
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   101
		
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   102
		viewer = new ComboViewer(viewerGroup, SWT.READ_ONLY);
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   103
		viewer.setLabelProvider(new LabelProvider() {
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   104
			@Override
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   105
			public String getText(Object element) {
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   106
				if (element instanceof IConnection)
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   107
					return ((IConnection) element).getDisplayName();
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   108
				
966
15c9cbbf6707 externalize strings
dadubrow
parents: 963
diff changeset
   109
				return Messages.getString("ConnectToDeviceDialog.NoCurrentItem"); //$NON-NLS-1$
911
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   110
			}
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   111
		});
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   112
		viewer.setContentProvider(new ArrayContentProvider());
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   113
		Combo combo = viewer.getCombo();
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   114
		GridDataFactory.defaultsFor(combo).grab(true, false).applyTo(combo);
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   115
		viewer.getControl().setData(UID, "combo_viewer"); //$NON-NLS-1$
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   116
		viewer.addSelectionChangedListener(new ISelectionChangedListener() {
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   117
			public void selectionChanged(SelectionChangedEvent event) {
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   118
				if (getDialogArea() != null)
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   119
					connectionSelected(getConnectionFromSelection(event.getSelection()));
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   120
			}
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   121
		});
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   122
		manager.addConnectionListener(this);
1191
0523013ddf00 Merge commits 1174, 1175, 1176, 1184, 1185 from default:
Ed Swartz <ed.swartz@nokia.com>
parents: 1060
diff changeset
   123
0523013ddf00 Merge commits 1174, 1175, 1176, 1184, 1185 from default:
Ed Swartz <ed.swartz@nokia.com>
parents: 1060
diff changeset
   124
		parent.addDisposeListener(new DisposeListener() {
0523013ddf00 Merge commits 1174, 1175, 1176, 1184, 1185 from default:
Ed Swartz <ed.swartz@nokia.com>
parents: 1060
diff changeset
   125
			public void widgetDisposed(DisposeEvent e) {
0523013ddf00 Merge commits 1174, 1175, 1176, 1184, 1185 from default:
Ed Swartz <ed.swartz@nokia.com>
parents: 1060
diff changeset
   126
				manager.removeConnectionListener(ConnectToDeviceDialog.this);
0523013ddf00 Merge commits 1174, 1175, 1176, 1184, 1185 from default:
Ed Swartz <ed.swartz@nokia.com>
parents: 1060
diff changeset
   127
				
0523013ddf00 Merge commits 1174, 1175, 1176, 1184, 1185 from default:
Ed Swartz <ed.swartz@nokia.com>
parents: 1060
diff changeset
   128
				if (currentServiceListener != null)
0523013ddf00 Merge commits 1174, 1175, 1176, 1184, 1185 from default:
Ed Swartz <ed.swartz@nokia.com>
parents: 1060
diff changeset
   129
					currentServiceListener.removeStatusChangedListener(ConnectToDeviceDialog.this);
0523013ddf00 Merge commits 1174, 1175, 1176, 1184, 1185 from default:
Ed Swartz <ed.swartz@nokia.com>
parents: 1060
diff changeset
   130
			}
0523013ddf00 Merge commits 1174, 1175, 1176, 1184, 1185 from default:
Ed Swartz <ed.swartz@nokia.com>
parents: 1060
diff changeset
   131
		});
911
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   132
		
963
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   133
		final Composite buttonGroup = new Composite(viewerGroup, SWT.NONE);
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   134
		int w = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.HORIZONTAL_MARGIN);
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   135
		int h = Dialog.convertVerticalDLUsToPixels(fm, IDialogConstants.VERTICAL_MARGIN);
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   136
		int hs = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.HORIZONTAL_SPACING);
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   137
		int vs = Dialog.convertVerticalDLUsToPixels(fm, IDialogConstants.VERTICAL_SPACING);
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   138
		GridLayoutFactory.swtDefaults().numColumns(2).equalWidth(true).
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   139
			margins(w, h).spacing(hs, vs).applyTo(buttonGroup);
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   140
		GridDataFactory.swtDefaults().align(SWT.END, SWT.CENTER).applyTo(buttonGroup);
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   141
		buttonGroup.setFont(parent.getFont());
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   142
		
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   143
		newButton = new Button(buttonGroup, SWT.PUSH);
966
15c9cbbf6707 externalize strings
dadubrow
parents: 963
diff changeset
   144
		newButton.setText(Messages.getString("ConnectToDeviceDialog.NewLabel")); //$NON-NLS-1$
963
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   145
		newButton.setFont(JFaceResources.getDialogFont());
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   146
		int widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH);
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   147
		Point minSize = newButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   148
		widthHint = Math.max(widthHint, minSize.x);
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   149
		GridDataFactory.swtDefaults().align(SWT.FILL, SWT.TOP).hint(widthHint, SWT.DEFAULT).applyTo(newButton);
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   150
		newButton.setData(UID, "newButton"); //$NON-NLS-1$
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   151
		newButton.addSelectionListener(new SelectionAdapter() {
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   152
			@Override
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   153
			public void widgetSelected(SelectionEvent e) {
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   154
				SettingsWizard wizard = new SettingsWizard(null, data.getService());
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   155
				wizard.open(composite.getShell());
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   156
				IConnection connection = wizard.getConnectionToEdit();
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   157
				setViewerInput(connection);
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   158
			}
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   159
		});
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   160
		
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   161
		editButton = new Button(buttonGroup, SWT.PUSH);
966
15c9cbbf6707 externalize strings
dadubrow
parents: 963
diff changeset
   162
		editButton.setText(Messages.getString("ConnectToDeviceDialog.EditLabel")); //$NON-NLS-1$
963
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   163
		editButton.setFont(JFaceResources.getDialogFont());
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   164
		widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH);
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   165
		minSize = editButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   166
		widthHint = Math.max(widthHint, minSize.x);
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   167
		GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).hint(widthHint, SWT.DEFAULT).applyTo(editButton);
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   168
		editButton.setData(UID, "editButton"); //$NON-NLS-1$
911
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   169
		editButton.addSelectionListener(new SelectionAdapter() {
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   170
			@Override
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   171
			public void widgetSelected(SelectionEvent e) {
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   172
				IConnection connection = getConnectionFromSelection(viewer.getSelection()); 
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   173
				if (connection != null) {
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   174
					SettingsWizard wizard = new SettingsWizard(connection, data.getService());
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   175
					wizard.open(composite.getShell());
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   176
				}
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   177
			}
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   178
		});
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   179
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   180
		descriptionLabel = new Label(composite, SWT.WRAP);
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   181
		GridDataFactory.defaultsFor(descriptionLabel).grab(false, true).applyTo(descriptionLabel);
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   182
		composite.addControlListener(new ControlAdapter() {
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   183
			@Override
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   184
			public void controlResized(ControlEvent e) {
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   185
				descriptionLabel.pack();
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   186
			}
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   187
		});
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   188
		
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   189
		setViewerInput(data.getConnection());
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   190
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   191
		return composite;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   192
	}
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   193
	
963
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   194
	private void initializeDialogUnits(Composite parent) {
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   195
		GC gc = new GC(parent);
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   196
		gc.setFont(JFaceResources.getDialogFont());
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   197
		fm = gc.getFontMetrics();
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   198
		gc.dispose();
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   199
	}
ed38f30e9216 add new button to new launch wizard connection dialog
dadubrow
parents: 953
diff changeset
   200
911
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   201
	protected void validate() {
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   202
		IStatus status = ConnectToDeviceSection.revalidate(data);
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   203
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   204
		if (status.isOK()) {
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   205
			IConnection connection = data.getConnection();
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   206
			if (connection != null) {
1060
852f9f9927e6 bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents: 982
diff changeset
   207
				IConnectedService connectedService = findConnectedServiceFromConnection(connection);
911
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   208
				
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   209
				if (connectedService == null) {
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   210
					status = error(MessageFormat.format(
966
15c9cbbf6707 externalize strings
dadubrow
parents: 963
diff changeset
   211
							Messages.getString("ConnectToDeviceDialog.ServiceNotSupportedError"), //$NON-NLS-1$
911
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   212
							data.getService().getDisplayName()));
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   213
				}
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   214
				else {
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   215
					com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus serviceStatus = 
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   216
						connectedService.getStatus();
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   217
					if (!serviceStatus.getEStatus().equals(
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   218
							com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus.EStatus.UP)) {
1060
852f9f9927e6 bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents: 982
diff changeset
   219
						String description  = serviceStatus.getLongDescription();
966
15c9cbbf6707 externalize strings
dadubrow
parents: 963
diff changeset
   220
						status = warning(Messages.getString("ConnectToDeviceDialog.ServiceNotAvailWarning"),  //$NON-NLS-1$
1060
852f9f9927e6 bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents: 982
diff changeset
   221
								description == null ? "" : description); //$NON-NLS-1$
911
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   222
					}
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   223
				}
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   224
			}
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   225
		}
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   226
		updateStatus(status);
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   227
	}
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   228
1060
852f9f9927e6 bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents: 982
diff changeset
   229
	private IConnectedService findConnectedServiceFromConnection(IConnection connection) {
852f9f9927e6 bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents: 982
diff changeset
   230
		Collection<IConnectedService> services = manager.getConnectedServices(connection);
852f9f9927e6 bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents: 982
diff changeset
   231
		for (IConnectedService connectedService : services) {
852f9f9927e6 bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents: 982
diff changeset
   232
			if (connectedService != null && connectedService.getService().getIdentifier().equals(data.getService().getIdentifier())) {
852f9f9927e6 bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents: 982
diff changeset
   233
				return connectedService;
852f9f9927e6 bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents: 982
diff changeset
   234
			}
852f9f9927e6 bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents: 982
diff changeset
   235
		}
852f9f9927e6 bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents: 982
diff changeset
   236
		return null;
852f9f9927e6 bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents: 982
diff changeset
   237
	}
852f9f9927e6 bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents: 982
diff changeset
   238
911
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   239
	/**
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   240
	 *	Update for a change in the connection.  We will attempt to connect to the
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   241
	 *  device (once) to detect what TRK it is running.
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   242
	 */
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   243
	private void updateConnection(IConnection connection) {
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   244
		String standardPNPMessage = ConnectToDeviceSection.getStandardPNPMessage();
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   245
		data.setConnection(connection);
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   246
		if (connection != null) {
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   247
			descriptionLabel.setText(standardPNPMessage);
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   248
		} else {
966
15c9cbbf6707 externalize strings
dadubrow
parents: 963
diff changeset
   249
			descriptionLabel.setText(Messages.getString("ConnectToDeviceDialog.NoConnectionsText") + standardPNPMessage); //$NON-NLS-1$
911
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   250
		}
1060
852f9f9927e6 bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents: 982
diff changeset
   251
		if (currentServiceListener != null)
852f9f9927e6 bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents: 982
diff changeset
   252
			currentServiceListener.removeStatusChangedListener(this);
852f9f9927e6 bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents: 982
diff changeset
   253
		currentServiceListener = findConnectedServiceFromConnection(connection);
852f9f9927e6 bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents: 982
diff changeset
   254
		if (currentServiceListener != null)
852f9f9927e6 bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents: 982
diff changeset
   255
			currentServiceListener.addStatusChangedListener(this);
911
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   256
	}
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   257
1060
852f9f9927e6 bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents: 982
diff changeset
   258
	protected void connectionSelected(IConnection connection) {
911
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   259
		updateConnection(connection);
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   260
		validate();
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   261
	}
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   262
	
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   263
	public void connectionAdded(IConnection connection) {
982
c848ffa5a500 New launch wizard UI tweaks based on demo feedback
dadubrow
parents: 977
diff changeset
   264
		refreshUI(null);
911
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   265
	}
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   266
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   267
	public void connectionRemoved(IConnection connection) {
982
c848ffa5a500 New launch wizard UI tweaks based on demo feedback
dadubrow
parents: 977
diff changeset
   268
		refreshUI(null);		
911
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   269
	}
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   270
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   271
	public void currentConnectionSet(IConnection connection) {
1060
852f9f9927e6 bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents: 982
diff changeset
   272
//		refreshUI(connection);
911
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   273
	}
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   274
1060
852f9f9927e6 bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents: 982
diff changeset
   275
	public void statusChanged(com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus status) {
852f9f9927e6 bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents: 982
diff changeset
   276
		validate();
852f9f9927e6 bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents: 982
diff changeset
   277
	}
852f9f9927e6 bug 10815 - connection dialog listen to service status change and update status
dadubrow
parents: 982
diff changeset
   278
	
911
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   279
	private Set<IConnectionType> getCompatibleConnectionTypes() {
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   280
		HashSet<IConnectionType> types = new HashSet<IConnectionType>();
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   281
		Collection<String> compatibleTypeIds =
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   282
			typeProvider.getCompatibleConnectionTypeIds(data.getService());
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   283
		for (String typeId : compatibleTypeIds) {
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   284
			types.add(typeProvider.getConnectionType(typeId));
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   285
		}
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   286
		return types;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   287
	}
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   288
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   289
	private List<IConnection> getCompatibleConnections() {
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   290
		Set<IConnectionType> types = getCompatibleConnectionTypes();
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   291
		
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   292
		List<IConnection> compatibleConnections = new ArrayList<IConnection>();
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   293
		for (IConnection connection : manager.getConnections()) {
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   294
			if (types.contains(connection.getConnectionType()))
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   295
				compatibleConnections.add(connection);
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   296
		}
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   297
		return compatibleConnections;
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   298
	}
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   299
	
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   300
	private void setViewerInput(IConnection connection) {
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   301
		List<IConnection> connections = getCompatibleConnections();
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   302
		viewer.setInput(connections);
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   303
		
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   304
		if (connections.isEmpty())
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   305
			viewer.getCombo().setEnabled(false);
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   306
		else {
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   307
			viewer.getCombo().setEnabled(true);
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   308
			if (connection == null) {
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   309
				viewer.getCombo().select(0);
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   310
				ISelection selection = viewer.getSelection();
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   311
				connection = getConnectionFromSelection(selection);
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   312
				viewer.setSelection(selection);
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   313
			}
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   314
			else
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   315
				viewer.setSelection(new StructuredSelection(connection));
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   316
		}
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   317
		editButton.setEnabled(!viewer.getSelection().isEmpty());
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   318
		
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   319
		// fire listener in case we selected anew or the current connection changed
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   320
		connectionSelected(connection);
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   321
	}
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   322
	
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   323
	private IConnection getConnectionFromSelection(ISelection selection) {
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   324
		return (IConnection) ((IStructuredSelection) selection).getFirstElement();
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   325
	}
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   326
982
c848ffa5a500 New launch wizard UI tweaks based on demo feedback
dadubrow
parents: 977
diff changeset
   327
	private void refreshUI(final IConnection connection) {
911
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   328
		Display.getDefault().syncExec(new Runnable() {
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   329
			public void run() {
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   330
				if (viewer != null && viewer.getContentProvider() != null) {
982
c848ffa5a500 New launch wizard UI tweaks based on demo feedback
dadubrow
parents: 977
diff changeset
   331
					IConnection connectionToSet = connection == null ? getConnectionFromSelection(viewer.getSelection()) : connection;
c848ffa5a500 New launch wizard UI tweaks based on demo feedback
dadubrow
parents: 977
diff changeset
   332
					setViewerInput(connectionToSet);
911
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   333
				}
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   334
			}
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   335
		});
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   336
	}
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   337
}
81a2e70a37d7 new wizard initial commit
dadubrow
parents:
diff changeset
   338