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